To many arguments to function

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);
}
  if (Moisture_Sensor1val< 300 | (Moisture_Sensor2val< 300 | Moisture_Sensor3val< 300);

The logical OR is ||, not |.

Count the number of open and close parentheses. You MUST come up with the same number of each.

It is very rare to see a ; on the end of an if statement.

Thanks for the quick reply.

I did change those couple things and , unfortunately, am still getting the same errors.
could it be in the "void on " /"void off " section near the void setup ?!?!

I think it's still in the IF statements but not sure.

thanks

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");
      }

Hard code values for Moisture_Sensor1, Moisture_Sensor2, Moisture_Sensor3

and trace the logic with Serial.println( )

Using arrays and for loops will make your script easier to write, and easier to read too :wink:

Here

on(RP1);//valve 1

you try to call the on() function with a parameter. Yet your on() function is defined without needing a parameter.

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);
}

Your "if" statement looks OK.

You have an extra space in the declaration of "zone 4" (should be zone4)

And you are creating on and off such that they take no arguments:

void on() {
  digitalWrite(RP1, HIGH);

but are calling them WITH an argument:

if (Moisture_Sensor1val < 300 || Moisture_Sensor2val < 300 || Moisture_Sensor3val < 300)
  {
    on(RP1);//valve 1
    on(RP5);// Main Water Pump

So of course you get a "too many arguments" error.

thanks for all the help guys...

Self-learner and a newbie so the understanding of the simple mistakes is greatly appreciated :slight_smile:

Keep doing what you do .

Is all working now :slight_smile:

sean

Another tip: Just before copying your code from the IDE for a post, use Ctrl-T. It reformats the code in a standard C style that's easier for us to read.

if(Moisture_Sensor1val || Moisture_Sensor2val || Moisture_Sensor3val > 300 && < 700)

The stuff in the if() parenthesis must be a syntactically valid expression in the C++ language for the compiler to understand it. When the compiler reats the code above, it sees:

if Moisture_Sensor1val is nonzero or Moisture_Sensor2val is nonzero or Moisture_Sensor3val > 300 and WTF??

What it will understand is

if( (Moisture_Sensor1val > 300 && Moisture_Sensor1val < 700)
   || (Moisture_Sensor2val > 300 && Moisture_Sensor2val < 700)
   || (Moisture_Sensor3val > 300 && Moisture_Sensor3val < 700))

Now, that's pretty wordy. There are a variety of ways to make it neater, such as using an array of values, and using a function or define for bounds checking.

But for the moment, there's your answer. But the longer answer is: read a tutorial on the C++ language. Here's one. You only need the first couple of sections to start with.