
This project uses an LDR to switch a DC motor fully on or off based on ambient light — a different kind of light-triggered control than the LDR ambient lamp we've covered before, which dims an LED gradually rather than flipping a relay.
How it works
The LDR's resistance changes with ambient light level, and Arduino reads that as an analog voltage. Once the reading crosses a set threshold — 400 in the base example — the sketch switches a relay on, which in turn powers the DC motor; below that threshold, the relay stays off and the motor stays off. This is deliberately a binary on/off response rather than a variable-speed one.
Components needed
An Arduino Uno, an LDR with a 4.7kΩ pull-up resistor, a 1-channel relay module, a 3–6V DC motor, an LED with a 220Ω resistor for status indication, and a breadboard.
Wiring it up
The LDR and pull-up resistor form a voltage divider read on analog pin A0. The relay's control input connects to digital pin 8, with the motor wired through the relay's normally-open contacts so the relay physically switches its power circuit rather than driving it directly from an Arduino pin. The status LED connects to pin 9.
Why a relay instead of driving the motor directly
A relay is used here specifically because it isolates the motor's power circuit from Arduino's low-current output pins — acting purely as an electronic on/off switch rather than a way to vary speed, which is why this project reads as simpler wiring than a PWM-based speed-control setup but only offers on/off control rather than adjustable speed.
Where this is used
Light-triggered motor switching like this fits simple solar-tracking mechanisms, automatic blinds or shade motors that respond to daylight, and any project where a motor should simply turn on once it gets bright enough (or dark enough, by inverting the logic) rather than needing fine speed control.
You can find LDR modules and relay modules at Juthour Tech.
Leave your comment