LCD with Light and Temperature Sensors

LCD with Light and Temperature Sensors

Overview:

Here we will use the LCD to display real-time data that we are getting from a light sensor and a temperature sensor.

Parts:

1 - Arduino Uno

1 - LCD Display with I2C adapter

1 - LM35 Temperature Sensor

1 - 220 Ω Resistor

Many Jumper Wires

Wiring Guide:

Wire up your LCD screen the same way as in previous lessons

Arduino
LCD Screen

5V

5V

GND

GND

A4

SDA

A5

SCL

Temperature Sensor and Light Sensor Wiring

Arduino Code:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int tempPin = A1;
const int lightPin = A0;

// set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3f, 20, 4);

//initialize variables to store light and temp values
int val = 0;
int light = 0;

void setup()
{
  Serial.begin(9600);
  lcd.init(); // initialize the lcd
  lcd.backlight(); //turn on the backlight
}

void loop()
{
  lcd.setCursor(0, 0);
  val = analogRead(tempPin);
  float temp = (val / 1024.0) * 500; //convert raw value to temp in celcius  lcd.print("Tempis: ");
  lcd.print(temp);
  lcd.print("C");
  lcd.setCursor(0, 1); //move cursor to bottom row
  light = analogRead(lightPin);
  lcd.print("Light level: ");
  lcd.print(light);
  delay(500);
}

Last updated

Was this helpful?