Skip to content
All notebook entries
Hardware · · Entry #13

Adding the buzzer (because nobody watches an LED forever)

I figured out that nobody actually stares at the LED waiting for spoiled food. So I added a buzzer. It's loud. My mom does not love it. Sorry, mom.

Adding the buzzer (because nobody watches an LED forever)

Here’s a thing I learned at Community Storehouse: nobody is going to sit and stare at your blinky LED for 8 hours waiting for it to turn red. People are busy. Pantry volunteers are running around. Families are making dinner. If the gadget can’t get your attention from across the room, it might as well not exist.

So I added a buzzer.

What I picked

A 5V active piezo buzzer. Important word: active. Here’s the difference:

  • Passive buzzer: you have to send it a wiggly signal (a “PWM” wave) at the exact frequency you want it to make. More wiring, more code. But you can play actual tunes.
  • Active buzzer: you just give it +5V and ground. It buzzes at its own built-in frequency. Two wires. Done.

For a food-spoilage alarm I don’t need it to play “Twinkle Twinkle Little Star.” I just need it to make NOISE when something is spoiling. So: active. Easy.

The wiring

Two wires. That’s it.

  1. The (+) pin goes to a GPIO pin on the ESP32 (I picked pin 23).
  2. The (-) pin goes to ground.

Then in code, I do digitalWrite(23, HIGH) to turn it on, digitalWrite(23, LOW) to turn it off.

// pseudocode in my alarm function
void alarm(bool on) {
  if (on) {
    digitalWrite(BUZZER_PIN, HIGH);  // BEEEEEP
    digitalWrite(LED_RED, HIGH);
  } else {
    digitalWrite(BUZZER_PIN, LOW);
    digitalWrite(LED_RED, LOW);
  }
}

The first test (and a small disaster)

I wired it up. I uploaded the code. I triggered the alarm by holding a piece of moldy bread up to the sensor. The buzzer went BEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE at the loudest, most piercing volume I have ever heard a tiny piece of plastic produce. The dog ran out of the room. My mom called from the kitchen. I yanked the power cable out as fast as I could.

So now I have a TODO: add a “max alarm length” in the code so the buzzer doesn’t just buzz forever. Beep three times. Wait a few seconds. Beep three more times. Like a real smoke detector. Less ear damage. More chance my family lets me keep the gadget in the kitchen.

Why I’m telling you all of this

Because it’s the kind of small thing that nobody mentions in tutorials. They show you the wiring. They don’t tell you about the dog running out of the room. Real builds have these moments. They are completely normal. And kind of funny.

  • Sri (and a slightly traumatized dog)

- Sri

Related entries