Water sensor and buzzer

Hi everyone!

So I have a water sensor working with the following code

void setup(){

Serial.begin(9600);

}

void loop(){

Serial.print("Water level Sensor Value:");
Serial.println(analogRead(A5));
delay(100);

}

But i would like to add the functionality of when the water level/analouge output gets to a certain point for the buzzer to sound. Alerting the user the the water level is to high.

Is an if statement the best way to go about doing this? if not which way is best?

thanks!!

Yes use an if statement.

So the next question is how do I program the if statement? I have never done one where the condition is based on an analogue output. Could you help?

Grumpy_Mike: Yes use an if statement.

An if statement compaires two things. In your case one will be the sensor reading and the other the threshold you want to compaire it with. Between the two is the comparison type which is > for greater than or < for less that or == for equals to.

If the test is passed then the next statement is done, if you want more than one statement to be done then you put them all in braces { }

Grumpy_Mike:
An if statement compaires two things. In your case one will be the sensor reading and the other the threshold you want to compaire it with. Between the two is the comparison type which is > for greater than or < for less that or == for equals to.

If the test is passed then the next statement is done, if you want more than one statement to be done then you put them all in braces { }

Brilliant thanks! Another learning curve achieved :slight_smile: