Jump to content


"Where The Stoners Grow"

Forums, Picture Gallery, How to Tutorials, Articles, Blogs, Product Reviews, Recipes, Strain Guides and much more
Join Today

Seed To Weed

We Cover It All-

Tutorials, Forums, And Articles Devoted To Marijuana

Learn to Grow

Grow To Learn

Learn and Share Advanced Marijuana Growing, Harvesting and Extraction Techniques
Advanced GrowingHarvestingExtracts

Interactive Legalization Map

Find State Laws, Marijuana Business In Your Area And Much More

Cooking With Marijuana

Tutorials, Forums, Recipes And Articles All to Help You Become A Canna-Connoisseur

Arduino 2 lamp and fan controller

Recommended Posts

This one is sort of a PITA because I never did add in a switch to flip between photoperiods easily.  I have to edit the code and re-upload it.  however, since I use an arduino micro and plug it into a breadboard, it's pretty easy to remove and bring it over to the PC.


How it works:

You set what time you want your lights to turn on and off and when it's time to turn them on, it will start the first lamp, then the lamp cooling fan in 5 seconds, then 10 seconds after the first lamp fires, the 2nd lamp starts.  The exhaust fan/canopy fan starts after 30 seconds of lights on.  Everything is staggered so it doesn't slam your breaker and trip it.  When it's time to turn off, both lamps go off along with the room exhaust/canopy fans while the lamp cooling fan continues for another 10 mins to cool the bulbs.  If the controller is turned on during a time when your lamps would normally be on, it goes into a protection mode and turns the lamp cooling fan on for 10 mins before starting the lamps.  This is to avoid a hot bulb restart in the case of a brown-out that resets the controller.


The only soldering needed is for the AC adapter, so this one is a bit easier to put together than the humidifier controller.  I use breadboard wires to connect everything.



Arduino micro --  Like this: https://www.gearbest.com/sensors/pp_729019.html?wid=1433363  NOTE:  whichever arduino you use, make sure it has a 3.3v ouput pin for the RTC

RTC  -- arduino real time clock.

2 double relays  -- 4 relays in total

5v regulated AC adapter


3 single plug outlets, 1 double outlet, electrical boxes, some wiring for it all.  The double outlet is for your carbon filtered room exhaust and canopy fan (if you use one).


Build notes:  it all goes together quite easily.  I installed the AC adapter inside the electrical box behind the outlets.  I used 2 boxes and a second 5v adapter so I could have the lamps on a 220V line, but you could use just 1 box if you wanted.  Just be sure to label those 220V sockets if you don't change the plug type!!! The arduino and relays are attached to the outside of the box so everything stays together.  Power them directly with the AC adapter, not the arduino.  I think it might have just enough power to do it, but it would be right at the limits with 4 of them.  Wiring diagrams are all online for each component.  You'll also have to program the RTC with the correct time.  That code is quite common and will come with the library files you download.  I've used this code for several years now, so it's well tested and bulletproof.  Enjoy!




/* Beekers Lamp Controller v1.0.1 

 * 5 sec lamp fan delay
 * 10 sec lamp2 delay
 * 30 sec exhaust fan delay
 * 10 min lamp fan lights out cooldown
 * 10 min lamp fan reset cooldown

#include <MD_DS3231.h>
#include <Wire.h>

#define lightsOnTime 21 // 9pm
#define lightsOffTime 9 // 9am

#define LAMP1 9
#define LAMP2 10
#define LAMP_FAN 11
#define EXHAUST_FAN 12

byte lightsOnState = LOW;
byte lampFanState = LOW;
byte lamp1State = LOW;
byte lamp2State = LOW;
byte lampResetCoolState = LOW;

unsigned long previousMillisLampResetCool = 0;
unsigned long previousMillisLampCoolDown = 0;
unsigned long previousMillisLamp2OnDelay = 0;
unsigned long previousMillisExhaustOnDelay = 0;
unsigned long previousMillisLampFanOnDelay = 0;

void setup(){
  pinMode(LAMP1, OUTPUT);
  digitalWrite(LAMP1, HIGH);
  pinMode(LAMP2, OUTPUT);
  digitalWrite(LAMP2, HIGH);
  pinMode(LAMP_FAN, OUTPUT);
  digitalWrite(LAMP_FAN, HIGH);
  digitalWrite(EXHAUST_FAN, HIGH);
  if ((RTC.h) >= lightsOnTime || (RTC.h) < lightsOffTime){
    lampResetCoolState = HIGH;

void loop(){
  unsigned long currentMillis = millis();
// Lamp Control
  if ((RTC.h) >= lightsOnTime && lampResetCoolState == LOW || (RTC.h) < lightsOffTime && lampResetCoolState == LOW){
    lightsOnState = HIGH;
    lightsOnState = LOW;
  if (lightsOnState == HIGH && lamp1State == LOW){
    digitalWrite(LAMP1, LOW);
    lamp1State = HIGH;
    previousMillisLamp2OnDelay = currentMillis;
    previousMillisLampFanOnDelay = currentMillis;
    previousMillisExhaustOnDelay = currentMillis;
  if (lightsOnState == HIGH && lamp1State == HIGH && lamp2State == LOW && currentMillis - previousMillisLamp2OnDelay >= 10000){ // 10 sec
    digitalWrite(LAMP2, LOW);
    lamp2State = HIGH;
  if (lightsOnState == LOW && lamp1State == HIGH && lamp2State == HIGH){
    digitalWrite(LAMP1, HIGH);
    lamp1State = LOW;
    digitalWrite(LAMP2, HIGH);
    lamp2State = LOW;
    previousMillisLampCoolDown = currentMillis;

// Lamp Cooling Fan
  if (lamp1State == HIGH && lampFanState == LOW && (currentMillis - previousMillisLampFanOnDelay > 5000)){ // 5 sec
    digitalWrite(LAMP_FAN, LOW);
    lampFanState = HIGH;
  if (lamp1State == LOW && lampFanState == HIGH && (currentMillis - previousMillisLampCoolDown > 600000)){  // 10 mins
    digitalWrite(LAMP_FAN, HIGH);
    lampFanState = LOW;
  if (lampResetCoolState == HIGH){
    digitalWrite(LAMP_FAN, LOW);
    lampFanState = HIGH;
  if (lampResetCoolState == HIGH && lampFanState == HIGH && currentMillis - previousMillisLampResetCool > 600000){ // 10 mins
    lampResetCoolState = LOW;
// Exhaust Fan
  if (lamp1State == HIGH && (currentMillis - previousMillisExhaustOnDelay > 30000)){ // 30 sec delay
    digitalWrite(EXHAUST_FAN, LOW);
    digitalWrite(EXHAUST_FAN, HIGH);

Edited by Zombeek
  • Like 4

Share this post

Link to post
Share on other sites

Cool stuff, great post!

  • Like 2

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.


Important Information

By using this service you agree to our Terms of Use and use of cookies.