Temperature on the Shield Part 1 Read the thermometer The LE

Temperature on the Shield! Part 1: Read the thermometer The LED display shield actually has a thermometer on it -it is the tiny chip in one corner with \"DigiTher\" printed next to it. We can read it using the 12C protocol. Its 12C address was already in your last lab\'s assembly language template file: Ox92 (we use the upper 7 bits of this address, and then a lowest 8th bit of O to indicate write and 1 to indicate read; for the 7-segment display we only did writes; another way to look at it is that the thermometer\'s write address is the byte 0x92 and its read address is the byte Ox93). You carn learn a lot more about the thermometer here if you want to (but not necessary for this lab)

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

}

 Temperature on the Shield! Part 1: Read the thermometer The LED display shield actually has a thermometer on it -it is the tiny chip in one corner with \
 Temperature on the Shield! Part 1: Read the thermometer The LED display shield actually has a thermometer on it -it is the tiny chip in one corner with \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site