Buzzer not working (problem in code)

Hi. I'm trying to make a CO2 detector. basically when there's more than 200 I want it to light up led and activate a buzzer. while the led works, the buzzer only lets out like a ticking sound and I have no idea why. I'm new to this and I don't know coding well. also I checked the buzzer and it works in my other project. Here is my code

int analog = A0;
int value = 0;
int buzzer = 6;
int led = 13;
void setup() {
pinMode(analog, INPUT);
pinMode(led, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (value > 200) {
digitalWrite(buzzer, HIGH);
digitalWrite(led, HIGH);
}
else digitalWrite(led, LOW);
digitalWrite(buzzer, LOW);
value = analogRead(analog);
Serial.println(value);
delay(250);
}

Welcome to the forum

Why don't users read and follow the advice that they are directed to when first joing the forum ?

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use [color = red]code tags[/color] (the </> icon above the compose window) to make it easier to read and copy for examination


else 
{
digitalWrite(led, LOW);
digitalWrite(buzzer, LOW);
}

value = analogRead(analog);
Serial.println(value);
delay(250);


1 Like

What do you mean? I used it.

oooh yeah I forgot about that. tysm

My apologies if I misread how you had posted your code

1 Like

It's alright

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