2
const int buzzerPin = 7;
const int flamePin = 10;
int Flame = HIGH;
int redled = 8;
void setup() 
{
  pinMode(buzzerPin, OUTPUT);
  pinMode(redled, OUTPUT);

  pinMode(flamePin, INPUT);
  Serial.begin(12000);
}

void loop() 
{
  Flame = digitalRead(flamePin);
  if (Flame== HIGH)
  {
    digitalWrite(redled, HIGH);
  int i=0;
  do {
    digitalWrite(buzzerPin, HIGH);
    tone(buzzerPin,450);
    delay(200);
    noTone(buzzerPin);
    delay(200);
    
  }while (i<2);
  } 
  else
  {
    digitalWrite(buzzerPin, LOW);
    digitalWrite(redled, LOW);
  }
}
3
  • test the buzzer with the simplest code possible
    – jsotola
    Commented Jun 9, 2021 at 16:25
  • We don't know anything about your buzzer or circuit, so there's little to offer in the way of help. Please make sure when posting code that it's formatted as code so people can actually read it. It's also helpful to include what does work, e.g., there are other factors in your code that could make it seem like the buzzer isn't working. Commented Jun 9, 2021 at 16:40
  • 2
    450 is too low frequency for a piezo. use 3000
    – Juraj
    Commented Jun 9, 2021 at 17:53

1 Answer 1

1

Here are the modifications I have done

  • I changed the Piezo Buzzer frequency to 3000 Hz The green Button simulates the Flame signal
  • Change the RED LED from pin 8 to Pin 13 so that I don't have to use an external LED

Here is the simulation output

enter image description here

Observe the onboard LED going HIGH and the buzzer going off. You can find the project link here where you can test with different Piezo buzzer frequency.

Code

const int buzzerPin = 7;
const int flamePin = 10;
int Flame = HIGH;
int redled = 13;
void setup() 
{
  pinMode(buzzerPin, OUTPUT);
  pinMode(redled, OUTPUT);  

  pinMode(flamePin, INPUT);
  Serial.begin(12000);
}

void loop() 
{
  Flame = digitalRead(flamePin);
  if (Flame== HIGH)
  {
    digitalWrite(redled, HIGH);
  int i=0;
  do {
    digitalWrite(buzzerPin, HIGH);
    tone(buzzerPin,3000);
    delay(200);
    noTone(buzzerPin);
    delay(200);
    
  }while (i<2);
  } 
  else
  {
    digitalWrite(buzzerPin, LOW);
    digitalWrite(redled, LOW);
  }
}

Disclaimer: I am not the Wokwi creator but I support it since it is open source and free to use

2
  • @Juraj fixed it
    – ArduinoFan
    Commented Jun 13, 2021 at 7:17
  • @Juraj I Doubt it. if the flame signal is high, he is triggering the alarm
    – ArduinoFan
    Commented Jun 13, 2021 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.