Newbie question I know, I want the buzzer to beep once only in an if statement. The if statement is that if the water level sensor detects that the water tank is empty. The problem is that it keeps on beeping continuously as the condition is in the loop. How can I let it beep once only whenever the if condition happens? Please help its urgent, thanks.
The problem is that it keeps on beeping continuously as the condition is in the loop.
The problem is you 'have not' shown us your code.
use a variable to mark the buzzer is beep or not. for example
isBeeped = false;
and set it to true when you beep.
If the isBeeped == true, do not beep
IoT_hobbyist:
use a variable to mark the buzzer is beep or not. for example
isBeeped = false;and set it to true when you beep.
If the isBeeped == true, do not beep
And set it back to false when the tank becomes un-empty, else it won't beep next time it empties.
Your problem comes down to what is called state change detection (beep when the water level goes low, not when the water level is low).
See the example in the IDE on how it's done.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.