Well here’s another little hack that demonstrates hooking up a temperature sensor to an Arduino Duemilanove micro-controller and displaying the temperature on an LCD. Before you say anything, yes I realize it’s not directly model railroad related but I suppose it could be if you needed to monitor the temperature from something, say a model railroad volcano with lava flow. :) Really it just demonstrates how easy it is to hook up an analog sensor to the Arduino and get meaningful data out and onto an LCD. I can picture the LCD embedded in a cool layout control panel and you could certainly swap the temperature IC for something like the opto-interruptor in my hack on making a Model Railroad Scale Speedometer and be able to display the scale speed of a model locomotive right on the LCD. Well anyway, it’s a good foundation for other more model railroad related projects to come and it tests out and shows off some of the new doo-dads I picked up recently.

The micro-controller is obviously an Arduino Duemilanove and the LCD is a 16 character x 2 line white text on a blue background LCD from adafruit.com. It has a single LED backlight that, if you watch the video below, is quite bright. It comes with a 10K contrast pot for $12.00 which is a bargain. It’s a fantastic, very readable LCD. The only caveat is that you can’t read it without the backlight. Oh well. The temperature IC is a little TMP36, I think I inaccurately called an LM35, oh well basically the same thing. It outputs an analog signal proportionate to the temperature and is capable of measuring between -40C to +125C. I wired up the LCD to the Arduino in 4-bit mode to save using extra pins along with the contrast pot.  The TMP36 comes in on a single analog input.

I took the Arduino Hellow World example sketch (program loaded onto the Arduino to tell it what to do) for the LCD and added the parts about monitoring the analog input signal from the TMP36 and then scaling and converting that to temperature in degrees Fahrenheit and Celsius which is then displayed onto the LCD along with the degree symbol.

Here is my Arduino Temperature to LCD sketch:

Arduino Temperature to LCD Sketch

#include <LiquidCrystal.h>
float tempC;
float tempF;
int tempPin = 0;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
Serial.begin(9600); //opens serial port, sets data rate t
// set up the LCD’s number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(“Temperature:”);
}

void loop() {
tempC = analogRead(tempPin);           //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature F
tempF = ((tempC – 32)/9)*5; //convert temperature in degrees F to degrees C

// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);// set the cursor to column 0, line 1
lcd.print(tempC);  //send the data to the computer
lcd.print((char)223); // degree symbol
lcd.print(“F “);
lcd.print(tempF);
lcd.print((char)223); // degree symbol
lcd.print(“C”);
delay(500);  //wait one second                  
}

Here is a quick video of the working Arduino Temperature Sensor with LCD Readout:

Well that’s it, I hope you liked this little hack. I know it’s not the hardcore model railroading stuff you’re looking for but it’s fits in and it’s certainly a building block for more Arduino Model Railroading hacks to come. Keep checking back! :)


Enhanced by Zemanta

  6 Responses to “Arduino Temperature to LCD Hack”

 Leave a Reply

(required)

(required)


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2012 Track Hacker Suffusion theme by Sayontan Sinha