Arduino LCD Thermometer With LM35 Temp Sensor

by WWC in Circuits > Arduino

120908 Views, 43 Favorites, 0 Comments

Arduino LCD Thermometer With LM35 Temp Sensor

04.bmp
05.bmp
02.bmp
03.bmp
01.bmp
06.bmp
07.bmp
08.bmp
09.bmp
10.bmp
11.bmp
12.bmp
FRitzLM35.png
: 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.

Reference

PDF logo.jpg
LCD Pinout.png

Downloads

(codeTime);

ArduinoLogo.gif
I doubt that i am going to build this any farther. The goal for me with this is to get more familial and better with code, coding.
I have included the sketch in a download also. When code is coppied and pasted into and ible it tends to scatter stuff around.
I have commented the code best i know how, but if somethings not correct or could be cleaned up please leave a comment. 



/*
October 25 2012
Based off of a project by DJ Mentzik.
Enhanced and modified by WWC.
Supporting documents can be found at https://www.instructables.com/member/WWC/
Use and modify as needed.

 

To wire your LCD screen to your Arduino, connect the following pins:
LCD Pin 6 to digital pin 12
LCD Pin 4 to digital pin 11
LCD Pin 11 to digital pin 5
LCD Pin 12 to digital pin 4
LCD Pin 13 to digital pin 3
LCD Pin 14 to digital pin 2
Additionally, wire a 10K pot to +5V and GND, with it's wiper (output) to LCD screens VO pin (pin3).


*/

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

                                                                 //declare variables
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;

                                             
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);                          // initialize the library with the numbers of the interface pins

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

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

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


}

void loop()
{
Serial.println("");                                            // Blank line for spacing in the serial monitor
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("Current Temp is: ");                                // Print text to LCD
lcd.setCursor(1, 1);                                           // Set LCD cursor position (column 1, row 1)
lcd.print("  Celcius   ");                                     // Print text to LCD
lcd.setCursor(12, 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
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

                                                               // Send Results to Serial Monitor
Serial.println("New measurement:");
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(0, 1);                                           // Set LCD cursor position (column 0, line 1)
lcd.print(" Fahrenheit ");                                     // Print text to LCD
lcd.setCursor(12, 1);                                          // Set LCD cursor position (column 12, line 1)
lcd.print(tempf);                                              // Send the data to the 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
}