In my project i want to be able to use a passive buzzer using the digitalWrite command. However im getting a little confused how i can actually control the buzzer how i want it. I simply just want the buzzer to beep on and off with around a half a second delay on it. i have created one small program that does this however it isnt the best. So if anyone has any advice or pointers to where to go next it would be appreciated
Here is the code:
for(int i = 0; i <200; i++)
A delay of 1 millisecond. Why ?
What is the purpose of the while loop when the loop() function will do it for you ?
What is the point of the for loop ?
In loop() make buzzPin HIGH, delay() for 500 milliseconds, make buzzPin LOW, delay() for 500 milliseconds,
April 19, 2021, 10:56am
Why not use tone() function?
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
Because it is a passive buzzer with a fixed tone
This does not work on passive buzzers. It will just make a small noise. For a passive buzzer your delay inbetween has to be extremely short for it to work.
The passive buzzer will make a tone for as long as it is powered and that can be as long or short a period as you want
For the Passive buzzer to work it needs a very short delay. I understand your confusion, because i was in the same situation a few days ago.
This code below, will compile and run. However, it will just create a small noise that sounds like a tick from a clock every second.
For a passive buzzer to work, the delay needs to be very low. I usually use microseconds because it creates a better tone for the buzzer.
The code above will constantly create a sound without stopping.
For a passive buzzer to create a sound, you will have to send a rapid series of on and off pulses for it to generate a tone. This is because a passive buzzer does not have a built in Oscillator.
I have confused passive and active buzzers in my replies and you are quite right in saying that a passive buzzer needs a series of short HIGH/LOW in order to make a sensible noise
August 17, 2021, 11:17am
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.