Comment on page
You'll need to install a library to make Arduino IDE support the sensor. This library includes helpers for the module and sample code for you to jumpstart your project.
For ESP32 based systems, we're currently supporting Arduino core. Please make sure you've installed the following:
- Arduino IDE.
- ESP32 Hardware libraries for the Arduino IDE.
- Python for the compilation of Arduino projects.
- Drivers for your host device, e.g., USB Virtual Serial Port driver.
Then, copy its contents to your Arduino Libraries folder.
You can find the Arduino Libraries folder inside your Arduino sketch directory. It is generally located inside the My Documents folder.
The library comes with included samples. There is no need to download additional files for the examples.
The hardware, its drivers and the sample code are open source. You can use them under the terms of the MIT license. Please feel free to customize and prototype them for your projects.
Turta_BuzzerButton_Module library is responsible for configuring interrupt and PWM pins, reading button state and generating a frequency for the piezo sounder.
To use the library on Arduino IDE, add the following #include statement to the top of your sketch.
Then, create an instance of the Turta_BuzzerButton_Module class.
Now you're ready to access the library by calling the bb instance.
To initialize the sensor, call the begin method.
This method configures the interrupt and PWM pins.
Returns the button pressed state.
- Bool: Button state
Plays a tone on the buzzer.
void buzzerTone(int frequency, short dutyCycle)
- Int: frequency
- Short dutyCycle
Stops the tone.
Plays a tone on the buzzer for a duration.
void buzzerTonePeriod(int frequency, short dutyCycle, int durationMs)
- Int: frequency
- Short: dutyCycle
- Int: durationMs
You can open the example from Arduino IDE > File > Examples > Examples from Custom Libraries > Turta Buzzer Button Module. There is one example of this sensor.
If you're experiencing difficulties while working with your device, please try the following steps.
Problem: You're pressing the button, but the application does not recognize it. Cause: There are two press levels of the button. You probably stop pushing to it after the first level. Solution: Please push the button stronger.
Problem: The buzzer does not produce sound or produces incorrect tones. Cause: The PWM pin drives the buzzer uses PWM channel 15. You probably use this channel with another component. Solution: Please do not assign PWM channel 15 to any pin.