Advertisement
Guest User

Arduino TM36 vs LM35 temperature sensor + LCD

a guest
Dec 23rd, 2014
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.58 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. LiquidCrystal lcd(12,11,5,4,3,2);
  4.  
  5. const int LM35_vcc   = A0;    // sets analog input A0 as +5V source for LM35
  6. const int LM35_gnd   = A1;    // sets analog input A1 as ground for LM35
  7. const int LM35sensor = A2;    // sets analog input A2 as LM35  sensor input
  8. const int TM36sensor = A3;    // sets analog input A3 as TMP36 sensor input
  9.  
  10. int counter=0;
  11. float mean_diff=0;
  12.  
  13. void setup() {
  14.  
  15.   // LCD: lines of 16 characters,
  16.   lcd.begin(16, 2);
  17.   lcd.clear();
  18.  
  19.   pinMode(LM35_vcc,OUTPUT);
  20.   digitalWrite(LM35_vcc,HIGH); // sets analog input A0 HIGH
  21.   pinMode(LM35_gnd,OUTPUT);
  22.   digitalWrite(LM35_gnd,LOW);  // sets analog input A2 LOW
  23.  
  24.   pinMode(LM35sensor,INPUT);
  25.   pinMode(TM36sensor, INPUT);
  26.  
  27.   // log the difference between LM35 and TMP36 sensor
  28.   Serial.begin(9600);        // sets the baud rate at 9600
  29. }
  30.  
  31. void loop() {
  32.    
  33.   float TM36voltage, TM36degreesC;
  34.   int TM36reading;
  35.  
  36.   // TMP36 input sensor -> degrees Calculation calculation
  37.   TM36reading = analogRead(TM36sensor);  
  38.   TM36voltage = (TM36reading/1024.0)*5.0;
  39.   //converting from 10mv per degree with 500 mV offset
  40.   //             (TMP36 voltage - 500mV) times 100)
  41.   TM36degreesC = (TM36voltage - 0.5) * 100 ;
  42.  
  43.   // set cursor to first line of LCD display
  44.   lcd.setCursor(0,0);
  45.   // Print temperature of TMP36 sensor
  46.   lcd.print("TMP36: ");
  47.   lcd.print(TM36degreesC);
  48.   lcd.print(" ");
  49.   lcd.write(B11011111); // upper 'o' symbol
  50.   lcd.print("C");
  51.  
  52.   float LM35voltage, LM35degreesC;
  53.   int LM35reading;
  54.  
  55.   // LM35 input sensor -> degrees Celcius calculation
  56.   LM35reading=analogRead(LM35sensor);    // reads the LM35 output
  57.   LM35voltage = (LM35reading/1024.0)*5.0;
  58.   LM35degreesC=LM35voltage*100.0;       // converts the digital value into temperature degree C
  59.  
  60.  
  61.   // set cursor to second line of LM35 sensor
  62.   lcd.setCursor(0,1);
  63.   // Print temperature of LM35 sensor
  64.   lcd.print("LM35 : ");
  65.   lcd.print(LM35degreesC);
  66.   lcd.print(" ");
  67.   lcd.write(B11011111); // upper 'o' symbol
  68.   lcd.print("C");
  69.  
  70.   // compute mean difference betweeb  
  71.   counter++;
  72.  
  73.   Serial.print("TM36: ");
  74.   Serial.print(TM36degreesC);
  75.   Serial.print(", LM35: ");
  76.   Serial.print(LM35degreesC);
  77.   Serial.print(" diff -> ");
  78.   Serial.println(abs(TM36degreesC - LM35degreesC));
  79.  
  80.   mean_diff = mean_diff + abs(TM36degreesC - LM35degreesC);
  81.  
  82.   int nr_of_samples=10;
  83.   if (counter==nr_of_samples) {
  84.     counter=0;
  85.     Serial.print("mean difference between sensors: ");
  86.     Serial.println(mean_diff/float(nr_of_samples));
  87.     mean_diff=0;
  88.   }
  89.  
  90.   delay(1000);
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement