Build it step by step
0 of 7 doneTest the RTC
Print the time and set it.
Test the relays
Click each channel from code.
Wire the 12 V side
Fit a fuse on the adapter lead.
Add the schedule
Lights on in the daytime hours.
Add the fan cycle
5 minutes each hour.
Add the override
Press to force the lights on.
Run for a week
Check the time drift and the plants.
How do you build a plant grow shelf timer?
A timer for a shelf of plants that runs lights 14 hours and a fan for 5 minutes each hour. You need Arduino Nano, DS3231 RTC module, Relay module 2-channel 5 V, 12 V DC fan 80 mm, 12 V LED strip warm white (5 m, 2835), 12 V 2 A DC adapter and Tactile push button 6 mm. It takes 7 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 7
Wiring
| From | To | Why |
|---|---|---|
| DS3231 VCC, GND | Nano 5V, GND | Power |
| DS3231 SDA, SCL | Nano A4, A5 | I2C |
| Relay module VCC, GND | Nano 5V, GND | Power |
| Relay IN1 | Nano D4 | Light channel |
| Relay IN2 | Nano D5 | Fan channel |
| 12 V adapter plus | Relay 1 COM and relay 2 COM | Common supply |
| Relay 1 NO | LED strip + (strip − to adapter −) | Lights |
| Relay 2 NO | Fan + (fan − to adapter −) | Fan |
| Button | Nano D2 and GND | Manual override |
| Nano | 5 V from a USB adapter | Power (separate from the 12 V loads) |
Code
The DS3231 keeps time through power cuts with its coin cell, so the schedule survives a blackout. Edit the hours at the top to suit your plants; seedlings often need 14 to 16 hours of light, but different plants differ, so check what yours need. The relay module switches only the 12 V side here: the 12 V adapter powers the strip and fan, and the Nano has its own 5 V supply. Never wire mains to the relay in this build; if you want to switch a mains grow light, a qualified electrician must wire the mains side with a suitably rated, enclosed relay unit. Use a fuse on the 12 V lead and keep the electronics away from water. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Plant shelf timer: lights 06:00 to 20:00, fan 5 minutes each hour. Libraries: RTClib. Board: Arduino Nano.
#include <Wire.h>
#include <RTClib.h>
RTC_DS3231 rtc;
const int LIGHT = 4, FAN = 5, BTN = 2;
const int LIGHT_ON_HOUR = 6, LIGHT_OFF_HOUR = 20; // 14 hours of light
const int FAN_MINUTES = 5;
bool override_on = false;
unsigned long lastBtn = 0;
void setup() {
pinMode(LIGHT, OUTPUT); pinMode(FAN, OUTPUT); pinMode(BTN, INPUT_PULLUP);
digitalWrite(LIGHT, HIGH); digitalWrite(FAN, HIGH); // most relay boards are active LOW, HIGH = off
Serial.begin(115200);
if (!rtc.begin()) { Serial.println("RTC not found"); while (1); }
if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // set once from the compile time
}
void loop() {
DateTime now = rtc.now();
if (!digitalRead(BTN) && millis() - lastBtn > 400) { override_on = !override_on; lastBtn = millis(); }
bool lightsOn = (now.hour() >= LIGHT_ON_HOUR && now.hour() < LIGHT_OFF_HOUR) || override_on;
bool fanOn = (now.minute() < FAN_MINUTES); // first 5 minutes of every hour
digitalWrite(LIGHT, lightsOn ? LOW : HIGH);
digitalWrite(FAN, fanOn ? LOW : HIGH);
Serial.print(now.hour()); Serial.print(":"); Serial.print(now.minute());
Serial.print(" lights "); Serial.print(lightsOn); Serial.print(" fan "); Serial.println(fanOn);
delay(1000);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
RTC not found
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| At 06:00 | Lights switch on |
| At 20:00 | Lights switch off |
| Each hour | Fan runs for 5 minutes |
| Unplug and replug | Schedule continues at the right time |
If it does not work
Relays reversed
Change active LOW to HIGH for your board.
Time resets to the compile time
Replace the RTC coin cell.
Fan never runs
Check the wiring to NO, not NC.
Nano resets when the lights switch
Use separate supplies and add a 100 µF capacitor.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the plant grow shelf timer?
Arduino Nano, DS3231 RTC module, Relay module 2-channel 5 V, 12 V DC fan 80 mm, 12 V LED strip warm white (5 m, 2835), 12 V 2 A DC adapter and Tactile push button 6 mm.
How long does the plant grow shelf timer take to build?
About 90 minutes for a beginner maker, in 7 steps.
How do I know the plant grow shelf timer works?
At 06:00: Lights switch on. At 20:00: Lights switch off. Each hour: Fan runs for 5 minutes.
Relays reversed: what should I check?
Change active LOW to HIGH for your board.
Time resets to the compile time: what should I check?
Replace the RTC coin cell.
Fan never runs: what should I check?
Check the wiring to NO, not NC.
Nano resets when the lights switch: what should I check?
Use separate supplies and add a 100 µF capacitor.
