Okay,
I have written and rewritten, changed variables and values, researched and reviewed and I am now frustrated because I think that I have everything in the correct place, but I am not getting the functionality that I desire.
I am looking to have 2 relays (digital pins 8, 9) trigger to turn on exhaust fans in the greenhouse.
The triggers are (High temp or high humidity and/or high light) Light trigger is somewhat important as the power will be automotive batteries connected to a solar cell and I don't want the fans to be running when there is no charging going on. I have been able to get the baseline functional, so the relays turn on when the humidity passes threshold value, and when temperature does as well, but the light trigger is a no go. I have used the light as a trigger for relays or for backlight, but once added to the larger code it stops working as it should. The sensor is still reading data but I can't do anything with it.
I apologize for seeming needy, but this has now gone beyond my reasoning and I have been unable to decipher the correct arrangement by searching through other's projects.
So, this is where I am at:
#include <DHT.h>
#include <DHT_U.h>
#include <Adafruit_Sensor.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);
#define DHTPIN A1
#define DHTTYPE DHT12
DHT dht(DHTPIN, DHTTYPE);
int fan1 = 8;
int fan2 = 9;
int soil1 = A2;
int light = A0; // select the input pin for LDR
int LUX = 0; // variable to store the value coming from the sensor
int h = 0;
int t = 0;
int soil = 0;
char hTemp;
//char lTemp;
char hHumid;
//char lHumid;
char hLight;
//char lLight;
void setup() {
dht.begin();
lcd.begin(16, 2);
pinMode(light, INPUT);
pinMode(soil1, INPUT);
pinMode(fan1, OUTPUT);
pinMode(fan2, OUTPUT);
//pinMode(water1, OUTPUT);
}
void loop() {
sensorcheck();
humidcontrol();
tempcontrol();
soilcondition();
fanstate();
lcdprint();
}
void sensorcheck() {
h = dht.readHumidity();
t = dht.readTemperature();
soil1 = analogRead(A2);
LUX = analogRead(A0);
}
void humidcontrol() {
if (h >= 60) {
hHumid = true;
}
else if (h <= 55) {
hHumid = false;
}
}
void tempcontrol() {
if (t >= 35) {
hTemp = true;
}
else if (t <= 30) {
hTemp = false;
}
}
void lightcheck() {
if (LUX >= 105) {
hLight = true;
}
else if (LUX <= 100) {
hLight = false;
}
}
void soilcondition() {
soil = analogRead(A2);
soil = map(soil, 1020, 230 , 0, 100);
}
void fanstate() {
if ( hTemp || hHumid || hLight ) {
digitalWrite( fan1, LOW );
digitalWrite( fan2, LOW );
}
else {
digitalWrite( fan1, HIGH );
digitalWrite( fan2, HIGH );
}
}
void lcdprint() {
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.print(t);
lcd.print("C ");
lcd.print("Hum:");
lcd.print(h);
lcd.print ("%");
lcd.setCursor(0, 1);
lcd.print("Lux:");
lcd.print(analogRead(A0));
lcd.print(" ");
lcd.print("Soil:");
lcd.print(soil);
lcd.print("%");
lcd.print(" ");
}
Thank you in advance