Free tools Windows power users keep installed
One-click scans. No signup required.
Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Build an automatic low-voltage LED controller with an Arduino, an LDR (photoresistor), and a logic-level N-channel MOSFET. The LDR measures ambient light; when the measured level falls below a calibrated dusk threshold, the Arduino switches the LED strip on. A second, brighter threshold—called hysteresis—switches it off at dawn without flickering during changing light.
This guide is for low-voltage DC strips. The Arduino provides only the control signal; a separate power supply provides the strip current.
As an Amazon Associate I earn from qualifying purchases.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Choose the correct LED strip first
“LED strip” can mean three different systems:
- Single-color analog strip: one MOSFET controls on/off or PWM brightness. This is the simplest version and the circuit below is designed for it.
- Analog RGB or RGBW strip: each color channel needs its own MOSFET and PWM-capable Arduino output. The strip’s common positive connection normally goes to the external supply.
- Addressable strip: WS2811, WS2812, WS2810 and similar strips need a data signal and a suitable library such as FastLED. A MOSFET connected to the supply cannot control individual pixels.
Before buying parts, record the strip voltage, type, length, watts or amps per metre, connector polarity, and indoor or outdoor rating.
How the controller works
Ambient light → LDR voltage divider → Arduino analog input
↓
MOSFET gate signal
↓
External supply → LED strip
The LDR and a fixed resistor form a voltage divider. Use this arrangement:
Popular on Amazon
- 【All In One LED Controller】SP630E is compatible with various types of LED light strips.Such as PWM 3CH RGB 4 CH RGBW(Without IC), SPI RGB/RGBW (With Addressable IC Chip). SP630E max control: 600 ICs (SPI RGB LED Strip). 450ICs (SPI RGBW LED strip).
- 【2.4Ghz Wireless 30M(98FT) Remote Control Distance】One RF remote control can control up to 4 groups of lights.Each group can control an LED strip within 30m (98ft).The remote control allows for free control of a distance of 30 meters (98ft) within an open space.
- 【4 Zones Control Separately】The RB3 RF remote can control up to 4 zones, supports one-to-many control, and one RF remote control can control multiple controllers. It also supports multi-to-one control, with each controller able to bind up to 5 RF remote controls.
- 【Special Functions】3 kinds of collection methods:mobile phone Mic, player streaming, Built-in high-sensitivity Mic.BanlanX app supports to set kinds of on/off animations and the power-on state.Four APP operating interfaces: static effect, dynamic effect, music effect and DIY. Timing function.You can set up to 5 timers.
- 【DIY】Through the Banlanx app, you can customize your favorite lighting effects to meet your various needs.(Note:BanlanX APP does not support the group function.)Great for DIYers, home renovators, low-voltage lighting pros, and smart home beginners tackling kitchen cabinets, bookshelves, TV backlights, Office lighting, RVs, or PC builds.
5 V ── LDR ── A0 ── 10 kΩ resistor ── GND
In brighter conditions, the LDR resistance falls and the A0 voltage rises. In darkness, its resistance rises and the A0 reading falls. On a classic 5 V Arduino Uno, analogRead() normally returns a 10-bit value from 0 to 1023. See the Uno Rev3 specifications and analogRead reference.
Reversing the LDR and fixed resistor reverses this behavior. If your readings are high in darkness, reverse the comparison operators in the code or swap the two divider components.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Parts for a single-color 12 V strip
Required
- Arduino Uno, Nano, or compatible 5 V Arduino
- LDR/photoresistor
- 10 kΩ resistor
- Single-color analog LED strip
- Logic-level N-channel MOSFET rated for the strip voltage and current
- 100–220 Ω resistor for the MOSFET gate
- 10 kΩ gate-to-ground pulldown resistor
- 12 V power supply matched to the strip
- Breadboard for testing, or terminal blocks for a permanent installation
- Wire and a reliable common-ground connection
Useful additions
- 100–470 µF electrolytic capacitor across the strip supply rails
- 0.1 µF ceramic bypass capacitor near the controller
- Fuse for higher-current strip wiring
- Manual override switch
- Enclosure suitable for the installation
A classic Uno has six analog inputs and PWM output on pins 3, 5, 6, 9, 10, and 11. Pin 9 is used here. PWM details are available in Arduino’s analogWrite reference.
Wire the LDR sensor
Arduino 5V ───── LDR ───── A0
│
10 kΩ
│
Arduino GND ────────────┘
Keep the sensor away from the LED strip’s direct light. Otherwise, the strip can illuminate the LDR, causing the controller to switch itself off and potentially oscillate.
Wire the MOSFET switch
12 V supply + ───────────── LED strip +
LED strip − ────────────── MOSFET Drain
MOSFET Source ──────────── supply GND
Arduino GND ────────────── supply GND
Arduino D9 ── 100–220 Ω ── MOSFET Gate
MOSFET Gate ── 10 kΩ ───── GND
This is a low-side switch. The MOSFET’s source, the external supply negative, and Arduino ground must be connected together so the gate signal has the correct reference.
Use a genuine logic-level power MOSFET whose performance is specified at the Arduino’s gate voltage. “Logic-level” alone is not enough: check voltage rating, continuous current, on-resistance at the actual gate voltage, package limits, and heat dissipation. Adafruit’s LED-strip guide recommends a power N-channel MOSFET and warns that strip channels can require amp-level current.
Check the datasheet for the device’s pin order before connecting it. MOSFET packages do not all use the same drain-gate-source arrangement.
Why use a MOSFET instead of a relay?
| Criterion | MOSFET | Relay |
|---|---|---|
| Noise | Silent | Clicks when switching |
| PWM dimming | Suitable | Not suitable |
| Wear | No mechanical contacts | Contacts wear and bounce |
| Isolation | Usually none | May provide contact isolation |
| Best use | Frequent low-voltage DC switching | Simple on/off switching within contact ratings |
A relay can work for basic on/off control, but it should not be rapidly switched as the sensor value fluctuates. Relay modules also vary: some are active-low, meaning LOW turns the relay on. Verify the module’s active state and DC contact rating.
Also popular on Amazon
- This is a new Multi-color RGB LED controller with powerful functions and small size, which can present many special dynamic modes and bring new applications for multi-color LED decoration.
- This Mini RGB dimmer is used to control a variety of single-color fixtures with LEDs as the light source, and can realize 19 dynamic effects and 20 static effects; adjustable dynamic speed and brightness and other features.
- This Led strip light switch can easily change the dynamic mode, speed and brightness by pressing three keys on its slim body. It also has an automatic memory function. It is the perfect companion for your LED lights.
- This 3 Keys RGB Led brightness controller cable has 3 buttons. MODE key: dynamic mode key, press the mode key to cycle through 19 dynamic effects; COLOR key: static color key, press the COLOR key to switch among 20 static colors; SPEED/BRIGHT key: adjust the speed in MODE mode, adjust the brightness in COLOR mode, and the long button will shut down the power for 1 second, stable performance, good operation, simple wiring Convenient.
- Widely used in halls, buildings, indoor, outdoor and other places.
Arduino code with averaging and hysteresis
This sketch assumes the divider and MOSFET wiring shown above.
const byte LDR_PIN = A0;
const byte STRIP_PIN = 9; // PWM pin on a classic Arduino Uno
// Lower reading means darker with the divider shown above.
const int DARK_THRESHOLD = 420; // turn on below this value
const int LIGHT_THRESHOLD = 520; // turn off above this value
const byte NIGHT_BRIGHTNESS = 255;
const unsigned long SAMPLE_INTERVAL_MS = 250;
bool stripOn = false;
unsigned long lastSampleTime = 0;
int readLdrAverage(byte samples = 8) {
long total = 0;
for (byte i = 0; i < samples; i++) {
total += analogRead(LDR_PIN);
delay(2);
}
return total / samples;
}
void setup() {
pinMode(STRIP_PIN, OUTPUT);
analogWrite(STRIP_PIN, 0);
Serial.begin(9600);
Serial.println("Automatic day-night LED controller");
}
void loop() {
unsigned long now = millis();
if (now - lastSampleTime < SAMPLE_INTERVAL_MS) {
return;
}
lastSampleTime = now;
int lightLevel = readLdrAverage();
// Hysteresis prevents flicker between the two thresholds.
if (!stripOn && lightLevel < DARK_THRESHOLD) {
stripOn = true;
analogWrite(STRIP_PIN, NIGHT_BRIGHTNESS);
}
if (stripOn && lightLevel > LIGHT_THRESHOLD) {
stripOn = false;
analogWrite(STRIP_PIN, 0);
}
Serial.print("LDR: ");
Serial.print(lightLevel);
Serial.print(" | Strip: ");
Serial.println(stripOn ? "ON" : "OFF");
}
The strip turns on below DARK_THRESHOLD, turns off above LIGHT_THRESHOLD, and keeps its previous state between them. The 100-point gap is only an example; every installation needs calibration.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteBuild and calibrate it safely
- Test the divider alone. Upload the sensor-reading sketch below and open Serial Monitor at 9600 baud.
- Record real readings. Measure full daylight, normal room lighting, intended dusk, and intended nighttime conditions.
- Connect a short strip section. Verify polarity, MOSFET pinout, common ground, and gate wiring before installing the full length.
- Upload the controller sketch. In the Arduino IDE, select the correct board and port before uploading.
- Set the thresholds. Choose a dark threshold below the intended dusk reading and a light threshold comfortably above it.
- Test transitions. Cover and uncover the sensor slowly. The strip should switch once and remain stable while the reading lies between the thresholds.
const byte LDR_PIN = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(LDR_PIN));
delay(250);
}
For example, if the measured values are 830 in a bright room, 470 at dusk, and 220 at night, thresholds around 420 and 520 may be a reasonable starting point. The LDR, resistor value, sensor position, window direction, enclosure, temperature, and nearby lighting all affect the result.
Size the power supply from the strip rating
Do not choose a “12 V adapter” without checking current. Use:
Required current = current per metre × strip length
Supply rating ≥ required current × 1.25
If the strip is rated in watts:
Current = total watts ÷ supply voltage
Example: a 12 W/m, 12 V strip measuring 3 m requires 36 W. That is:
36 W ÷ 12 V = 3 A
A practical initial target is therefore about 3.75 A or more, subject to the strip manufacturer’s specifications, operating temperature, supply quality, and duty cycle.
For longer strips, run the high-current supply wiring directly to the strip rather than through the Arduino, breadboard, or thin jumper wires. Adafruit’s wiring guidance also recommends direct strip power and a shared ground. As a reference point, one listed Adafruit 12 V RGBW strip is rated up to 1.6 A/m; a 2 m section could therefore require approximately 3.2 A with all channels fully driven. Check the specific product rather than applying that figure universally.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.RGB, RGBW, and addressable upgrades
Analog RGB or RGBW
Use one appropriately sized MOSFET per channel. Connect the strip’s common positive terminal to the supply positive and switch each color or white channel on its own low side. Each MOSFET gate needs its own Arduino output, gate resistor, and pulldown. The listed Adafruit RGBW strip, for example, uses four controllable channels and requires 9–12 V.
Also popular on Amazon
- 15A Continuous/30A Peak High-Current Output – Drive heavy-duty motors, LED strips (up to 400W), and pumps effortlessly with dual parallel MOSFETs for minimal heat and maximum reliability.
- Wide 5V-36V PWM Compatibility – Works with Arduino, Raspberry Pi, PLCs, and 3.3V-20V signals (0-20KHz) for precise speed control, dimming, or automation – no extra circuits needed!
- Industrial-Grade Durability – Operates in extreme temps (-40°C to 85°C) perfect for drones, CNC machines, and smart homes.
- Multi-Application Versatility – Ideal for DIY robotics, LED lighting, 3D printers, solar projects, or replacing bulky relays – unleash your creativity safely!
Addressable pixels
An addressable strip needs a data connection and pixel-control code. Use an appropriate library such as FastLED, provide adequate strip power, and consider power injection on longer runs. A MOSFET can disconnect the entire strip for an emergency or master power switch, but it cannot replace the data signal.
Troubleshooting
The strip never turns on
- Confirm that the external supply voltage matches the strip.
- Check strip polarity and the MOSFET drain/source wiring.
- Confirm that Arduino ground and supply ground are connected.
- Verify that D9 is connected through the gate resistor.
- Check whether the LDR reading crosses the dark threshold.
- Confirm that the MOSFET is suitable at the Arduino’s gate voltage.
To test the output independently, temporarily replace the sensor decision with analogWrite(STRIP_PIN, 255);.
The strip is always on
Look for a missing gate pulldown, an incorrect MOSFET pinout, reversed divider behavior, or an inverted relay module. Print the sensor value in bright and dark conditions before changing the code.
The strip flickers at dusk
Keep the two thresholds separated, retain averaging, and increase the sample interval if necessary. For difficult locations, require several consecutive samples beyond a threshold before changing state. Shield the LDR from direct strip light and passing shadows.
The Arduino resets when the strip starts
The strip may be drawing current through the Arduino, the supply may be undersized, or the high-current wiring may have excessive voltage drop. Use separate strip power wiring, a correctly rated supply, a solid common ground, and local bulk capacitance. Arduino I/O pins and the 5 V rail are not LED-strip power sources; the Uno specification lists 20 mA as the recommended current per I/O pin.
The MOSFET gets hot
Check the strip current, the MOSFET’s on-resistance at the actual gate voltage, its package limits, wiring resistance, and whether it is being driven continuously at full power. A large current number printed on a MOSFET does not guarantee cool operation in your circuit.
Installation and safety
- Keep this project on the low-voltage DC side.
- Do not connect mains voltage to the Arduino circuit.
- Use an enclosed, appropriately rated AC adapter.
- Do not leave a permanent installation on an exposed breadboard.
- Fuse higher-current strip circuits where practical.
- Protect exposed conductors from metal mounting surfaces.
- Match the enclosure and connectors to the environment.
“Weatherproof” is product-specific; it does not automatically mean submersible, UV-proof, or suitable for prolonged outdoor exposure. Follow the strip manufacturer’s installation limits.
When an LDR is not the best choice
An LDR is inexpensive and ideal for approximate day-night switching, but it does not measure lux precisely. Its readings vary with the resistor, temperature, aging, sensor placement, and enclosure. Choose a digital ambient-light sensor when repeatable or lux-based measurement matters; it will generally require I²C wiring and additional software.
Also consider time-based control if the light must follow a schedule rather than actual conditions. A real-time clock or network time can avoid false triggers from shadows, but it will not respond to an unusually dark room or weather. A combined schedule-and-light rule can provide both predictable operating hours and ambient-light response.
Quick Recap
Final checklist
- Strip voltage and current rating recorded
- External supply sized from watts or amps per metre
- Arduino is not powering the strip
- LDR divider orientation verified
- Logic-level MOSFET checked at the board’s gate voltage
- Gate resistor and 10 kΩ pulldown installed
- Arduino and strip supply grounds connected
- Thresholds measured and calibrated at the installation site
- Hysteresis enabled
- Permanent wiring enclosed and protected
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.

