My first code

Hello to all,
I will post my first automatic irrigation project for 2 plants.
The following is the code that at line 105 gives me an error (error: expected unqualified-id before 'if' if (ValSenA = <300); {)

// definizione delle librerie
#include <Wire.h>
#include <RTClib.h>

// frequency musical notes
#define NOTE_C6 1047
#define NOTE_C3 131
#define NOTE_G3 196

// definizione dei pin
int SensUmiA = 1;
int SensUmiB = 2;
int LedA = 3;
int LedB = 6;
int PompA = 8;
int PompB = 7;
int Buz = 2;
int RedLedA = 5;
int GreenLedA = 4;
int RedLedB = 9;
int GreenLedB = 10;

// variabili
int ValSensA; // Valore del sensore A
int ValSensB; // Valore del sensore B

// definizione degli oggetti
RTC_DS1307 RTC;

void setup() {

/* Vorrei fare in modo che il ValSensA e ValSensB eseguano le letture esattamente alle ore; 00:00 , 06:00 , 12:00 , 18:00 di ogni giorno.
3 letture a distanza di 5 minuti e trarre la media.
L'attivazione della pompa A/B con ValSensA/B <300 ma solo dalle 22:00 alle 06:00*/

// inizializzazione seriale
Serial.begin(9600);

// RTC initialization // non conosco come impostare il modulo RTC
//RTC.begin();
//if (!RTC.isrunning()){
// date and time adjust as the PC computer date and time
//RTC.adjust(DateTime(DATE, TIME));

// inizializzazione Pin Arduino Nano
pinMode(Buz, OUTPUT);
pinMode(LedA, OUTPUT);
pinMode(LedB, OUTPUT);
pinMode(PompA, OUTPUT);
pinMode(PompB, OUTPUT);
pinMode(RedLedA, OUTPUT);
pinMode(GreenLedA, OUTPUT);
pinMode(RedLedB, OUTPUT);
pinMode(GreenLedB, OUTPUT);

// inizializzazione ritardo
delay(5000);
}

void loop() {
// lettura dei sensori
ValSensA = analogRead(SensUmiA);
ValSensB = analogRead(SensUmiB);
}

// ricerca range di umidità
if(ValSenA =>500);{
digitalWrite(GreenLedA,HIGH);
// valore superiore a 500 corrisponde terra bagnata
delay(250);

}
if(ValSenB => 500);{
digitalWrite(GreenLedB, HIGH);
// valore superiore a 500 corrisponde terra bagnata
delay(250);
}

if(ValSenA >=300) && (ValSenA <500);{
//se il valore è compreso tra 300 e 500 lampeggia led verde
digitalWrite(GreenLedA,LOW);
delay(500);
digitalWrite(GreenLedA,HIGH);
delay(500);
}

if(ValSenB >=300) && (ValSenB <500);{
//se il valore è compreso tra 300 e 500 lampeggia led verde
digitalWrite(GreenLedB,LOW);
delay(500);
digitalWrite(GreenLedB,HIGH);
delay(500);
}

if(ValSenA =< 300);{
digitalWrite(RedLedA, HIGH);
// valore inferiore o uguale a 300 accendi led rosso terra secca
tone(Buz,NOTE_C6, 100); // suona allarme
delay(250);
digitalWrite(PompA,HIGH); //attiva pompa A
noTone(Buz);
ValSensA = analogRead(SensUmiA);
}

if(ValSensB <= 300);{
digitalWrite(RedLedB, HIGH);
// valore inferiore o uguale a 300 accendi led rosso terra secca
tone(Buz,NOTE_C6, 100); // suona allarme
delay(250);
digitalWrite(PompB,HIGH); // attiva pompa B
noTone(Buz);
ValSensB = analogRead(SensUmiB);
}

{
digitalWrite(PompA, LOW); // spegni pompa A
digitalWrite(RedLedA, LOW); // spegni led rosso A
}

{
digitalWrite(PompB, LOW); // spegni pompa B
digitalWrite(RedLedB, LOW); // spegni led rosso B
}

delay(500);

}

