Ambient Light Meter with LCD Display and LED Indicator

To build a Simple Light Meter that uses a Light Dependent Resistor (LDR) to measure ambient light levels and display the result on an I2C LCD screen in percentage, along with an LED to indicate light levels, follow this guide. The project will read the LDR values, calculate the light intensity percentage, and display it on an LCD while using the LED to visually indicate whether the light level is high or low.

Components Needed:

  • Arduino (Uno, Nano, or any compatible board)
  • Light Dependent Resistor (LDR)
  • 10kΩ Resistor (for voltage divider)
  • 16×2 I2C LCD (for displaying light percentage)
  • LED (to indicate light levels)
  • 220Ω Resistor (for the LED)
  • Breadboard and jumper wires
  • USB cable to connect Arduino to your computer

Circuit Setup:

1. LDR and Resistor (Voltage Divider) Setup:

  • LDR and a 10kΩ resistor are connected in a voltage divider configuration to read the light intensity.
    • One end of the LDR connects to 5V on the Arduino.
    • The other end of the LDR connects to A0 (Analog Pin 0) and also connects to one end of the 10kΩ resistor.
    • The other end of the 10kΩ resistor connects to GND.
    • This creates a voltage divider, and the analog input pin (A0) reads the voltage based on the light level falling on the LDR.

2. I2C LCD Connection:

  • The I2C LCD requires only 4 wires:
    • GND to GND on Arduino.
    • VCC to 5V on Arduino.
    • SDA to A4 on Arduino (for Uno or Nano).
    • SCL to A5 on Arduino (for Uno or Nano).

3. LED Indicator:

  • LED:
    • Anode (long leg) of LED connects to digital pin 13 on Arduino.
    • Cathode (short leg) connects to GND via a 220Ω resistor.

The LED will turn on or off depending on whether the ambient light level is above or below a certain threshold.

Arduino Code:

The code reads the light intensity from the LDR, converts the value to a percentage (0-100%), and displays it on the LCD. If the light level is high (greater than a threshold), the LED will turn on; otherwise, it will turn off.

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

// Pin definitions
const int ldrPin = A0; // LDR connected to analog pin A0
const int ledPin = 13;  // LED connected to digital pin 13

// Initialize the LCD (I2C address 0x27 is common for many LCDs)
LiquidCrystal_I2C lcd(0x27, 16, 2); 

void setup() {
  // Start serial communication
  Serial.begin(9600);

  // Initialize the LCD
  lcd.begin(16, 2); 
  lcd.print("Light Meter");
  delay(2000); // Display "Light Meter" for 2 seconds
  lcd.clear();
  
  // Set LED pin as output
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // Read the value from the LDR
  int ldrValue = analogRead(ldrPin);

  // Map the LDR value to a percentage (0 to 100)
  int lightPercentage = map(ldrValue, 0, 1023, 0, 100);

  // Display the light level percentage on the LCD
  lcd.setCursor(0, 0); // Move cursor to top-left corner
  lcd.print("Light Level:");
  lcd.setCursor(0, 1); // Move cursor to the second row
  lcd.print(lightPercentage);
  lcd.print("%");

  // Control LED based on light level
  if (lightPercentage > 50) {
    digitalWrite(ledPin, HIGH); // Turn LED on if light > 50%
  } else {
    digitalWrite(ledPin, LOW);  // Turn LED off if light <= 50%
  }

  // Delay before the next reading
  delay(500);  // Update every 500 milliseconds
}

How the Code Works:

  1. Reading the LDR Value:
    • The analogRead(ldrPin) function reads the analog voltage from the LDR (which varies based on the ambient light) and returns a value between 0 and 1023.
  2. Mapping the Value:
    • The map() function scales this value from the range of 0-1023 to a more user-friendly 0-100, representing the light intensity as a percentage.
  3. Displaying the Value on LCD:
    • The light intensity in percentage is displayed on the 16×2 LCD screen using lcd.setCursor() to set the text position and lcd.print() to print the value.
  4. LED Indicator:
    • The LED is controlled based on the mapped light percentage. If the light percentage is greater than 50%, the LED is turned on; otherwise, it is turned off.
  5. Serial Output:
    • If you want to view the values in the Serial Monitor, you can print the percentage using Serial.print() in the loop.

Testing:

  • After uploading the code to your Arduino, you should see the LCD display showing the light level as a percentage.
  • LED Indicator: When the ambient light is above 50%, the LED will turn on, and if it’s below 50%, the LED will turn off.
  • You can test the system by changing the light in the room (e.g., shining a flashlight on the LDR or covering it with your hand to simulate low light).

Conclusion:

This project allows you to measure ambient light using an LDR, display the intensity as a percentage on an LCD, and use an LED to visually indicate whether the light is above or below a threshold. It’s a great introductory project for learning about sensors, analog-to-digital conversion, and interfacing with an LCD in Arduino!