Buzzer always ringing

Hello...

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();
  
}

Hi,
Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

When a pin it set to OUTPUT it defaults to LOW. If your buzzer is triggered by LOW, it will begin buzzing immediately.

Your buzzer() function is never called, so the pin remains LOW.

ahh..thanks for the quick reply Tom :smiley:

wait a minute

i see, now i've deleted the

pinMode(buzzerPin, OUTPUT);

the code looks like this now (for testing purposes only) :



const int water_level = A0;
const int buzzerPin = D1;

void setup() {
  Serial.begin(115200);

}

void waterLevel() {
  int level = analogRead(water_level);
  Serial.print("Water Level : ");
  Serial.println(level);
  delay(200);
}

void buzzer(){
  
}
void loop() {
  waterLevel();

  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
}

but the Buzzer now won't beep at all? what's wrong? what should i change

pinMode(buzzerPin, OUTPUT);

with? thanks for the help :smiley:

Try

pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, HIGH); 

but you may find that the buzzer clicks or buzzes for a short time when the Arduino starts up or is reset.

ahh...thanks Paul :smiley:

it worked!, i dont notice the buzzer clicks for the first time starting Arduino, which is good

now i notice that my Buzzer is triggered by LOW signal, i switch my code "LOW" to "HIGH" and vice versa, this sounds perfect...many thanks :+1:

has been solved Tom :+1: ...anyway many thanks for the help :smiley:

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.

i just don't realize that "LOW Level" means the level used to program the buzzer.my bad, never read the Buzzer previously

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.