ESPHome RTTTL passive buzzer volume control?

Hi all,

I’ve configured the buzzer to beep as I needed but the volume is too low to be useful. How is the volume controlled? Is it fixed with the hardware or parameter to be passed into? I didn’t find any mention on the ESPHome RTTTL page. Thanks!

Disclaimer: I have never use one but maybe frequency. I think 100Hz is the default but maybe go to 1000Hz and then set the sound level. Se example link below

I think that does not work because LEDC can’t be used together with RTTTL at the same time.

Best would be test the possibilities presented before in this thread which were part of a now hidden/deleted post.

Yea not sure… there are 2 links under RTTTL overview that sent me down that path.


esphome:

  name: buzzer

  platform: ESP32

  board: esp32dev

 

# Enable logging

logger:

  level: INFO

# Enable Home Assistant API

api:

  services:

    - service: play_rtttl

      variables:

        song_str: string

      then:

        - rtttl.play:

            rtttl: !lambda 'return song_str;'

 

ota:

  password: "redacted"

 

wifi:

  ssid: "redacted"

  password: "redacted"

  fast_connect: false

  manual_ip:

    static_ip: 192.168.1.58

    gateway: 192.168.1.1

    subnet: 255.255.255.0

    dns1: 8.8.4.4

    dns2: 8.8.8.8

 

  # Enable fallback hotspot (captive portal) in case wifi connection fails

  ap:

    ssid: " Rtttl-Buzzer"

    password: "redacted"

 

captive_portal:

 

output:

  - platform: ledc

    pin: GPIO19

    id: rtttl_out

    inverted: True

 

rtttl:

  output: rtttl_out

 

Show quoted text

This is my code. Rtttl quite loud

Maybe this


output:

  - platform: ledc
    pin: GPIO19
    id: rtttl_out
    inverted: True
    - output.set_level:
        id: rtttl_out
        level: "50%"
1 Like

or this

output:

  - platform: ledc
    pin: GPIO19
    id: rtttl_out
    inverted: True
    - output.ledc.set_frequency:
        id: rtttl_out
        frequency: "1000Hz"
    - output.set_level:
        id: rtttl_out
        level: "50%"

Ha. I used bluetac to soften it. Will try level. Tried it on TASMOTA and it was much softer. Just checking OP is using ESP32 and not ESP8266.

Tried actually both on ESP32 and ESP8266. Same volume. Frequency not changing the volume.

Looks to me nothing was set at all. Maybe just the buzzers are different?

True. Been caught out by dodgy modules before. I assume you have also tried the 5V to power it. If your module allows.

This is a example that may help you

# Configure the output
output:
  - platform: ledc
    ######################################################
    # One buzzer leg connected to GPIO12, the other to GND
    ######################################################
    pin: GPIO12
    id: buzzer

# Example usage in an automation
on_press:
    then:
    ######################################################
    # Must be turned on before setting frequency & level
    ######################################################
    - output.turn_on: buzzer
    ######################################################
    # Frequency sets the wave size
    ######################################################
    - output.ledc.set_frequency:
        id: buzzer
        frequency: "1000Hz"  ## maybe try 100Hz
    ######################################################
    # level sets the %age time the PWM is on
    ######################################################
    - output.set_level:
        id: buzzer
        level: "50%"

For esp8266 link below… also see the note regarding TASMOTA in the link

5V just run hotter not louder LOL

Forgot to mention: also tried set_level, not making any difference. Maybe I should try some 85db active buzzers since I just need an alarm and nothing fancy.

@AndreasBVB if the 85db works for you then yea…

just checking that when you used set_level that

on_press:
    then:
    ######################################################
    # Must be turned on before setting frequency & level
    ######################################################
    - output.turn_on: buzzer

Yes tried setting level before and after turning on. No difference.
The 85db active buzzer worked well. I used GPIO ON/OFF with delays to create beeps.

Changing the level in the yaml config is not working as the level is set in code before playing the note:

    ESP_LOGVV(TAG, "playing note: %d for %dms", note, note_duration_);
    output_->update_frequency(freq);
    output_->set_level(0.5);
  } else {
    ESP_LOGVV(TAG, "waiting: %dms", note_duration_);
    output_->set_level(0.0);
  }

This can be refactored to be configurable from the yaml config, but for now I edited /esphome/esphome/components/rtttl/rtttl.cpp and changed output_->set_level(0.5) into output_->set_level(0.003) as this made the volume acceptable for me.

I did a rude experiment; using a resistor as a volume control. Putting it this way (GPIO) → (Buzzer terminal 1), (Buzzer terminal 2) → (10kOhm resistor) → (GND) would significantly reduce the volume. Putting less resistance, e.g. 1kOhm would reduce it somewhat but not as much as 10kOhm. Leaving the resistor out completely (essentially 0 Ohms) to GND would give “max” volume.

That leads me to believe that the proper way to do volume control is to adjust the current. Within specs of course.

Given that the volume you get when connecting directly to the GPIO and GND with no current-limiting resistor, i guess the maximum-ish of 15-20mA you get from the GPIO, simply is not enough for you. Then connect the GPIO to a transistor and give the buzzer more amps (but don’t forget to add your own current-limiting resistor, taking e.g. the full amps of your probably-usb-5V-1A-supply is several orders of magnitude more than that from the GPIO).

Giving 3.3V 20mA would be 0.066W.
Giving 5V 1A would be 5W. 100-ish times more.

Be careful or you’ll fry the buzzer :wink:

I’ve been experimenting with resisters too and found 56 ohms (@3.3v) is a good value for my particular buzzer to reduce the noise from ridiculous ear splitting, to just right. As a bonus, the unit doesn’t heat up as much too.

1 Like

Use a resistor! Obvious, I should have thought of that. If I have to tamper with my setup I’ll put in a variable resistor. Well, I bought some and haven’t had to use them yet. :grin: