Instructables

Arduino LCD Thermometer with LM35 Temp Sensor

: UPDATE OF PIN 13: Thanks to cybersb for the catch.
The Fritzing schematic shows using pins 12 and 13. This not correct. Should use the pins listed in the code, pins 11 and 12.


This is as the title implies, An Arduino powered LCD monitored thermometer that uses an LM35 temp sensor for the temp readings. If you have never worked with an LCD before like me some things can be a little confusing such as: the first line, the top line is line 0. The second line, bottom line is line 1. But no matter once some of these things are figured out its easier to move on.

These run one time at power up:

First display line 0 is Waynes World
First display line 1 is Thermometer
Second display line 0 is LCD Displayed
Second display line 1 is Averaged Temp

These run over and over in the loop:

Third display line 0 is Current Temp is:
Third display line 1 is Celius [ tempC displayed ]
Fourth display line 0 is Current Temp is:
fourth display line 1 is Fahrenheit [ tempF displayed]

So the information that changes every 3 seconds on the display is it changes on line 1 from display three to display four. Celcius tempC] to Fahrenheit [tempF]

LCD's have one big plus that makes it easier for us to work with them. The LCD library.
When you download and install the Arduino program that is just one of the many libraries that are included.

While this LCD is after-after market it still utilizes the extremely common HD44780 parallel interface chipset. Lucky for me.
It can be used in 4-Bit or 8-Bit mode. We are using the 4-Bit mode here. That's why pins 7,8,9 and 10 of the LCD are not used.
If you are using 8-Bit mode then those pins will be used also.

This is the second time i have written this sketch. The first time i deleted it right after i finished it. Woops!
It' s good really, i need all the practice i can get for coding.

YouTube video link.

 
Remove these adsRemove these ads by Signing Up
jpls051 month ago

hello :D can you send me the code of this project ? it will help me a lot. thank you ! :D

tejesh4k7 months ago
I want a code for temperature and time without using rtc
calebjc made it!8 months ago

Awesome! Thank you so much. I noticed that the display of F and C seemed swapped in value (C was F), but accurate. Was that a bug?

Any advice for coding the addition of a PowerSwitch Tail II (https://www.sparkfun.com/products/10747) and having it turn on until the sensor measures a certain avg temp, and then off? I'm wanting to hook up a simple tiny heater in a simple 2ft seed starter greenhouse and keep the temp up, but I'm not much of a coder. I'll be using a plastic bin and this heater BTW with a cup of water to hold the heat and provide humidity. http://amzn.com/B000CO89T8

tempsense.jpg
bizzabazza9 months ago

Great project. Thank you! I am also using tmp36gz and had to adjust calculation variables as per the comment from citin. Except I had to change the *25 to *34 to get a near accurate reading.

bizzabazza9 months ago

Great project. Thank you! I am also using tmp36gz and had to adjust calculation variables as per the comment from citin. Except I had to change the *25 to *34 to get a near accurate reading.

bizzabazza9 months ago

Great project. Thank you! I am also using tmp36gz and had to adjust calculation variables as per the comment from citin. Except I had to change the *25 to *34 to get a near accurate reading.

WillerKrautz10 months ago

Hi, I am starting with arduino and I am using the mega 2560, That program works very good, well my problem is, How can I read data from SD reader and write data too. When I try read, the lcd display goes clear and never comes back and when do reset on mega a lot trash comes to display.

/*

October 25 2012

Based off of a project by DJ Mentzik.

Enhanced and modified by WWC.

Supporting documents can be found at http://www.instructables.com/member/WWC/

Use and modife as needed.

Displays Current, 8 sec Average, Max and Min Temperature.

To wire your LCD screen to your Arduino, connect the following pins:

LCD Pin 6 to digital pin 12 - mega 50

LCD Pin 4 to digital pin 11 - mega 51

LCD Pin 11 to digital pin 5 - mega 43

LCD Pin 12 to digital pin 4 - mega 42

LCD Pin 13 to digital pin 3 - mega 41

LCD Pin 14 to digital pin 2 - mega 40

Additionally, wire a 10K pot to +5V and GND, with it's wiper (output) to LCD screens VO pin (pin3).

* SD card attached to SPI bus as follows:

** MOSI - pin 11 - mega 51

** MISO - pin 12 - mega 50

** CLK - pin 13 - mega 52

** CS - pin 4 - mega 44

*/

#include <SPI.h>;

#include <SD.h>

#include <LiquidCrystal.h> // include the LCD driver library

// declare variables

char Room_ID[]="";

int ThmCode = 0; // Variable for Thermometer unit number

float tempC = 0; // Variable for holding Celcius temp (floating for decimal points precision)

float tempf = 0; // variable for holding Fareghneit temp

int tempPin = 0; // Declaring the Analog input to be 0 (A0) of Arduino board.

float samples[8]; // Array to hold 8 samples for Average temp calculation

float maxi = 0,mini = 100; // Max/Min temperature variables with initial values. LM35 in simple setup only measures Temp above 0.

int i;

File myFile; // about SD card

LiquidCrystal lcd(50,51,43,42,41,40); // Mega ////(12, 11, 5, 4, 3, 2); //Uno // initialize the library with the numbers of the interface pins

void setup()

{

Serial.begin(9600); // Opens serial port, sets data rate to 9600 bps

ThmCode = 1;

lcd.begin(16, 2); // Set up the LCD's number of columns and rows:

lcd.clear();

lcd.setCursor(2, 0); // Set LCD cursor position (column, row)

lcd.print("Waynes World"); // Print text to LCD

lcd.setCursor(3, 1); // Set LCD cursor position (column,row)

lcd.print("Thermometer"); // Print text to LCD

delay(5000); // wait 500ms // Delay to read text

lcd.clear(); // clear LCD display // Clear the display

lcd.setCursor(2, 0); // Set LCD cursor position (column, row)

lcd.print("LCD Displayed"); // Print text to LCD

lcd.setCursor(1, 1); // Set LCD cursor position (column, row)

lcd.print(" Averaged Temp "); // Print text to LCD

delay(5000); // Delay to read text

lcd.clear(); // Clear LCD

///// SD-Card initializing /////

Serial.print("Initializing SD card...");

// On the Ethernet Shield, CS is pin 4. It's set as an output by default.

// Note that even if it's not used as the CS pin, the hardware SS pin

// (10 on most Arduino boards, 53 on the Mega) must be left as an output

// or the SD library functions will not work.

pinMode(53, OUTPUT);

if (!SD.begin(4)) {

Serial.println("initialization failed!");

return;

}

else

{

Serial.println("initialization done.");

delay(1000);

// open the file. note that only one file can be open at a time,

// so you have to close this one before opening another.

// myFile = SD.open("test.txt", FILE_WRITE);

// if the file opened okay, write to it:

// if (myFile)

//{

// Serial.print("Writing to test.txt...");

// myFile.println("testing 1, 2, 3.");

//// close the file:

// myFile.close();

// Serial.println("done.");

// } else {

// // if the file didn't open, print an error:

// Serial.println("error opening test.txt");

// }

// re-open the file for reading:

myFile = SD.open("test.txt");

if (myFile) {

Serial.println("test.txt:");

// read from the file until there's nothing else in it:

while (myFile.available())

{

Serial.write(myFile.read());

}

Serial.readBytes(Room_ID,7);

// close the file:

myFile.close();

Serial.println(Room_ID);

}

else

{

// if the file didn't open, print an error:

Serial.println("error opening pacient.txt");

}

}

}

void loop()

{

Serial.println(""); // Blank line for spacing in the serial monitor

Serial.print("Room Identification: ");

Serial.println(Room_ID);

Serial.println("You are looking at a project built by WWC."); // Print text to Serial monitor

Serial.print("Feal free to use and modife as needed.");

Serial.println(""); // Blank line for spacing in the serial monitor

Serial.print("LM35 Raw data: "); // Print text to Serial monitor

Serial.println(analogRead(tempPin)); // Displays on serial monitor the sampled value before conversion to real Temperature reading

// Start of calculations FOR loop.

for(i = 0;i<=7;i++){ // gets 8 samples of temperature

samples[i] = ( 4.4 * analogRead(tempPin) * 100.0) / 1024.0; // conversion math of LM35 sample to readable temperature and stores result to samples array.

// 5v is the supply volts of LM35. Change appropriatelly to have correct measurement. My case is 4.4Volts.

// If powered from USB then use value 4.4v to 4.6v. If power is 7v< to the Arduino then use 4.9v to 5.1v

// The voltage is critical for accurate readings

Serial.println(samples[i]); // Print samples [i] to sertiual monitor

// ( LCD note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 0); // Set LCD cursor position (column 0, row 0)

lcd.print("Room: ");

lcd.setCursor(6,0);

lcd.print(Room_ID);

lcd.setCursor(0, 1); // Set LCD cursor position (column 1, row 1)

lcd.print("Temp is: "); // Print text to LCD

lcd.setCursor(9, 1); // Set LCD cursor position (column 12, row 1)

lcd.print(samples[i]); // print current Temp sample to LCD

tempC = tempC + samples[i]; // do the addition for average temperature

lcd.setCursor(14,1);

lcd.print(" C"); // Print text to LCD

delay(800); // wait 800ms

} // END of FOR loop

Serial.println(""); // Blank line for spacing in the serial monitor

Serial.println(""); // Blank line for spacing in the serial monitor

tempC = tempC/8.0; // calculated the averare of 8 samples in Celcius

tempf = (tempC * 9)/ 5 + 32; // converts to fahrenheit

if(tempC > maxi) {maxi = tempC;} // set max temperature

if(tempC < mini) {mini = tempC;} // set min temperature

Serial.print("Thermometer Code is: "); // Send Results to Serial Monitor

Serial.println(ThmCode); // Send the data to the computer

Serial.println("now the New measurement:"); // Send the data to the computer

Serial.print(" Average Temperature in Celcius is " ); // Print text to Serial monitor

Serial.println(tempC);//send the data to the computer // Send the data to the computer

Serial.print(" Average Temperature in Farenait is " ); // Print text to Serial monitor

Serial.println(tempf);//send the data to the computer // Send the data to the computer

Serial.print(" MAX Temperature in Celcius is " ); // Print text to Serial monitor

Serial.println(maxi);//send the data to the computer // Send the data to the computer

Serial.print(" MIN Temperature in Celcius is " ); // Print text to Serial monitor

Serial.println(mini);//send the data to the computer // Send the data to the computer

// Send results to LCD.

lcd.setCursor(9, 1); // Set LCD cursor position (column 0, line 1)

lcd.print(" Fahrenheit "); // Print text to LCD

lcd.setCursor(9, 1); // Set LCD cursor position (column 12, line 1)

lcd.print(tempf); // Send the data to the LCD

lcd.setCursor(14,1);

lcd.print(" F"); // Print text to LCD

delay(6000); // Wait 3 seconds to display the Fahrenheit temp and 3 seconds to display results to LCD screen befor starting the loop again = 6 seconds.

tempC = 0; // Set tempC to 0 so calculations can be done again

}

if somebody can help me, I appreciate. Thanks in advance.

My e-mail address is krautzhomeimprovement@gmail.com

Akash jaiswal10 months ago
Really loved your project and completed it in 2 hours....nice instructables bro........the best part of this is the serial monitor data which i was unable to do it perfectly..........THANKZZZ A LOT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
WWC (author)  Akash jaiswal10 months ago
I am glad this has helped you.
cybersb10 months ago
Hey! I just completed the build and it's working like a charm! Thanks! :)

However, I hooked up the wiring based on the schematic picture you uploaded (I like to jump into the middle of things without reading first), which clearly points at digital 12 + 13 and in the code it says 11 + 12. I double checked my LCD soldering 3 times before I realised this. Is there something I'm missing or is the schematic drawing actually not correct?

Nicely done btw! ;)
WWC (author)  cybersb10 months ago
Ya you have found a discrepancy, nicely done. I would use 11 and 12.
Good work, i am glad this working for you.
cybersb WWC10 months ago
Thanks for the credit there! ;) I was so glad to make this work as this was the second project I ever did on the Arduino. I actually moved those two pins over to 6 and 7 as my Ethernet shield is using those upper pins.
WWC (author)  cybersb10 months ago
I have updated the ible and gave you the credit you deserve for the catch. Thanks
nofeel10 months ago
I've already done. but still can not :(
WWC (author)  nofeel10 months ago
Recheck your wiring.
nofeel10 months ago
why my lcd blank??? just backlight... thkz
WWC (author)  nofeel10 months ago
Adjust the contrast
iceng2 years ago
Eloquently straight forward wiring, good coding nice project..

