Hello, i'm new here, and new on arduino. So thank you for your patience.
I am trying to program a water level sensor constituted of 5 to 10 non-contact sensors.
When the sensors detects water, it sends a signal printed as "1", else, it's "0".
Everything is working except that the serial monitor is printing not necessary informations as seen below
Water height 10% reached : 1
Water height 20% reached : 1
Water height 30% reached : 1
Water height 40% reached : 0
Water height 50% reached : 0
...when the water reachs 30%, i want to only print the reached level,
ex . "Water height 30% reached : 1"
and not the others heights like "Water height 10% reached : 0" and "Water height 20% reached : 0"
I can't find the argument to tell my program to "print only ... " perhaps should i search something with the "else" and "else if" arguments... but i didn't succeed...may i ask for help ? this is my beginner code :
int wls10 = 0; //Water level sensor 1 ok
int wls20 = A2; //Water level sensor 2 ok
int wls30 = 6; //Water level sensor 3 ok
int wls40 = 7; //Water level sensor 4 ok
int wls50 = 5; //Water level sensor 5 ok
//int wls = 32; //Water level sensor 6 ok
//int wls = 33; //Water level sensor 7 ok
//int wls = 34; //Water level sensor 8 ok
//int wls = 36; //Water level sensor 9 ok
//int wls = 39; //Water level sensor 10 ok
int level10 = 0; //Variable to store the data received from sensor
int level20 = 0;
int level30 = 0;
int level40 = 0;
int level50 = 0;
//int buzzer = 5;
void setup() {
Serial.begin(9600);
pinMode(wls10, INPUT);
pinMode(wls20, INPUT);
pinMode(wls30, INPUT);
pinMode(wls40, INPUT);
pinMode(wls50, INPUT);
//pinMode(wls60, INPUT);
//pinMode(wls70, INPUT);
//pinMode(wls80, INPUT);
//pinMode(wls90, INPUT);
//pinMode(wls100, INPUT);
//pinMode(pump, OUTPUT);
}
void loop() {
level10 = digitalRead(wls10);
level20 = digitalRead(wls20);
level30 = digitalRead(wls30);
level40 = digitalRead(wls40);
level50 = digitalRead(wls50);
///////////////////////////////////////////////////////////////
//if (level10 == 1 && level20 != 1 && level30 != 1 && level40 != 1 && level50 != 1) //My sensor gives 0 when it senses water and 1 when there is no water
//if (level10 == 1 && level20 == 1 && level30 != 1 && level40 != 1 && level50 != 1)
//if (level10 == 1 && level20 == 1 && level30 == 1 && level40 != 1 && level50 != 1)
//if (level10 == 1 && level20 == 1 && level30 == 1 && level40 == 1 && level50 != 1)
//if (level10 == 1 && level20 == 1 && level30 == 1 && level40 == 1 && level50 == 1)
if (level10 == 1 && level20 != 1 && level30 != 1 && level40 != 1 && level50 != 1);
{
Serial.print("Water height 10% reached : ");
Serial.print(level10);
Serial.println("");
}
if (level10 == 1 && level20 == 1 && level30 != 1 && level40 != 1 && level50 != 1);
{
Serial.print("Water height 20% reached : ");
Serial.print(level20);
Serial.println("");
}
if (level10 == 1 && level20 == 1 && level30 == 1 && level40 != 1 && level50 != 1);
{
Serial.print("Water height 30% reached : ");
Serial.print(level30);
Serial.println("");
}
if (level10 == 1 && level20 == 1 && level30 == 1 && level40 == 1 && level50 != 1);
{
Serial.print("Water height 40% reached : ");
Serial.print(level40);
Serial.println("");
}
if (level10 == 1 && level20 == 1 && level30 == 1 && level40 == 1 && level50 == 1);
{
Serial.print("Water height 50% reached : ");
Serial.print(level50);
Serial.println("");
}
Serial.println("");
Serial.println("");
Serial.println("");
Serial.println("");
delay(2000);
}
Thanks in advance ! Alain