Friday, July 25, 2025

Smart LED Dimming with LDR & Arduino | Ambient Light Sensor Project

Have you ever seen lights that automatically dim or brighten based on the lighting around them? In this project, we’ll show you how to make your own auto-dimming LED using an Arduino Uno and a Light Dependent Resistor (LDR) sensor.

Smart LED Dimming

๐Ÿ“ฆ What You’ll Need

To get started, you will need the following components:

Components required for this tutorial

✅ Arduino UNO × 1
✅ 3-pin LDR Module × 1
✅ Jumper Wires × 1
✅ USB cable for Arduino × 1
✅ Resistor 220ฮฉ × 1
✅ Breadboard × 1

๐Ÿ› ️ Circuit Wiring

Here’s how to connect each component to the Arduino:

3-pin LDR module wiring

3-pin LDR Module 
✅ VCC → 5V on Arduino
✅ GND → GND on Arduino
✅ A0 → Analog pin A0 on Arduino

LED and resistor wiring

LED and Resistor
✅ LED Anode (long leg) → Digital pin 9 on Arduino
✅ LED Cathode (short leg) → 220ฮฉ resistor → GND on Arduino

The connection between components and Arduino

๐Ÿ’ป Uploading the Code

After wiring everything up, connect the Arduino to your computer using a USB cable.  Then, upload the following code, or you can download the code HERE.
int ldrPin = A0;
int ledPin = 9;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int ldrValue = analogRead(ldrPin);
  int ledBrightness = map(ldrValue, 0, 1023, 255, 0); // Invert brightness
  analogWrite(ledPin, ledBrightness);
  delay(100);
}

Open Arduino IDE and copy-paste the code
The analogRead() function reads the ambient light level from the LDR (ranging from 0 to 1023), then map() converts that value to a PWM range (255 to 0) to invert the brightness, and finally analogWrite() sets the LED brightness based on the mapped value.

๐Ÿงช Test the System

Once you've uploaded the code and completed the wiring, it's time to test how the system reacts to different light levels:

Observe the LED in normal lighting—it should appear dim or completely off if the room is bright.

Slowly cover the LDR sensor with your hand or a piece of paper. You should see the LED gradually get brighter as the light decreases.

Fully cover the LDR sensor with your hand the LED will get brighter as the light level drops.

๐Ÿ“Œ Conclusion

This auto-dimming LED project is a fantastic introduction to how sensors can make electronics smarter. You’ve learned how to read light levels with an LDR, process the input, and control an LED with PWM based on real-world light conditions.

๐ŸŽฅ Watch the Full Video Tutorial


๐Ÿ”” If you found this guide helpful, share it with fellow makers! For more tutorials, subscribe to our YouTube channel and follow us on social media. ๐Ÿš€

#ArduinoProject #AutoDimLED #LDREngineering #PWMControl #SmartLighting #DIYElectronics #Maker

No comments:

Post a Comment