Week 8 – Night Light with Arduino

Project Overview

This project is a hands-free, light-activated night light designed to automatically turn on an LED when it’s dark and turn it off when it’s light. Using a light-dependent resistor (LDR) as a sensor, the circuit detects ambient light levels and toggles the LED accordingly. This is ideal as a night light or as an indicator light in dark conditions.

Materials Used

  • Arduino Uno: The microcontroller board used to control the circuit.
  • Jumper Wires: For making connections between components.
  • Resistors:
    • 330 Ohm resistor (for the LED, to limit current).
    • 10k Ohm resistor (as a pull-down resistor for the LDR to ensure stable readings).
  • LED: Acts as the night light, illuminating when ambient light is low.
  • Light-Dependent Resistor (LDR): Detects the light level in the environment and changes its resistance accordingly.

    Arduino Code

    The following code reads the light level from the LDR and turns the LED on when the light level drops below a specified threshold (indicating darkness) and off when the light level is above this threshold (indicating light):

int ldrPin = A0;           
int ledPin = 9;           
int threshold = 500;       

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

void loop() {
  int ldrValue = analogRead(ldrPin);  
  Serial.println(ldrValue);           
  
  // Check if the light level is below the threshold
  if (ldrValue < threshold) {
    digitalWrite(ledPin, HIGH);  
  } else {
    digitalWrite(ledPin, LOW);   
  }
  
  delay(100);  
}

Improvements

    • Automatic Brightness Adjustment: Incorporate PWM to adjust the LED brightness gradually based on light levels, creating a dimmer effect in low light.
    • Sensitivity Adjustment: Experiment with different threshold values based on the ambient light conditions in various environments. This ensures accurate and responsive behavior.

Video Demonstration

Leave a Reply