Please help with piezo buzzer and Esp32

I am using an Esp32 and a Piezo buzzer (two legs). This is my code

output:
  - platform: ledc
    pin: GPIO19
    id: buzzer_output

switch:
  - platform: output 
    name: 'buzzer'
    id: buzzer
    output: buzzer_output
    on_turn_on: 
      then:
        - output.turn_on: buzzer_output
        - output.ledc.set_frequency:
            id: buzzer_output
            frequency: "1000Hz"
        - output.set_level:
            id: buzzer_output
            level: "50%"

    on_turn_off:
      then:
        - output.turn_off: buzzer_output
        
    

I can’t make the buzzer beep by turning the switch on/off. If I directly connect the buzzer to VCC and GND it beeps. Thanks in advance for your help.

2 Likes

Sounds like you have an active buzzer?

I’ve never used them.

I use passive ones and the rttl component and that works well.

I checked and indeed they are active buzzers. I really can’t understand why I couldn’t make it work. It should be as simple as making the gpio pin 19 high and low, right? Maybe I am making it too complicated.

Yeah I know what you mean. I was going to suggest just trying it with a basic gpio switch config?

I have tried that but for some reason it doesn’t work. :frowning:

1 Like

Did you try your luck just using the rttl? You never know…

After that, I would ask on the ESPHOME Discord forum, see what they reckon…

Lots of very active experienced people over there willing to help, with very quick responses.

1 Like

Are you using this procedure?

The documentation mentions that the buzzer must be passive.

I am a little embarrassed to admit that the problem was not the yaml code but the fact that there was a tiny gap on the soldering connection of the pin. Thanks for your willingness to help.

1 Like

Thanks for closing the loop so that others can use your config knowing it works…

I would say that happens to everyone;)

1 Like

Thanks for sharing, your code was working out of the box.

1 Like

Hello, am trying to get tones out of HA myself. Is the “RTTL component” you mentioned connected to an ESPHome device? I am using HA Green at the moment.

Thanks, Jim

Yes, connected to a esp running ESPHome. There is a bit of a shift away from adding hardware/sensors directly to the HA servers GPIOs.

ESPHome opens up a lot.