#include <LiquidCrystal.h> // include the liquid crystal library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
int tempPin = A0; // assign the analog pin A0 to tempPin
float temperature; // variable to store temperature
void setup() {
lcd.begin(16, 2); // set up the LCD's number of columns and rows
lcd.print("Temperature:"); // display "Temperature:" on the first line of the LCD
}
void loop() {
temperature = analogRead(tempPin); // read the voltage from the temperature sensor
temperature = temperature * 0.48828125; // convert the voltage reading to Celsius
lcd.setCursor(0, 1); // move the cursor to the second line of the LCD
lcd.print(temperature); // display the temperature reading on the second line of the LCD
lcd.print(" C"); // display the unit of temperature on the second line of the LCD
delay(1000); // wait for a second before taking another temperature reading
}
Arduino code for displaying temperature in LCD using DHTHere's an example Arduino code that displays temperature readings on an LCD screen:
Code:#include <LiquidCrystal.h> // include the liquid crystal library LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins int tempPin = A0; // assign the analog pin A0 to tempPin float temperature; // variable to store temperature void setup() { lcd.begin(16, 2); // set up the LCD's number of columns and rows lcd.print("Temperature:"); // display "Temperature:" on the first line of the LCD } void loop() { temperature = analogRead(tempPin); // read the voltage from the temperature sensor temperature = temperature * 0.48828125; // convert the voltage reading to Celsius lcd.setCursor(0, 1); // move the cursor to the second line of the LCD lcd.print(temperature); // display the temperature reading on the second line of the LCD lcd.print(" C"); // display the unit of temperature on the second line of the LCD delay(1000); // wait for a second before taking another temperature reading }
Note: This code assumes that you are using a LM35 temperature sensor, which outputs a voltage proportional to the temperature in Celsius. If you are using a different sensor, you may need to adjust the conversion factor in the code.
Here's an example Arduino code that displays temperature readings on an LCD screen using the DHT temperature and humidity sensor:Arduino code for displaying temperature in LCD using DHT
#include <LiquidCrystal.h> // include the liquid crystal library
#include <DHT.h> // include the DHT library
#define DHTPIN 2 // assign the DHT sensor pin
#define DHTTYPE DHT11 // set the sensor type
DHT dht(DHTPIN, DHTTYPE); // initialize the sensor
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
void setup() {
lcd.begin(16, 2); // set up the LCD's number of columns and rows
lcd.print("Temperature:"); // display "Temperature:" on the first line of the LCD
dht.begin(); // start the sensor
}
void loop() {
float temperature = dht.readTemperature(); // read the temperature from the sensor
lcd.setCursor(0, 1); // move the cursor to the second line of the LCD
lcd.print(temperature); // display the temperature reading on the second line of the LCD
lcd.print(" C"); // display the unit of temperature on the second line of the LCD
delay(1000); // wait for a second before taking another temperature reading
}