Am I imagining your C° scale only does even numbers ??

A
WWC (author)  iceng2 years ago
Thank A.
This is quite a bit better than my first coding projects.

It seams to be displaying an odd number in the tens, ones and tenths places, if i understand you question correctly.

But there is a difference in the C compared to the F. I think you spotted it. I haven't been able to fix it. The C will display to the second temp changes. You can watch the numbers change on the display, while the F will display a single temp value. No change visible on current display showing.
All that is hard to explain.
If you watch the video you can see what the C value does compared to the F value.
iceng WWC2 years ago
I did watch it but the first time though I did not pay attention till half way through.

On the second watching .... Yes, there are two odd number C° values.

Sorry to cast aspersions half cocked :-)

WWC (author)  iceng2 years ago
Magnanimous
afadhel WWC11 months ago
HI WWC
I have an Crowduino GSM/GPRS shield and crowduino with ATMega 328 shield .
and I want to monitor the LM35 sensor like if the temperature increased more than 28C
or decreased less than 23, the gsm shield send sms to my phone NO

i want your help please..

thank you alot
WWC (author)  afadhel11 months ago
Sorry i have never worked with those GPS shields. I would suggest to research this on Google. Good Luck.
citin1 year ago
it works ! but my sensor is a" tmp 36gz" i changed .. samples [i] = (4.4 * analogRead(tempPin) *1000) /1024; to samples [i] = (4.4 * analogRead(tempPin) *25) /1024; so i get nearly real temprature .
WWC (author)  citin1 year ago
This great i am glad you got it sorted out. Will you be posting an ible?
I now have made a 8x10 LED matrix with scrolling temp date and time, no ible on that tho.
citin WWC1 year ago
I m new to this instructables what did ible mean ? i create this ,it based on your stuff but its not ready now.

http://www.instructables.com/id/Arduino-LCD-Thermometer-with-TMP36GZ-Temp-Sensor-b/
WWC (author)  citin1 year ago
ible is short for Instructable
citin1 year ago
Hy i try to build it after your guid . But i miss the wires in the fritzing picture, on the Photo there are more wires.
The Serial monitor gives the feedback in farenheit and c°c but it shows not the real tempratur it shows 65°c but we have 19°c.any solution?
Greatings.
WWC (author)  citin1 year ago
Hi citin

Great you have decided to build one of my projects.

Your question is very vague on which wires so i will have to give the best answer i can.
Every picture has an explanation of where every wire goes. Maybe you did not see, but if you hover over a picture a drop down will appear with description of that individual picture.
Also in the code every wire is accounted for as it needs a place to go.

For the incorrect temperature readings: Are you using an LM35 temp sensor? The LM335 is similar but will give different readings.
Has the code been altered?
Triple check the wiring!!!
Without more information i do not have any better answers.

Let me know if you need more help as i will help the best i can and i would like to see your project also.

Good Luck
Wayne
citin WWC1 year ago
now i know it wire 15 and 16 on the lcd display .. pos. gnd but didn't work i have to solder the wires to the lcd again. First time i did this , i thinks its bad work from me.
but not today i will try it tomorrow.