Project 6

Light Level Sensor (Day/Night Detector)

Light Dependent Resistor (LDR) based light level sensor

Project Description

The automatic night light is a smart lighting system that uses an LDR (Light Dependent Resistor) to detect the level of ambient light and automatically control an LED. The resistance across an LDR varies with light intensity. This effect can be used to detect and measure changes in light intensity. In this project, the LDR connected in series with a resistor. A voltage is measured across the LDR which corresponds to the light intensity. The resistors connected in series uses the concept of a voltage divider

The Analog to Digital Converter (ADC) is fed with the output of the voltage divider. An ADC converts analog signals such a voltage that varies with light intensity to digital signals. The ADC is how most analogue signals are converted into numbers that a computer can process. A voltage signal varing from 0 to 5V is converted to 10 bit number ranging from 0 to 1023 (2 to the power 10).

Read more about the analogRead function here

During the day or when the surroundings are bright, the LDR senses high light intensity and the LED remains OFF. When it becomes dark, the LDR detects low light intensity, and the LED automatically turns ON. This project demonstrates how sensors and microcontrollers can be used to achieve automatic control, improve convenience, and save energy by ensuring the light operates only when needed.

Components
  • Arduino Uno
  • LDR
  • Jumper wires
  • Breadboard
  • Resistor (220 Ohm) - [Red-Red-Brown-Gold]
  • LED
Code

int ldrPin = A0;   // LDR sensor connected to A0
int ledPin = 7;    // LED connected to pin 7

int threshold = 500;  // Adjust based on your environment

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600); // For calibration
}

void loop() {
  int ldrValue = analogRead(ldrPin);  // Read LDR value
  Serial.println(ldrValue);           // Print to Serial Monitor

  if (ldrValue < threshold) {
    digitalWrite(ledPin, HIGH);   // Dark → LED ON
  } else {
    digitalWrite(ledPin, LOW);    // Light → LED OFF
  }

  delay(100);
}

Taking things further
  • The trigger point/threshold can be adjusted with a variable resistor or potentiometer
  • A timed delay can be started in combination with the timer so that the light only runs for a set amount of time after dark
  • It can be used with a PIR motion sensor so that the lights are only triggered when there is motion after dark and stay off when it is still bright outside