# Buzzer not working (problem in code)

**URL:** <https://forum.arduino.cc/t/buzzer-not-working-problem-in-code/1058290>\
**Category:** Sensors\
**Created:** [November 26, 2022, 6:30pm UTC](https://forum.arduino.cc/t/buzzer-not-working-problem-in-code/1058290 "2022-11-26T18:30:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gega\_yee](https://avatars.discourse-cdn.com/v4/letter/g/22d042/32.png) [@gega\_yee](https://forum.arduino.cc/u/gega_yee)\
**Post date:** [November 26, 2022, 6:30pm UTC](https://forum.arduino.cc/t/buzzer-not-working-problem-in-code/1058290/1 "2022-11-26T18:30:59Z")

</div>

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

```cpp
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);
}

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [November 26, 2022, 6:35pm UTC](https://forum.arduino.cc/t/buzzer-not-working-problem-in-code/1058290/2 "2022-11-26T18:35:35Z")

</div>

Welcome to the forum

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

> [@gega\_yee](#):
>
> Here is my code

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)&nbsp;to make it easier to read and copy for examination

> [@How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966):
>
> See also [FAQ - Arduino Forum](https://forum.arduino.cc/faq) for general rules on forum behavior and etiquette. Hello, Welcome to the Arduino Forum. This guide explains how to get the best out of this forum. Please read and follow the instructions below. Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is frus…

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [November 26, 2022, 6:36pm UTC](https://forum.arduino.cc/t/buzzer-not-working-problem-in-code/1058290/3 "2022-11-26T18:36:39Z")

</div>

> [@gega\_yee](#):
>
> ```arduino
> else digitalWrite(led, LOW);
> digitalWrite(buzzer, LOW);
> value = analogRead(analog);
> Serial.println(value);
> delay(250);
> 
> ```

```arduino

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

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

```

---

<div class="post-metadata">

**Author:** ![gega\_yee](https://avatars.discourse-cdn.com/v4/letter/g/22d042/32.png) [@gega\_yee](https://forum.arduino.cc/u/gega_yee)\
**Post date:** [November 26, 2022, 6:38pm UTC](https://forum.arduino.cc/t/buzzer-not-working-problem-in-code/1058290/4 "2022-11-26T18:38:20Z")

</div>

What do you mean? I used it.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/a/7/7/a7700b2068a1e083279056dba83626ba132fb442.png)

---

<div class="post-metadata">

**Author:** ![gega\_yee](https://avatars.discourse-cdn.com/v4/letter/g/22d042/32.png) [@gega\_yee](https://forum.arduino.cc/u/gega_yee)\
**Post date:** [November 26, 2022, 6:40pm UTC](https://forum.arduino.cc/t/buzzer-not-working-problem-in-code/1058290/5 "2022-11-26T18:40:50Z")

</div>

oooh yeah I forgot about that. tysm

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [November 26, 2022, 6:45pm UTC](https://forum.arduino.cc/t/buzzer-not-working-problem-in-code/1058290/6 "2022-11-26T18:45:30Z")

</div>

> [@gega\_yee](#):
>
> What do you mean? I used it.

My apologies if I misread how you had posted your code

---

<div class="post-metadata">

**Author:** ![gega\_yee](https://avatars.discourse-cdn.com/v4/letter/g/22d042/32.png) [@gega\_yee](https://forum.arduino.cc/u/gega_yee)\
**Post date:** [November 26, 2022, 6:47pm UTC](https://forum.arduino.cc/t/buzzer-not-working-problem-in-code/1058290/7 "2022-11-26T18:47:34Z")

</div>

It's alright

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 25, 2023, 6:47pm UTC](https://forum.arduino.cc/t/buzzer-not-working-problem-in-code/1058290/8 "2023-05-25T18:47:56Z")

</div>

Closed on May 25, 2023, 6:47pm UTC

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