Automatic Night Lamp Using ESP32 and LDR – Fun Grade 8 STEM Activities

Automatic Night Lamp Using ESP32 and LDR project setup on breadboard for Grade 8 STEM Activities

Technology has made our daily lives easier through automation. One common example is street lights that automatically turn ON at night and turn OFF during the day without human intervention. In this Fun Grade 8 STEM Activities project, students will learn how to create an Automatic Night Lamp Using ESP32 and LDR. This project combines electronics, programming, and sensor technology to build a smart lighting system that responds to surrounding light conditions.

The project uses an ESP32 microcontroller, an LDR (Light Dependent Resistor), and an LED. The LDR senses the amount of light in the environment and sends information to the ESP32. Based on the detected light intensity, the ESP32 decides whether the LED should turn ON or OFF. This simple yet powerful project introduces students to the fundamentals of automation, sensors, and embedded programming.

ESP32 development board used in Automatic Night Lamp Using ESP32 and LDR project

What is an Automatic Night Lamp Using ESP32 and LDR?

An automatic night lamp is a lighting system that turns ON automatically when it becomes dark and switches OFF when sufficient light is available. Such systems are commonly used in:

  • Street lights
  • Garden lighting
  • Parking areas
  • Home entrances
  • Security lighting systems

The main purpose is to save electricity and eliminate the need for manual switching.


Components Required

To build the Automatic Night Lamp Using ESP32 and LDR, the following components are required:

  • ESP32 Development Board
  • LDR (Light Dependent Resistor)
  • LED
  • Resistors
  • Breadboard
  • Jumper Wires
  • USB Cable
  • Laptop with Arduino IDE Installed

These components are affordable and commonly used in beginner electronics projects.


Understanding the ESP32

The ESP32 is a powerful microcontroller widely used in IoT and automation projects. It provides:

  • Multiple GPIO pins
  • Analog input support
  • Digital output support
  • Wi-Fi and Bluetooth connectivity
  • Fast processing capabilities

In this project, the ESP32 reads data from the LDR and controls the LED accordingly.


What is an LDR?

LDR stands for Light Dependent Resistor. It is a sensor whose resistance changes according to the amount of light falling on it.

Characteristics of an LDR

  • High light intensity → Low resistance
  • Low light intensity → High resistance
  • Works as a photoresistor
  • Used in automatic lighting systems

The LDR helps the ESP32 determine whether it is day or night.

LDR light dependent resistor sensor used for automatic light detection in ESP32 project

How Does the LDR Work?

The working principle of an LDR is based on photoconductivity.

The LDR contains a photosensitive material called Cadmium Sulfide (CdS). When light falls on the surface:

  1. Photons strike the CdS material.
  2. Electrons become energized.
  3. More free electrons are produced.
  4. Electrical conductivity increases.
  5. Resistance decreases.

When the surrounding light decreases:

  1. Fewer photons hit the sensor.
  2. Fewer electrons become active.
  3. Conductivity decreases.
  4. Resistance increases.

This change in resistance is measured by the ESP32 and used to control the LED.

Working principle of LDR sensor showing resistance changes with light intensity

Circuit Connections of Automatic Night Lamp Using ESP32 and LDR

The Automatic Night Lamp Using ESP32 and LDR project uses a simple voltage divider circuit.

LDR Connections

LDR TerminalConnection
Terminal 1GPIO 34
Terminal 25V Supply

Resistor Connection

ComponentConnection
ResistorBetween GPIO 34 junction and GND

LED Connections

LED TerminalConnection
Anode (+)GPIO 25
Cathode (-)GND through resistor

Complete Pin Mapping

ComponentESP32 Pin
LDR InputGPIO 34
LED OutputGPIO 25
Power5V
GroundGND

Working Principle of the Project

The ESP32 continuously reads the analog value coming from the LDR.

The sensor value changes depending on the amount of light in the environment.

Bright Environment

When there is sufficient light:

  • LDR resistance decreases.
  • Sensor reading becomes higher.
  • ESP32 detects daylight conditions.
  • LED remains OFF.

Dark Environment

When the surroundings become dark:

  • LDR resistance increases.
  • Sensor reading changes.
  • ESP32 detects night conditions.
  • LED turns ON automatically.

This behavior makes the system function as a smart night lamp.


Programming Logic

The program starts by defining the pins connected to the LDR and LED.

Setup Function

Inside the setup function:

  • Serial communication is started.
  • LED pin is configured as OUTPUT.
  • Initial settings are applied.

Loop Function

The loop function continuously performs three tasks:

  1. Read LDR sensor value.
  2. Compare it with a threshold value.
  3. Control LED accordingly.

The threshold value used in this project is approximately 25500.

Decision Logic

If LDR Value > 25500

  • Environment is bright.
  • LED remains OFF.

If LDR Value < 25500

  • Environment is dark.
  • LED turns ON.

This simple if-else logic creates the automatic night lamp behavior.


Testing the Project

After completing the circuit and uploading the code:

Daylight Test

Expose the LDR to a bright light source.

Expected Result:

  • LED remains OFF.

Night Mode Test

Cover the LDR with your hand or place it in a dark area.

Expected Result:

  • LED turns ON automatically.

Torch Light Test

Shine a flashlight on the LDR.

Expected Result:

  • LED turns OFF immediately.

These tests confirm that the system is responding correctly to changing light conditions.


Real-World Applications

The Automatic Night Lamp Using ESP32 and LDR project has many practical applications:

Smart Street Lights

Street lights can automatically operate without human intervention.

Garden Lighting

Garden lights can switch ON after sunset and OFF during sunrise.

Home Automation

Lights can automatically respond to environmental lighting conditions.

Security Systems

Outdoor lights can improve visibility and security during nighttime.

Energy Saving Systems

Automatic switching helps reduce unnecessary electricity consumption.

Automatic street light application using LDR sensor and ESP32 automation

Learning Outcomes

This Grade 8 STEM Activities project helps students learn:

  • Basics of ESP32 programming
  • Sensor interfacing techniques
  • Analog signal reading
  • Digital output control
  • Photoconductivity concepts
  • Voltage divider circuits
  • Automation system design
  • Real-world IoT applications

Students gain hands-on experience in combining hardware and software to solve practical problems.


Why Choose RoboSiddhi for STEM Learning?

https://robosiddhi.shop

At RoboSiddhi, students learn through project-based STEM education that combines robotics, coding, electronics, and innovation. Projects like Automatic Night Lamp Using ESP32 and LDR help learners understand real-world technology through practical experimentation.

RoboSiddhi’s STEM programs focus on:

  • Robotics and Automation
  • Arduino Programming
  • ESP32 and IoT Development
  • Artificial Intelligence Basics
  • Electronics Prototyping
  • Innovation and Problem Solving
  • Hands-on Learning Activities

These activities encourage creativity, critical thinking, and technical skills that prepare students for future technologies.


Conclusion

The Automatic Night Lamp Using ESP32 and LDR is an excellent beginner-friendly automation project for students. By combining an LDR sensor, ESP32 microcontroller, and LED, learners can create a smart lighting system that automatically responds to environmental light conditions.

This Fun Grade 8 STEM Activities project introduces important concepts such as photoconductivity, sensor interfacing, analog input processing, and automation. Beyond being a simple educational activity, it demonstrates how modern smart systems work in real-life applications such as street lights, garden lights, and home automation solutions.

Through projects like this, students develop valuable STEM skills while exploring the exciting world of electronics, coding, and automation.

Comments are closed.