if (t < 25 || h < 70) {
digitalWrite(Relay1, HIGH);
}
else if (t > 25 || h > 70) {
digitalWrite(Relay1, LOW);
}
So when i do this it is only making Relay1 LOW if both values (t&h) are above > greater then, here is the rest of the code.
#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 < 25 || h < 70) {
digitalWrite(Relay1, HIGH);
}
else if (t > 25 || h > 70) {
digitalWrite(Relay1, LOW);
}
}
I also need a 'in between' time, as in a timer, would this be a && in the same if sentence?
Kind regards