Difficulty Level: Beginner
Project Overview:
A beautiful automatic night light that turns on softly when the room gets dark. The brightness and color of the light can be adjusted using a potentiometer, creating relaxing mood lighting. The OLED display shows real-time light level and status.
What You Will Learn:
Reading analog sensor values (LDR)
Controlling RGB LEDs (WS2812)
Using a potentiometer for user input
Basic conditional logic and smooth lighting effects
Components Required:
ESP32 CoreLab Main Board
LDR Sensor
Potentiometer Module
WS2812 RGB LED (Onboard)
Concept & Working Principle:
The LDR (Light Dependent Resistor) changes its resistance based on surrounding light intensity. In bright light, resistance is low; in darkness, resistance is high. The ESP32 reads this analog value.
If the light level drops below a threshold set by the potentiometer, the WS2812 RGB LED and LED Hub gently turn on with a warm color. The potentiometer also controls the brightness and color hue, giving a smooth mood-lighting effect.
Hardware Connection:
LDR → 4-pin connector (3.3V, A , D,GND)
Potentiometer → 3-pin connector (3.3V, SIG,GND)
WS2812 Onboard on ESP32 CoreLab
Code:
Note: This project uses the Adafruit_NeoPixel library to control the WS2812 RGB LED. see How to install a library
Code Explanation:
analogRead(LDR_PIN): Reads current light intensity
analogRead(POT_PIN): Reads user-controlled brightness
map() function: Converts raw values into useful percentage and brightness range
Conditional if logic turns on lights only when dark
Working / Output :
When you cover the LDR or switch off the room light, the WS2812 and LED Hub will smoothly glow with a warm color. Turning the potentiometer changes both brightness and feel of the light. The light turns off automatically when the room becomes bright again.
Image
GIF
Video Tutorial :