Changing frequency for a buzzer

If I want to change sound of a buzzer using analogWrite pin. What will be the code

Syntax:

analogWrite('A0','a')

The range of the value of a is 0 to 255 and the frequency of buzzer will change with different values of a
For eg:- the sound with value 100 will be different for sound with value 200

analogWrite('A0','100')
analogWrite('A0','200')
6 Likes

And what will be the hardware connection for this code? is it same or we need a change? Please help, it would be appreciated.

Hi @choudharyaakash066 ,
The connection to be made with the buzzer, is the same is that made with the led, but keep in mind that the Resistor will not be used in case of buzzer.
Below is the hardware connection picture.
In it, The positive terminal of the buzzer is connected to the 0 pin of the Bolt Module and the negative terminal is connected to the ground pin.
Note :1: Red jumper wire is connected as -> 0 (on bolt module) with Positive terminal of Buzzer.
2: Orange jumper wire is connected as -> GND (on bolt module) with Negative terminal of Buzzer.
3: Male to Female Jumper wires are used for the connection.

P.S : IF you require the codes, do let me know.
Thank you.

1 Like

Hey @aaryan0827,
Thank you so much for responding. Yes, please do share the code as I will get the idea for placing the analogWrite function. Previously, I made my project by connecting
Positive pin of the buzzer to 0 (on bolt module).
And Negative pin to the GND (on bolt module).
All the connections were made using male to female jumper wires.

Once again, Thanks for your help.

@choudharyaakash066,
Sorry, in a hurry i made a mistake in the connection the digital pin 0 will be used.
i have made the correction and uploaded the correct circuit diagram. pls refer to it.
and here is the code, to be written in the product code section.

< html >
    < head >
        < title >Bolt IoT Platform</ title >
        < script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js" >< /script >
        < script >
        setKey('{API KEY','DEVICE NAME');
        < /script >
    < /head >
    < body >
        < center >
        < button onclick="analogWrite(0, '255');">ON< /button >
        < button onclick="analogWrite(0, '0');">OFF< /button >
        < /center >
    < /body >
< /html >

Note: the Buzzer sound is not very high,butyouvan regulate it by giving different values, instead of 255.
Remove the Space given within the angular brackets “<>”

3 Likes

Hey @aaryan0827,
It worked. Thank you so very much for responding.

1 Like

@choudharyaakash066, your welcome.

2 Likes