Simplest Thermometer With Arduino and LCD Display

by AYassineLebouiha in Circuits > Arduino

4150 Views, 11 Favorites, 0 Comments

Simplest Thermometer With Arduino and LCD Display

Arduino (thermometer) temperature sensor LM35 with LCD display

Welcome to you all, in this instructable, I will show the simplest Arduino based thermometer for beginners

Components and Wiring

LM35.png

This is what you will need to do this project:

1- Arduino board, I used here an Arduino Uno.

2- 16*2 LCD display with I²C Bus soldred on it.

3- Temperature sensor I used here an LM35DZ.

4- Jump wires.

5- Breadboard.

Wiring:

-Temperature sensor have 3 pins from left to right (Vcc, Vout, GND)

-LCD I2C display have 4 pins (names are written on them)

Both Vcc and GND are connected to 5v and GND from arduino

Vout from sensor is connected to Analog input A0

SDA and SCL are connected respectively to Analog inputs A4 and A5

Arduino Code

This is the code I used

--------------------------------------------------------------------------------------------------

//Arduino Thermometer using LM35DZ sensor with a LCD display<br>

//SurtrTech Youtube channel (LEBOUIHA)
#include <wire.h> //Libraries for I2C and LCD
#include <lcd.h>
#include <liquidcrystal_i2c.h>


float temp;   //Variable where we will stock the temperature value
int tempPin = 0; //Pin used with the sensor output here it's A0
#define I2C_ADDR 0x27 //I2C Adress
#define BACKLIGHT_PIN 3 //LCD Stuffs :D
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup() {
  Serial.begin(9600);
  lcd.begin (16,2);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
  
}
void loop()
{
  temp = analogRead(tempPin); //Reading the value from the analog input
  temp = temp * 0.48828125; //Sensor calibration to get the real value
  lcd.clear();
  
    lcd.setCursor (0,0); //Start writing on 0.0 on lcd screen
    lcd.print("Temperature");
    lcd.setCursor (0,1);
    lcd.print(temp); //Temperature value
    lcd.print(" C"); //Celsius of course :D
     
     delay(1000); //Refresh every 1s
}

Probable I2C Address Problem

If you encounter an I2C LCD address problem, so if you have it, I suggest to use the I2C address scanner code, first connect your LCD I2C like before and upload this code, after uploading open the serial monitor to know what's the bus address

-----------------------------------------------------------------------------------

#include <wire.h>
void setup() { Wire.begin(); Serial.begin(9600); while (!Serial); //wait for serial monitor Serial.println("\nI2C Scanner"); } void loop() { byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; for(address = 1; address < 127; address++ ) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Unknow error at address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } } if (nDevices == 0) Serial.println("No I2C devices found\n"); else Serial.println("done\n"); delay(5000); // wait 5 seconds for next scan }