Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(12,11,5,4,3,2);
- const int LM35_vcc = A0; // sets analog input A0 as +5V source for LM35
- const int LM35_gnd = A1; // sets analog input A1 as ground for LM35
- const int LM35sensor = A2; // sets analog input A2 as LM35 sensor input
- const int TM36sensor = A3; // sets analog input A3 as TMP36 sensor input
- int counter=0;
- float mean_diff=0;
- void setup() {
- // LCD: lines of 16 characters,
- lcd.begin(16, 2);
- lcd.clear();
- pinMode(LM35_vcc,OUTPUT);
- digitalWrite(LM35_vcc,HIGH); // sets analog input A0 HIGH
- pinMode(LM35_gnd,OUTPUT);
- digitalWrite(LM35_gnd,LOW); // sets analog input A2 LOW
- pinMode(LM35sensor,INPUT);
- pinMode(TM36sensor, INPUT);
- // log the difference between LM35 and TMP36 sensor
- Serial.begin(9600); // sets the baud rate at 9600
- }
- void loop() {
- float TM36voltage, TM36degreesC;
- int TM36reading;
- // TMP36 input sensor -> degrees Calculation calculation
- TM36reading = analogRead(TM36sensor);
- TM36voltage = (TM36reading/1024.0)*5.0;
- //converting from 10mv per degree with 500 mV offset
- // (TMP36 voltage - 500mV) times 100)
- TM36degreesC = (TM36voltage - 0.5) * 100 ;
- // set cursor to first line of LCD display
- lcd.setCursor(0,0);
- // Print temperature of TMP36 sensor
- lcd.print("TMP36: ");
- lcd.print(TM36degreesC);
- lcd.print(" ");
- lcd.write(B11011111); // upper 'o' symbol
- lcd.print("C");
- float LM35voltage, LM35degreesC;
- int LM35reading;
- // LM35 input sensor -> degrees Celcius calculation
- LM35reading=analogRead(LM35sensor); // reads the LM35 output
- LM35voltage = (LM35reading/1024.0)*5.0;
- LM35degreesC=LM35voltage*100.0; // converts the digital value into temperature degree C
- // set cursor to second line of LM35 sensor
- lcd.setCursor(0,1);
- // Print temperature of LM35 sensor
- lcd.print("LM35 : ");
- lcd.print(LM35degreesC);
- lcd.print(" ");
- lcd.write(B11011111); // upper 'o' symbol
- lcd.print("C");
- // compute mean difference betweeb
- counter++;
- Serial.print("TM36: ");
- Serial.print(TM36degreesC);
- Serial.print(", LM35: ");
- Serial.print(LM35degreesC);
- Serial.print(" diff -> ");
- Serial.println(abs(TM36degreesC - LM35degreesC));
- mean_diff = mean_diff + abs(TM36degreesC - LM35degreesC);
- int nr_of_samples=10;
- if (counter==nr_of_samples) {
- counter=0;
- Serial.print("mean difference between sensors: ");
- Serial.println(mean_diff/float(nr_of_samples));
- mean_diff=0;
- }
- delay(1000);
- }
RAW Paste Data