Simplest Arduino based thermometer using LM35 and LCD i2c screen
Hi everyone, this is a quick diy thermometer based on Arduino and LM35 temperature sensor and shown on a LCD I2C screen
Wiring:
LCD i2c Library: Download library
Code:
//Arduino Thermometer using LM35DZ sensor with a LCD display //SurtrTech Youtube channel #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 }
Categories
Yassine View All
Automation and Electrical Engineer, Electronics amateur trying to share my little projects.
Good night;
Below is the correct Source Code, since the one on your Site contains some errors:
//Arduino Thermometer using LM35DZ sensor with a LCD display
//SurtrTech Youtube channel
#include //Libraries for I2C and LCD
#include
#include
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 😀
#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 😀
delay(1000); //Refresh every 1s
}
ERROR MESSAGE – Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: “Arduino Uno”
LM35_temperature_display_on_I2C_LCD:5:37: error: #include expects “FILENAME” or
#include //Libraries for I2C and LCD
^
LM35_temperature_display_on_I2C_LCD:7:9: error: #include expects “FILENAME” or
#include
^
LM35_temperature_display_on_I2C_LCD:9:9: error: #include expects “FILENAME” or
#include
^
exit status 1
#include expects “FILENAME” or
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.