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
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.
๐ฆ Where to Buy
Shopee:
Lazada:
Aliexpress:
๐ฅ 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