Using RTC to trigger relays at certain times of day


hi,

i'm trying build automated greenhouse of rtc trigger actions @ times. i'm using ds3231 ds1307 library , relays thats why highs , lows inverted.

what want program :

1 . make lightpin low if time between interval, regardless if unit should reset or lose power. happens lightpin turns on @ right time, if unit loses power pin not go low until rtc @ starting time again.

2. make airpin low 15 minutes every other hour , humpin low 15 minutes every hour.


for goal 1 i've tried using while instead of if, no success.  

and goal 2 realise done lot of "if" statements specific times there has got better way this. i've thought using integer value of current hour/2 see if value in order trigger every other hour, , if digitalwrite low.


using while goal 1

code: [select]
  while (now.hour() >= 8 & now.hour() <= 18 & now.minute() == 00 & now.second() == 00)
    {
      digitalwrite(lightpin, low);
    }
  





complete sketch



code: [select]
#include <wire.h>
#include "rtclib.h"
#include <dht.h>;
#include <liquidcrystal_i2c.h>

liquidcrystal_i2c lcd(0x27, 16, 2);

rtc_ds1307 rtc;

int lightpin = 5;
int airpin = 6;
int humpin = 7;

#define dhtpin 2    
#define dhttype dht22  
dht dht(dhtpin, dhttype);


float hum;  
float temp;


void setup() {

  serial.begin(9600);
  
  lcd.begin();
  wire.begin();
  dht.begin();
  rtc.begin();
  lcd.backlight();

  if (! rtc.isrunning())
  {
    lcd.println("rtc not running!");
  }
  
   pinmode (airpin, output);
    pinmode (lightpin, output);
    pinmode (humpin, output);
}

void loop() {

  hum = dht.readhumidity();
    temp = dht.readtemperature();

    
  datetime = rtc.now();

 lcd.setcursor(0, 0);
    lcd.print("humi: ");
    lcd.print(hum);
    lcd.print(" %");
    lcd.setcursor(0,1);
    lcd.print("temp: ");
    lcd.print(temp);
    lcd.print(" c ");


    if (now.hour() == 8 & now.minute() == 00 & now.second() == 00)
    {
      digitalwrite(lightpin, low);
    }

    else if (now.hour() == 20 & now.minute() == 00 & now.second() == 00)
    {
      digitalwrite(lightpin, high);
    }    

       if (now.minute() == 15 & now.second() == 0)
    {
      digitalwrite(humpin, low);
    }

     else if (now.minute() == 30 & now.second() == 0)
    {
      digitalwrite(humpin, high);
    }
       if (now.minute() == 45 & now.second() == 0)
    {
      digitalwrite(airpin, low);
    }

     else if (now.minute() == 00 & now.second() == 0)
    {
      digitalwrite(airpin, high);
    }    }




is there here point me in right direction?


i'm still arduino beginner, , criticism welcome.


thanks in advance




if understand correctly logic inverted want pin stay high if loose power? when have no power can't maintain 5v...


btw should use && instead of & in

code: [select]
while (now.hour() == 8 & now.minute() == 00 & now.second() == 00)
    {


what have works in case  not practice confuse 2


Arduino Forum > Using Arduino > Programming Questions > Using RTC to trigger relays at certain times of day


arduino

Comments

Popular posts from this blog

Valutazione Template - Joomla! Forum - community, help and support

SD Datastring Convention

First use of Arduino Uno : avrdude error on Blink uploading