Temperature on the Shield Part 1 Read the thermometer The LE
Solution
Have a look. This might help you!
//Measuring temperature using one temp. sensor
#include <OneWire.h>
#include <DallasTemperature.h>
#define DATA_PIN 3
#define SENSOR_RESOLUTION 9
// index of sensors connected to data pin, default: 0
#define SENSOR_INDEX 0
OneWire oneWire(DATA_PIN);
DallasTemperature sensors(&oneWire);
DeviceAddress sensorDeviceAddress;
void setup() {
Serial.begin(9600);
sensors.begin();
sensors.getAddress(sensorDeviceAddress, 0);
sensors.setResolution(sensorDeviceAddress, SENSOR_RESOLUTION);
}
void loop() {
sensors.requestTemperatures();
// Measurement may take up to 750ms
long int temperatureInFahrenheit = sensors.getTempFByIndex(SENSOR_INDEX);
Serial.print(\"Temperature: \");
Serial.print(temperatureInFahrenheit, 4);
Serial.println(\" Fahrenheit\");
}
//For converting analog value to temp.
#include <math.h>
void setup() {
Serial.begin(115200); // sets up the Serial port at 115200 baud rate
}
double Thermister(int RawADC) { //Function to perform the fancy math of the Steinhart-Hart equation
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celsius
Temp = (Temp * 9.0)/ 5.0 + 32.0; // Celsius to Fahrenheit
return Temp;
}
void loop() {
int val;
double temp;
val=analogRead(0); //Read the analog port 0 and store the value in val
temp=Thermister(val); //Runs the fancy math on the raw analog value
Serial.println(temp); //Print the value to the serial port
delay(1000); //Wait one second before we do it again
}