I ask you a hand in solving the error and if it is a code in green that could work

Then after solving this I will pass on other questions in red

thanks everyone in advance

void loop() {
  // lettura dei sensori
  ValSensA = analogRead(SensUmiA);
  ValSensB = analogRead(SensUmiB);
}

Look where your loop() function ends.

Remove ; after if()

PLEASE read how to post in the forum...

  • Code goes within tags.
  • Use IDE Auto-Format to correctly indent before you code
  • Pictures go inline where possible.
  • Fritzy drawings are frowned upon, as they are very hard to read.
    OK, you're still learning (15 posts) - now's the time to learn!
    Good luck with your Arduino

arduino_new:
Remove ; after if()

I removed the; after if but continue to give me the error

dino72:
I removed the; after if but continue to give me the error

You modified the code. You forgot to post the code. You forgot to post the exact error messages.

if(ValSenB <= 300){

the line highlighted in green in the code

this message error
exit status 1
expected unqualified-id before 'if'

RTC don't know

I would like the ValSensA and ValSensB to do the readings exactly at the time; 00:00, 06:00, 12:00, 18:00 every day.
3 readings at a distance of 5 minutes and get the average.
The activation of the A / B pump with ValSensA / B <300 but only from 22:00 to 06:00

can someone help me how to set up the RTC module according to my preferences?

can someone help me how to set up the RTC module according to my preferences?

Do you have a watch? How do you set it up to do something at 0:00, 6:00, etc.? Or, do you actually have to look at it to see that it is 3:30, and check that there is nothing to do now?

Does the RTC module keep the time in memory?
Can a relay be controlled at a set time?
In the time slot (22:00 - 06:00) if the ValSensA / B is <= 300 the relay starts

Can you do this?

dino72:

if(ValSenB <= 300){

the line highlighted in green in the code

this message error
exit status 1
expected unqualified-id before 'if'

The error is in the code that you have not posted.

I try to enter the correct code but it keeps giving me the same error

dino72:
I try to enter the correct code but it keeps giving me the same error

So, fix the code.

If you need help, post ALL of your code AND your COMPLETE error message(s).

this is the code

// definizione delle librerie
#include <Wire.h>
#include <RTClib.h>

// frequency musical notes
#define NOTE_C6 1047
#define NOTE_C3 131
#define NOTE_G3 196

// definizione dei pin
int SensUmiA = 1;
int SensUmiB = 2;
int LedA = 3;
int LedB = 6;
int PompA = 8;
int PompB = 7;
int Buz = 2;
int RedLedA = 5;
int GreenLedA = 4;
int RedLedB = 9;
int GreenLedB = 10;

// variabili
int ValSensA; // Valore del sensore A
int ValSensB; // Valore del sensore B

// definizione degli oggetti
RTC_DS1307 RTC;

void setup() {

/* Vorrei fare in modo che il ValSensA e ValSensB eseguano le letture esattamente alle ore; 00:00 , 06:00 , 12:00 , 18:00 di ogni giorno.
3 letture a distanza di 5 minuti e trarre la media.
L'attivazione della pompa A/B con ValSensA/B <300 ma solo dalle 22:00 alle 06:00*/

// inizializzazione seriale
Serial.begin(9600);

// RTC initialization // non conosco come impostare il modulo RTC
//RTC.begin();
//if (!RTC.isrunning()){
// date and time adjust as the PC computer date and time
//RTC.adjust(DateTime(DATE, TIME));

// inizializzazione Pin Arduino Nano
pinMode(Buz, OUTPUT);
pinMode(LedA, OUTPUT);
pinMode(LedB, OUTPUT);
pinMode(PompA, OUTPUT);
pinMode(PompB, OUTPUT);
pinMode(RedLedA, OUTPUT);
pinMode(GreenLedA, OUTPUT);
pinMode(RedLedB, OUTPUT);
pinMode(GreenLedB, OUTPUT);

// inizializzazione ritardo
delay(5000);
}

void loop() {
// lettura dei sensori
ValSensA = analogRead(SensUmiA);
ValSensB = analogRead(SensUmiB);
}

// ricerca range di umidità
if(ValSenA =>500){
digitalWrite(GreenLedA,HIGH);
// valore superiore a 500 corrisponde terra bagnata
delay(250);

}
if(ValSenB => 500){
digitalWrite(GreenLedB, HIGH);
// valore superiore a 500 corrisponde terra bagnata
delay(250);
}

if(ValSenA >=300) && (ValSenA <500){
//se il valore è compreso tra 300 e 500 lampeggia led verde
digitalWrite(GreenLedA,LOW);
delay(500);
digitalWrite(GreenLedA,HIGH);
delay(500);
}

if(ValSenB >=300) && (ValSenB <500){
//se il valore è compreso tra 300 e 500 lampeggia led verde
digitalWrite(GreenLedB,LOW);
delay(500);
digitalWrite(GreenLedB,HIGH);
delay(500);
}

if(ValSenA =< 300){
digitalWrite(RedLedA, HIGH);
// valore inferiore o uguale a 300 accendi led rosso terra secca
tone(Buz,NOTE_C6, 100); // suona allarme
delay(250);
digitalWrite(PompA,HIGH); //attiva pompa A
noTone(Buz);
ValSensA = analogRead(SensUmiA);
}

if(ValSensB <= 300){
digitalWrite(RedLedB, HIGH);
// valore inferiore o uguale a 300 accendi led rosso terra secca
tone(Buz,NOTE_C6, 100); // suona allarme
delay(250);
digitalWrite(PompB,HIGH); // attiva pompa B
noTone(Buz);
ValSensB = analogRead(SensUmiB);
}

{
digitalWrite(PompA, LOW); // spegni pompa A
digitalWrite(RedLedA, LOW); // spegni led rosso A
}

{
digitalWrite(PompB, LOW); // spegni pompa B
digitalWrite(RedLedB, LOW); // spegni led rosso B
}

delay(500);

}

and this is the message

Arduino:1.8.4 (Windows 10), Scheda:"Arduino Nano, ATmega328P"

sketch_may07a:67: error: expected unqualified-id before 'if'

if(ValSenA =>500){

^

sketch_may07a:73: error: expected unqualified-id before 'if'

if(ValSenB => 500){

^

sketch_may07a:79: error: expected unqualified-id before 'if'

if(ValSenA >=300) && (ValSenA <500){

^

sketch_may07a:87: error: expected unqualified-id before 'if'

if(ValSenB >=300) && (ValSenB <500){

^

sketch_may07a:95: error: expected unqualified-id before 'if'

if(ValSenA =< 300){

^

sketch_may07a:105: error: expected unqualified-id before 'if'

if(ValSensB <= 300){

^

sketch_may07a:115: error: expected unqualified-id before '{' token

{

^

sketch_may07a:120: error: expected unqualified-id before '{' token

{

^

sketch_may07a:125: error: expected constructor, destructor, or type conversion before '(' token

delay(500);

^

sketch_may07a:127: error: expected declaration before '}' token

}

void loop() {
  // lettura dei sensori
  ValSensA = analogRead(SensUmiA);
  ValSensB = analogRead(SensUmiB);
}

THAT is your loop() function. ALL of the code after that is not in a function. ALL executable code MUST be in a function.

be patient .... :sweat_smile:
So how do I proceed?

dino72:
be patient .... :sweat_smile:
So how do I proceed?

Is there some part of "ALL executable code must be in a function" that you don't understand?

What you need to do is recognize that the } that ends loop() means "Do NOT type code after me".

Resolved!!!
It was just a matter of brackets ..... and thank's at PaulS that made me think

// definizione delle librerie
#include <Wire.h>
#include <RTClib.h>

// frequency musical notes
#define NOTE_C6  1047
#define NOTE_C3  131
#define NOTE_G3  196

// definizione dei pin
int SensUmiA = 1;
int SensUmiB = 2;
int LedA = 3;
int LedB = 6;
int PompA = 8;
int PompB = 7;
int Buz = 2;
int RedLedA = 5;
int GreenLedA = 4;
int RedLedB = 9;
int GreenLedB = 10;

// variabili
int ValSensA; // Valore del sensore A
int ValSensB; // Valore del sensore B

// definizione degli  oggetti
RTC_DS1307 RTC;

void setup() {

  /* Vorrei fare in modo che il ValSensA e ValSensB eseguano le letture esattamente alle ore; 00:00 , 06:00 , 12:00 , 18:00 di ogni giorno.
    3 letture a distanza di 5 minuti e trarre la media.
    L'attivazione della pompa A/B con ValSensA/B <300 ma solo dalle 22:00 alle 06:00*/

  // inizializzazione seriale
  Serial.begin(9600);

  // RTC initialization   // non conosco come impostare il modulo RTC
  //RTC.begin();
  //if (!RTC.isrunning()){
  // date and time adjust as the PC computer date and time
  //RTC.adjust(DateTime(__DATE__, __TIME__));

  // inizializzazione Pin Arduino Nano
  pinMode(Buz, OUTPUT);
  pinMode(LedA, OUTPUT);
  pinMode(LedB, OUTPUT);
  pinMode(PompA, OUTPUT);
  pinMode(PompB, OUTPUT);
  pinMode(RedLedA, OUTPUT);
  pinMode(GreenLedA, OUTPUT);
  pinMode(RedLedB, OUTPUT);
  pinMode(GreenLedB, OUTPUT);

  // inizializzazione ritardo
  delay(5000);
}

void loop() {
  // lettura dei sensori
  ValSensA = analogRead(SensUmiA);
  ValSensB = analogRead(SensUmiB);


  // ricerca range di umidità
  if (analogRead(ValSensA) >= 500) {
    digitalWrite(GreenLedA, HIGH);
    // valore superiore a 500 corrisponde terra bagnata
    delay(250);

  }

  if (analogRead(ValSensB) >= 500) {
    digitalWrite(GreenLedB, HIGH);
    // valore superiore a 500 corrisponde terra bagnata
    delay(250);
  }

  if ((analogRead(ValSensA) > 300) && (analogRead(ValSensA) < 500)) {
    //se il valore è compreso tra 300 e 500 lampeggia led verde
    digitalWrite(GreenLedA, LOW);
    delay(500);
    digitalWrite(GreenLedA, HIGH);
    delay(500);
  }

  if ((analogRead(ValSensB) > 300) && (analogRead(ValSensB) < 500)) {
    //se il valore è compreso tra 300 e 500 lampeggia led verde
    digitalWrite(GreenLedB, LOW);
    delay(500);
    digitalWrite(GreenLedB, HIGH);
    delay(500);
  }

  if (analogRead(ValSensA) < 300) {
    digitalWrite(RedLedA, HIGH);
    // valore inferiore o uguale a 300 accendi led rosso terra secca
    tone(Buz, NOTE_C6, 100); // suona allarme
    delay(250);
    digitalWrite(PompA, HIGH); //attiva pompa A
    noTone(Buz);
    ValSensA = analogRead(SensUmiA);
  }

  if (analogRead(ValSensB) < 300) {
    digitalWrite(RedLedB, HIGH);
    // valore inferiore o uguale a 300 accendi led rosso terra secca
    tone(Buz, NOTE_C6, 100); // suona  allarme
    delay(250);
    digitalWrite(PompB, HIGH); // attiva pompa B
    noTone(Buz);
    ValSensB = analogRead(SensUmiB);
  }

  {
    digitalWrite(PompA, LOW); // spegni pompa A
    digitalWrite(RedLedA, LOW); // spegni led rosso A
  }

  {
    digitalWrite(PompB, LOW); // spegni pompa B
    digitalWrite(RedLedB, LOW); // spegni led rosso B
  }

  delay(500);

}

Now I would like the ValSensA and ValSensB to do the readings exactly at the time; 00:00, 06:00, 12:00, 18:00 every day.
3 readings at a distance of 5 minutes and get the average.
Activation of the A / B pump with ValSensA / B <300 but only between 22:00 and 06:00

It's possible?

It's possible?

Yes