
Arduino can easily be turned into an adjustable on/off timer that powers any electrical device for a set duration and then switches it off automatically — a practical foundation for timed lighting projects or scheduled heating and cooling systems.
Components needed
An Arduino Uno board, a solid-state relay (or a regular relay module), a potentiometer to set the timing duration, and two push buttons (one to start the cycle, the other to reset).
Wiring it up
The potentiometer connects to analog pin A0, and each push button connects to its own digital pin with a pull-down resistor, while the relay's control pin connects to another digital pin that in turn connects to the electrical load being controlled.
How it works
The code reads the potentiometer's value via analogRead() and converts it using the map() function into a duration ranging, say, from 3 to 30 seconds, letting the user set the on-time by turning the knob before pressing the start button. When the start button is pressed, the relay activates and the Arduino begins tracking elapsed time using millis() instead of delay(), which would have blocked the rest of the code from running; once the elapsed time matches the set duration, the relay switches off automatically, ending the cycle, and everything resets to its initial state when the reset button is pressed.
You can find relay modules and potentiometers at Juthour Tech.
اترك تعليقا