Skip to content

Instantly share code, notes, and snippets.

@houmei
Created September 14, 2012 19:26
Show Gist options
  • Save houmei/3724141 to your computer and use it in GitHub Desktop.
Save houmei/3724141 to your computer and use it in GitHub Desktop.
Thermal Sensor LM35DZ/Arduino UNO R3
#include <LiquidCrystal.h>
// http://arduino.cc/en/Reference/AnalogReference
unsigned int t,c;
float sc;
int sensor0 = A0 ;
int value = 0 ;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float temp5v(int ain) { // analog 0-1023 10mV/Celsius ,5V*100/1024
return ain*500/1024;
}
float temp3v3(int ain) { // analog 0-1023 10mV/Celsius,3.3V*100/1024
return ain*330/1024;
}
float temp2v56(int ain) { // analog 0-1023 10mV/Celsius,2.56V*100/1024
return ain*256/1024;
}
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// External Aref(3.3V)
analogReference(EXTERNAL);
// Internal Aref(2.56V) ATmega328 ???
//analogReference(INTERNAL);
}
void loop() {
t=analogRead(sensor0); // (0...1023)
sc=temp3v3(t);
lcd.setCursor(0,0);lcd.print(" ");lcd.setCursor(0,0);
lcd.print(t);
lcd.setCursor(0,1);lcd.print(" ");lcd.setCursor(0,1);
lcd.print(sc);
delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment