LCDs facinate me very much. The second thing I did with my Arduino and the 16×2 LCD was to hook it up as per this schematic and try to say hi 🙂
Then I used the same logic to display the temperature.
Things used for this project are
- Arduino UNO
- 16×2 Hitachi compatible LCD
- LM35 Temperature sensor
This tutorial was used for the project.
The LM35 was wired as shown in the figure.
The major challenge faced during this project was writing the float temperature to LCD. There seems to be some issue with converting float to string in Arduino. After a lot of search I stumbled across dtostrf(). This funciton converts any floating boint number to a string of difined length with defined precision in a predifined buffer which can be printed on the LCD via LiquidCrystal library’s lcd.print().
Video of the thermometer
Source Code (modified)
//TMP36 Pin Variables
#include <LiquidCrystal.h>
#include <stdio.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int sensorPin = 0; //the analog pin the TMP36’s Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
/*
* setup() – this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
}
void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor
float reading = analogRead(sensorPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0
;
// print out the voltage
Serial.print(voltage); Serial.println(” volts”);
// now print out the temperature
float temperatureC = (voltage -.05 )*100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge – 500mV) times 100)
int decimal,fraction;
char temp[5];
dtostrf(temperatureC,5,1,temp);
Serial.print(temp);
//Serial.print(temperatureC); Serial.println(” degree C”);
lcd.setCursor(1, 0);
lcd.write(temp);lcd.write(” degree C”);
// now convert to Fahrenheight
delay(1000);
//
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
//Serial.print(temperatureF); Serial.println(” degrees F”);
delay(1000); //waiting a second
}