so i'm trying to make a function called "buzzer" which will be called by waterlevel when water is detected has reached to some point, this will beep...at first i try the code in the void loop everything works fine, however when the "2x beep buzzer" code i moved to a new function, now the buzzer is always continuesly beeping (although i havent called the function yet)...what's wrong? anyone can help?
i'm using Lolin V3 ESP8266 and "Buzzer Module Low Level Trigger" buzzer module. my code :
const int water_level = A0;
const int buzzerPin = D1;
void setup() {
Serial.begin(115200);
pinMode(buzzerPin, OUTPUT);
}
void waterLevel() {
int level = analogRead(water_level);
Serial.print("Water Level : ");
Serial.println(level);
delay(200);
}
void buzzer(){
digitalWrite(buzzerPin, HIGH); // turn the buzzer on
delay(250); // wait for 250 milliseconds
digitalWrite(buzzerPin, LOW); // turn the buzzer off
delay(250); // wait for 250 milliseconds
digitalWrite(buzzerPin, HIGH); // turn the buzzer on
delay(250); // wait for 250 milliseconds
digitalWrite(buzzerPin, LOW); // turn the buzzer off
delay(1000); // wait for 1 second
}
void loop() {
waterLevel();
}
How did you figure it out? Clearly, nothing in post #3 gave you any clue about that, and that fact that it is described as "Low Level Trigger" was not helpful either.