Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsButton 1 toggles the light, button 2 the fan; hold either for a second to toggle relays 3 and 4 (a night lamp and a socket). Button 3 switches everything off at once. It is the building block for the Bluetooth and Wi-Fi switch boards.
Keep to low-voltage loads unless a qualified electrician wires the mains side in an earthed, closed enclosure.
Tick anything you already have and the total updates.
Connects the Uno to your computer to upload code and power it
Three momentary buttons, one leg each to a pin and the other legs joined to GND; the internal pull-ups do the rest.
Four isolated relays on one board for four separate low-voltage loads.
Follow the colours: red is power, dark grey is ground, blue is a signal.
Test with 12 V loads. Connecting mains loads needs an electrician and a closed, earthed enclosure.
room_switch_panel_4ch.inoVerify & upload in Electrolark// Room switch panel with an all-off button
// Geekobot project library · board: Arduino Uno
// Wiring diagram, parts list and build steps: Geekobot project page "room-switch-panel-4ch"
// ---- pins ----
const uint8_t BTN_1 = 2;
const uint8_t BTN_2 = 3;
const uint8_t BTN_3 = 4;
const uint8_t RELAY_1 = 5;
const uint8_t RELAY_2 = 6;
const uint8_t RELAY_3 = 7;
const uint8_t RELAY_4 = 8;
// Button 1 toggles relay 1 (light), button 2 toggles relay 2 (fan), button 3 switches everything off.
// Relays 3 and 4 are left for a night lamp and a socket: hold button 1 or 2 for a second to toggle them.
bool on[4] = {false, false, false, false};
const uint8_t RELAYS[4] = {RELAY_1, RELAY_2, RELAY_3, RELAY_4};
const uint8_t BTNS[3] = {BTN_1, BTN_2, BTN_3};
bool wasDown[3];
unsigned long downAt[3];
// returns 0 when nothing is pressed, else 1-3
int pressedButton() {
if (digitalRead(BTN_1) == LOW) return 1;
if (digitalRead(BTN_2) == LOW) return 2;
if (digitalRead(BTN_3) == LOW) return 3;
return 0;
}
void apply() {
for (int i = 0; i < 4; i++) digitalWrite(RELAYS[i], on[i] ? LOW : HIGH); // active-low relay board
Serial.print(F("Relays: ")); for (int i = 0; i < 4; i++) Serial.print(on[i] ? F("ON ") : F("off ")); Serial.println();
}
void setup() {
Serial.begin(115200);
pinMode(BTN_1, INPUT_PULLUP); pinMode(BTN_2, INPUT_PULLUP); pinMode(BTN_3, INPUT_PULLUP);
for (int i = 0; i < 4; i++) pinMode(RELAYS[i], OUTPUT);
for (int i = 0; i < 3; i++) pinMode(BTNS[i], INPUT_PULLUP);
apply();
}
void loop() {
for (int i = 0; i < 3; i++) {
bool down = digitalRead(BTNS[i]) == LOW;
if (down && !wasDown[i]) downAt[i] = millis();
if (!down && wasDown[i]) {
bool held = millis() - downAt[i] > 1000;
if (i == 2) for (int r = 0; r < 4; r++) on[r] = false; // leaving the room: all off
else on[held ? i + 2 : i] = !on[held ? i + 2 : i];
apply();
}
wasDown[i] = down;
}
delay(15);
}
The sketch above runs here on a simulated Arduino Uno. Move the sliders for the sensors and buttons it reads, and watch the Serial monitor, display and outputs change.
It is rotated 90°; turn it so the legs span the gap.
Load must be on COM and NO, with its own supply in series.
Your module may be active-HIGH. Set RELAY_ACTIVE_LOW to false.
Some 5 V relay boards do not fully switch off with 3.3 V logic. Remove the JD-VCC jumper, feed JD-VCC from 5 V and VCC from 3.3 V, or use a relay board made for 3.3 V input.
Open the Serial Monitor at 115200 baud and check for messages. Make sure you chose the right board and port in the Arduino IDE.
Close other programs using the serial port, try another USB cable (some are charge-only) and press reset just before uploading.
Yes. Most of the code works unchanged on an ESP32 with the ESP32 board package. Watch for 5 V modules: ESP32 pins are 3.3 V, so 5 V output signals need a resistor divider.
The relay is rated for mains, but mains wiring is dangerous. Keep this build on low-voltage loads (12 V pumps, fans, LED strips), or have a qualified electrician fit the relay inside an earthed, closed enclosure.
Use a 5 V USB phone charger or a power bank into the board's USB port. Loads such as pumps, fans and solenoids need their own supply.
8 parts: Uno R3 CH340G ATmega328p Compatible Development Board, Arduino USB-A to USB-B Data Cable for UNO/MEGA, 3 × Tactile Push Button Switch, 5V Relay Module with Optocoupler (4 channel), 12V DC Brushless Fan 80mm (cooling fan), DC Power Adapter 12V 2A (5.5x2.1mm), Solderless Breadboard (830 points) and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 2 hours. The build on this page has 7 steps.
No. This page has the complete, tested code (room_switch_panel_4ch.ino).
Yes. The Run it panel under the code runs this exact sketch on a simulated board. Move the sliders or press the buttons for the sensors it reads, and the Serial monitor, display and outputs react as they will on the real build. It is a simulation, so real readings depend on your parts and wiring.
About ₹805 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Isolation, relays and switching higher-power loads; Pull-ups and debouncing.
Ideas that reuse this build: Bluetooth 4-relay switch and IR remote relay switch. They are listed under Take it further on this page.
Lights switch on by themselves at dusk and off again in the morning.
A precise thermostat that keeps tropical fish at a steady 25–26 °C.
Starts the pump when the tank runs low and stops it when it is full.
Tap a hidden pad to switch a lamp on or off, even through a wooden desk.
Learning project. Check every circuit and the datasheet of each part before you power it up.
Relays: off off off off
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.