Hey everyone,
I am having a little difficulty structuring the arguments in my if /else if statements. This is my first project trying to use multiple sensor values in one statement. Any help would great.
In the if statements I am trying to have it say
(sensor 1 OR sensor 2 OR sensor 3 are <300)
(sensor 1 OR sensor 2 OR sensor 3 are >300 and <700)
(sensor 1 OR sensor 2 OR sensor 3 are >700)
If there are "Best Practices" for when there are lots of sensors/ please let me know!
Thank you in advance.
sean
Errors:
Garden_Automation:80: error: expected initializer before numeric constant
Garden_Automation.ino: In function 'void loop()':
Garden_Automation:147: error: expected ')' before ';' token
Garden_Automation:149: error: too many arguments to function 'void on()'
Garden_Automation.ino:82:6: note: declared here
Garden_Automation:150: error: too many arguments to function 'void on()'
Garden_Automation.ino:82:6: note: declared here
Garden_Automation:154: error: 'else' without a previous 'if'
Garden_Automation:154: error: expected primary-expression before '<' token
Garden_Automation:156: error: too many arguments to function 'void off()'
Garden_Automation.ino:94:6: note: declared here
Garden_Automation:157: error: too many arguments to function 'void off()'
Garden_Automation.ino:94:6: note: declared here
Garden_Automation:162: error: too many arguments to function 'void off()'
Garden_Automation.ino:94:6: note: declared here
Garden_Automation:163: error: too many arguments to function 'void off()'
Garden_Automation.ino:94:6: note: declared here
expected initializer before numeric constant
Code:
#include <Wire.h>
/*
// desired eviromental settings
int TEMP1 = 70;
int TEMP2 = 70;
int TEMP3 = 70;
int HUMID1 = 50;
int HUMID2 = 50;
int HUMID3 = 50;
int MOISTURE1 = 20;
int MOISTURE2 = 20;
int MOISTURE3 = 20;
*/
//Relay board
int RP1 = 1;
int RP2 = 2;
int RP3 = 3;
int RP4 = 4;
int RP5 = 5;
int RP6 = 6;
int RP7 = 7;
int RP8 = 8;
// Checking status HIGH/LOW for the relay board
int check_RP1;
int check_RP2;
int check_RP3;
int check_RP4;
int check_RP5;
int check_RP6;
int check_RP7;
int check_RP8;
//Moisture sensors set up to anolog pin
int Moisture_Sensor1 = A1;
int Moisture_Sensor2 = A2;
int Moisture_Sensor3 = A3;
int Moisture_Sensor4 = A4;
int Moisture_Sensor5 = A5;
int Moisture_Sensor6 = A6;
int Moisture_Sensor7 = A7;
int Moisture_Sensor8 = A8;
int Moisture_Sensor9 = A9;
// Temp sensors to anolog pin
int HT_T_Sensor1 = A10;
int HT_T_Sensor2 = A11;
int HT_T_Sensor3 = A12;
int HT_T_Sensor4 = A13;
// Humidity sensors to anolog pin
/*int HT_H_Sensor1 = ;
int HT_H_Sensor2 = ;
int HT_H_Sensor3 = ;
int HT_H_Sensor4 = ;*/
//Float switch in main water container
int Float_Switch1 = 0;
int Float_Switch1val;
int Moisture_Sensor1val = 0;
int Moisture_Sensor2val = 0;
int Moisture_Sensor3val = 0;
int Moisture_Sensor4val = 0;
int Moisture_Sensor5val = 0;
int Moisture_Sensor6val = 0;
int Moisture_Sensor7val = 0;
int Moisture_Sensor8val = 0;
int Moisture_Sensor9val = 0;
// Temp sensors to anolog pin Val storage
int HT_T_Sensor1val = 0;
int HT_T_Sensor2val = 0;
int HT_T_Sensor3val = 0;
int HT_T_Sensor4val = 0;
// Humidity sensors to anolog pin Val storage
int HT_H_Sensor1val = 0;
int HT_H_Sensor2val = 0;
int HT_H_Sensor3val = 0;
int HT_H_Sensor4val = 0;
//Zones (or shelves) for action in Loop Statement
int zone1, zone2, zone3, zone 4;
void on() {
digitalWrite(RP1,HIGH);
digitalWrite(RP2,HIGH);
digitalWrite(RP3,HIGH);
digitalWrite(RP4,HIGH);
digitalWrite(RP5,HIGH);
digitalWrite(RP6,HIGH);
digitalWrite(RP7,HIGH);
digitalWrite(RP8,HIGH);
digitalWrite(Float_Switch1,HIGH);
}
void off(){
digitalWrite(RP1,LOW);
digitalWrite(RP2,LOW);
digitalWrite(RP3,LOW);
digitalWrite(RP4,LOW);
digitalWrite(RP5,LOW);
digitalWrite(RP6,LOW);
digitalWrite(RP7,LOW);
digitalWrite(RP8,LOW);
digitalWrite(Float_Switch1,LOW);
}
void setup() {
// put your setup code here, to run once:
pinMode(Float_Switch1,INPUT);
pinMode(RP1,OUTPUT);
pinMode(RP2,OUTPUT);
pinMode(RP3,OUTPUT);
pinMode(RP4,OUTPUT);
pinMode(RP5,OUTPUT);
pinMode(RP6,OUTPUT);
pinMode(RP7,OUTPUT);
pinMode(RP8,OUTPUT);
pinMode(Moisture_Sensor1, INPUT);
pinMode(Moisture_Sensor2, INPUT);
pinMode(Moisture_Sensor3, INPUT);
pinMode(Moisture_Sensor4, INPUT);
pinMode(Moisture_Sensor5, INPUT);
pinMode(Moisture_Sensor6, INPUT);
pinMode(Moisture_Sensor7, INPUT);
pinMode(Moisture_Sensor8, INPUT);
pinMode(Moisture_Sensor9, INPUT);
pinMode(HT_T_Sensor1,INPUT);
pinMode(HT_T_Sensor2,INPUT);
pinMode(HT_T_Sensor3,INPUT);
pinMode(HT_T_Sensor4,INPUT);
Serial.begin(9600);
Serial.println("Start Automation");
Serial.println("Calabration Startup");
}
void loop() {
// put your main code here, to run repeatedly:
//Moisture sensors to analog Val read
Moisture_Sensor1val = analogRead(Moisture_Sensor1);
Moisture_Sensor2val = analogRead(Moisture_Sensor2);
Moisture_Sensor3val = analogRead(Moisture_Sensor3);
if (Moisture_Sensor1val< 300 | (Moisture_Sensor2val< 300 | Moisture_Sensor3val< 300);
{
on(RP1);//valve 1
on(RP5);// Main Water Pump
Serial.println("Zone 1 being watered");
}
else if(Moisture_Sensor1val || Moisture_Sensor2val || Moisture_Sensor3val > 300 && < 700)
{
off(RP1);//valve 1
off(RP5);// Main Water Pump
Serial.println("Humid Soil");
}
else if(Moisture_Sensor1val || Moisture_Sensor2val || Moisture_Sensor3val > 700)
{
off(RP1);//valve 1
off(RP5);// Main Water Pump
Serial.println("In Water");
}
Moisture_Sensor4val = analogRead(Moisture_Sensor4);
Moisture_Sensor5val = analogRead(Moisture_Sensor5);
Moisture_Sensor6val = analogRead(Moisture_Sensor6);
Moisture_Sensor7val = analogRead(Moisture_Sensor7);
Moisture_Sensor8val = analogRead(Moisture_Sensor8);
Moisture_Sensor9val = analogRead(Moisture_Sensor9);
// Temp sensors to anolog pin Val read
HT_T_Sensor1val = analogRead(HT_T_Sensor1);
HT_T_Sensor2val = analogRead(HT_T_Sensor2);
HT_T_Sensor3val = analogRead(HT_T_Sensor3);
HT_T_Sensor4val = analogRead(HT_T_Sensor4);
/* Humidity sensors to anolog pin Val read
HT_H_Sensor1val = analogRead(HT_H_Sensor1);
HT_H_Sensor2val = analogRead(HT_H_Sensor2);
HT_H_Sensor3val = analogRead(HT_H_Sensor3);
HT_H_Sensor4val = analogRead(HT_H_Sensor4);
*/
Float_Switch1val = digitalRead(Float_Switch1);
}