Moving Steppers At Certain Time Of Day

Hi,

I've made a device that opens and closes my window blinds at certain times of the day using a RTC module and two 28byj-48 stepper motors. There is also a temperature sensor serving a similar function. Currently, the system only moves on temperature. For some reason, the time function is not working. The current time prints on the serial port so I know for certain the RTC is functioning, that said, what in my code is causing the motors not to run at the given times? Thanks.

#include <AFMotor.h>

#include "DHT.h"

#include <DS3231.h>

AF_Stepper motor1(48, 2);
AF_Stepper motor2(48, 1);

// Object for real time clock
DS3231 rtc(SDA, SCL);
Time t;

// Object for DHT11 temperature sensor
#define DHTTYPE DHT11

//Set the read off pin
#define DHTPIN A0
DHT dht(DHTPIN, DHTTYPE);

bool blinds_open;

void setup() {
  
  Serial.begin(9600);
  dht.begin();
  rtc.begin();
  motor1.setSpeed(500);
  motor2.setSpeed(500);   
  delay(1000); 
  blinds_open = true;
}

void loop() {
  //Allow start up and calibration period
  delay(2000);
  
  //Retrieve current time from RTC
  t = rtc.getTime();

  //Print Time in serial port
  Serial.print("Current Time : ");
  Serial.print(t.hour);
  Serial.print(":");
  Serial.print(t.min);
  delay(2000);
  
  //Read temperature off DHT11 sensor
  //Temp in Celcius
  float c = dht.readTemperature();
  //Temp in Fahrenheit
  float f = dht.readTemperature(true);
  //Serial.print("Temperature (C) : ");
  //Serial.print(c);
  Serial.print("      ");
  Serial.print(" Current temperature (F) : ");
  Serial.print(f);
  
  //If time or temperature matches, move stepper to open blinds
  if (t.hour == 7 && t.min == 00 && t.sec == 00 and (blinds_open == false) ) {
    Serial.print(" Good morning, opening blinds... ");
    motor1.step(8000, BACKWARD, SINGLE);
    motor2.step(8000, BACKWARD, SINGLE);
    motor1.release();
    motor2.release();
    Serial.print(" Blinds open, have a nice day. ");
    blinds_open = true;
    }
  else if (t.hour == 23 && t.min == 30 && t.sec == 00 and (blinds_open == true) ) {
    Serial.print(" Good evening, closing blinds... "); 
    motor1.step(8000, FORWARD, SINGLE);
    motor2.step(8000, FORWARD, SINGLE);
    motor1.release();
    motor2.release();
    Serial.print(" Blinds closed, goodnight. ");
    blinds_open = false; 
    }
  else if (f > 81 and (blinds_open == true) ) {
    Serial.print(" Ambient temperature limit exceeded, closing blinds... ");
    motor1.step(8000, FORWARD, SINGLE);
    motor2.step(8000, FORWARD, SINGLE);
    motor1.release();
    motor2.release();
    Serial.print(" Blinds closed." );
    blinds_open = false;
  }
  else if (f < 79 and (blinds_open == false) ) {
    Serial.print(" It's cooling off, opening blinds... ");
    motor1.step(8000, BACKWARD, SINGLE);
    motor2.step(8000, BACKWARD, SINGLE);
    motor1.release();
    motor2.release();
    Serial.print(" Blinds open. ");
    blinds_open = true;
  }
}

Loop has four seconds of delay in it. Your time based blind opening code relies on seconds being zero - it would be all too easy to miss it while you're delaying.

Since you check blinds_open, you could drop the check for seconds and catch the need to open anywhere in the period where minutes are zero.

wildbill:
Loop has four seconds of delay in it. Your time based blind opening code relies on seconds being zero - it would be all too easy to miss it while you're delaying.

Since you check blinds_open, you could drop the check for seconds and catch the need to open anywhere in the period where minutes are zero.

That's a good point. Never considered that. I added a delay at the beginning so it wouldn't constantly access the temperature sensor and make the system overly sensitive, but I could see how that would cause it to skip over the time. I'll take out the seconds and see if it works.