Hello,
I am fairly new to programming and I would love some help troubleshooting/fixing the errors that are appearing on my code. I am programming a controller for a DIY greenhouse. This includes 2 sets of lights, a diffuser (for humidity), and a fan (for circulation).
Note - I am using an 8 channel relay to control the four items listed above. I am also using a DHT11 sensor to measure the humidity and turn on/off the diffuser to maintain humidity between 90% and 93%.
Code:
const unsigned long eventTime_humDelay = 5000; //5 sec delay
const unsigned long eventTime_lightOn = 16*60*60*1000UL; //16 hrs
const unsigned long eventTime_lightOff = 8*60*60*1000UL; //8 hrs
const unsigned long eventTime_fanOn = 15*60*1000UL; //15 mins
const unsigned long eventTime_fanOff = 30*60*1000UL; //30 mins
unsigned long previousTime_humDelay = 0;
unsigned long previousTime_lightOn = 0;
unsigned long previousTime_lightOff = 0;
unsigned long previousTime_fanOn = 0;
unsigned long previousTime_fanOff = 0;
#include <DHT.h>
int relayPosition = 0;
#define dht_apin A0
#define relay1 2 //light
#define relay2 3 //humidifier
#define relay3 4 //top light
#define relay4 5 //fan
void setup() {
digitalWrite(relay3,LOW);
digitalWrite(relay1,LOW);
}
void loop() {
unsigned long currentTime = millis();
/*Humidifier Program*/
if ((relayPosition = 0) && (DHT.humidity < 90) && (currentTime - previousTime_humDelay>= previousTime_humDelay)) {
digitalWrite(relay2,HIGH); //high means on. if the humidity is below 60, the relay will turn on.
delay(250);
digitalWrite(relay2,LOW);
int relayPosition = 1
previousTime_humDelay = currentTime;
}
else if ((relayPosition = 1) && (DHT.humidity > 93) && (currentTime - previousTime_humDelay>= previousTime_humDelay)){
digitalWrite(relay2,HIGH);//low means off. if the humidity is above 70, the relay will turn off.
delay(250);
digitalWrite(relay2,LOW);
delay(250);
digitalWrite(relay2,HIGH);
delay(250);
digitalWrite(relay2,LOW);
delay(250);
digitalWrite(relay2,HIGH);
delay(250);
digitalWrite(relay2,LOW);
int relayPosition = 0
previousTime_humDelay = currentTime;
}
/*Lights Program*/
if ((relay3 = HIGH) && (currentTime - previousTime_lightOn>= previousTime_lightOn )) {
digitalWrite(relay3,LOW);
digitalWrite(relay1,LOW);
previousTime_lightOn = currentTime;
}
else if ((relay3=LOW) && (currentTime - previousTime_lightOff>= previousTime_lightOff )) {
digitalWrite(relay3,HIGH;
digitalWrite(relay1,HIGH);
previousTime_lightOff = currentTime;
}
/*Fan Program*/
if ((relay4 = LOW) && (currentTime - previousTime_fanOn>= previousTime_fanOn )) {
digitalWrite(relay4,HIGH);
previousTime_fanOn = currentTime;
}
else if ((relay4=HIGH) && (currentTime - previousTime_fanOff>= previousTime_fanOff)) {
digitalWrite(relay4,LOW);
}
}
error messages:
Arduino: 1.8.7 (Windows 10), Board: "Arduino Uno"
C:\Users\Eli\Documents\Arduino\Relay_Project\Relay_Project.ino:2:46: warning: integer overflow in expression [-Woverflow]
const unsigned long eventTime_lightOn = 16*60*60*1000UL; //16 hrs
~~~~~^~~
C:\Users\Eli\Documents\Arduino\Relay_Project\Relay_Project.ino: In function 'void loop()':
Relay_Project:32:34: error: expected primary-expression before '.' token
if ((relayPosition = 0) && (DHT.humidity < 90) && (currentTime - previousTime_humDelay>= previousTime_humDelay)) {
^
Relay_Project:37:5: error: expected ',' or ';' before 'previousTime_humDelay'
previousTime_humDelay = currentTime;
^~~~~~~~~~~~~~~~~~~~~
Relay_Project:39:39: error: expected primary-expression before '.' token
else if ((relayPosition = 1) && (DHT.humidity > 93) && (currentTime - previousTime_humDelay>= previousTime_humDelay)){
^
Relay_Project:52:5: error: expected ',' or ';' before 'previousTime_humDelay'
previousTime_humDelay = currentTime;
^~~~~~~~~~~~~~~~~~~~~
In file included from sketch\Relay_Project.ino.cpp:1:0:
C:\Users\Eli\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\cores\arduino/Arduino.h:40:14: error: lvalue required as left operand of assignment
#define HIGH 0x1
^
C:\Users\Eli\Documents\Arduino\Relay_Project\Relay_Project.ino:55:16: note: in expansion of macro 'HIGH'
if ((relay3 = HIGH) && (currentTime - previousTime_lightOn>= previousTime_lightOn )) {
^~~~
C:\Users\Eli\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\cores\arduino/Arduino.h:41:14: error: lvalue required as left operand of assignment
#define LOW 0x0
^
C:\Users\Eli\Documents\Arduino\Relay_Project\Relay_Project.ino:60:20: note: in expansion of macro 'LOW'
else if ((relay3=LOW) && (currentTime - previousTime_lightOff>= previousTime_lightOff )) {
^~~
Relay_Project:61:27: error: expected ')' before ';' token
digitalWrite(relay3,HIGH;
^
In file included from sketch\Relay_Project.ino.cpp:1:0:
C:\Users\Eli\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\cores\arduino/Arduino.h:41:14: error: lvalue required as left operand of assignment
#define LOW 0x0
^
C:\Users\Eli\Documents\Arduino\Relay_Project\Relay_Project.ino:66:16: note: in expansion of macro 'LOW'
if ((relay4 = LOW) && (currentTime - previousTime_fanOn>= previousTime_fanOn )) {
^~~
C:\Users\Eli\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\cores\arduino/Arduino.h:40:14: error: lvalue required as left operand of assignment
#define HIGH 0x1
^
C:\Users\Eli\Documents\Arduino\Relay_Project\Relay_Project.ino:70:19: note: in expansion of macro 'HIGH'
else if ((relay4=HIGH) && (currentTime - previousTime_fanOff>= previousTime_fanOff)) {
^~~~
exit status 1
expected primary-expression before '.' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.