Adding a action between two times, but relying on other variables.

kenwood120s:
I'm not sure what you mean by "between two times": do you mean times of day, like only operate between 0800 and 1700 or what?

Yes correct i feel this would be easier to adjust then millisec

wvmarle:
If you want time of day, you'll have to add a real time clock (or if you're connected to the Internet, use NTP).

Indeed rest of sketch, at the bottom is my attempted fail. Regards

#include "DHT.h"                                        // Libary for the DHT22
#include "Relay.h"                                      // Libary for the Relay
#define DHTPIN 2                                        // what digital pin DHT22 is connected to
#define DHTTYPE DHT22                                   // DHT type = 22
DHT dht(DHTPIN, DHTTYPE);                               // Init DHT sensor.
#define Relay1 7                                        // Define relay 1 to pin#

#include <Wire.h>                                       //DS3231
#include "RTClib.h"                                     //DS3231
RTC_DS3231 rtc;                                         //DS3231
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; //DS3231


void setup()
{
  Serial.begin(9600);                                   // Setup Serial connection speed (was 115200)
  dht.begin();                                          // Init DHT22
  digitalWrite(Relay1, HIGH);                           // set the pin HIGH first, stops on/off at boot
  pinMode(Relay1, OUTPUT);                              // then make it an output

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");// following line sets the RTC to the date & time this sketch was compiled
  }

}

void loop()
{
  DateTime now = rtc.now();

  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(" (");
  Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
  Serial.print(") ");
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();

  float h = dht.readHumidity();                         // DHT22 deciaml point
  float t = dht.readTemperature();                      // DHT22 deciaml point
  Serial.print("Humidity: ");                           // DHT22
  Serial.print(h);                                      // DHT22
  Serial.print(" %\t");                                 // DHT22
  Serial.print("Temperature: ");                        // DHT22
  Serial.print(t);                                      // DHT22
  Serial.println(" *C ");                               // DHT22

  delay (1000);                                           // Wait one second before repeating

  
 if (t > 32 || h > 70 && now.hour 12:00:00-13:00:00 ) {
    digitalWrite(Relay1, LOW);
  }
  else if (t < 32 || h < 70 && now.hour 13:00:01-11:59:59) {
    digitalWrite(Relay1, HIGH);
  }
 

}