For operate the buzzer

How change the buzzer frequency? How write the code for it? I connect it at analog pin.

analogWrite(‘pin numer’, ‘intensity value’)

Please use the above code.
Intensity value can be between 0 to 255. By changing the intensity value you can change the frequency.
Pin Number will be the analog pin used. If A0 pin is used then its ‘0’.

Thanks for the question fellow IoT developer.
First of all, you do not need to connect the buzzer at the analog pin. The circuit for buzzer is exactly same as that for LED WITHOUT the RESISTOR i.e join the positive(longer) leg of the buzzer to the GPIO pin 0 and the negative(shorter) leg to the GND(Ground) pin. That should make the buzzer buzz on pressing ON and become silent on pressing OFF in the HTML web page.
Now, coming to the frequency variation part, there is JavaScript function analogWrite() which takes two parameters:

  1. Pin No - The GPIO Pin No to which we have connected the positive(longer) leg of the buzzer.
  2. Value - Any value between min and max bounds (here 0-255), different values produce sounds of different frequencies.
    An analog signal is one that can take on any number of values, unlike a digital signal which has only two values: HIGH and LOW. For 10 bit sensors, the range of values is ( 0 to 2^10-1 ) i.e 0-1023. So, in this function the second parameter value corresponds to the voltage applied, ( min/LOW being 0 and max/HIGH being 1023 ) which further reflects in the frequency of the buzzer.
    For example: analogWrite(0, 700);

Here, I am sharing the complete HTML for 3 different frequency of sounds produced on the buzzer :

<html>
    <head>
<script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js"></script>
<script type="text/javascript">setKey('{{ApiKey}}','{{Name}}');</script>
</head>
<body>
<center>
  <button onclick="analogWrite(0, 0);">OFF</button>
  <button onclick="analogWrite(0, 100);">Frequency 1</button>
  <button onclick="analogWrite(0, 200);">Frequency 2</button>
</center>
</body>
</html>

Paste this code in the CODE tab in Configure this product section of your product, Save the changes and view your product.
The final web page should look something like this:


Now you can play with different values of the second parameter of the analogWrite() function and produce different sounds.
Hope this helps !

3 Likes

don’t able to understand what is the problem with my device buzzer is not giving sound

Thanks for the question fellow IoT developer.
If your buzzer is not producing sound, please verify the following points:

  1. Join the positive(longer) leg of the buzzer to the GPIO pin 0 and the negative(shorter) leg to the GND(Ground) pin. DO NOT CONNECT ANY RESISTOR IN THE CIRCUIT.
  2. The code for the product remains same as for LED.
  3. Make sure all connections are tight and both blue and green lights are stable on the Bolt Wifi module.

That should make the buzzer buzz on pressing ON and become silent on pressing OFF in the HTML web page.

giving error while loading upload configuration that
No Hardware configuration exists for this device type

Hi @ganeshaya5151,

If you are controlling tan output device then you don’t need to do the deploy configuration. Directly click on the control device icon.

Thanks for the question, fellow IoT developer.
It is probably due to some wrong configuration in the hardware section of the product. If you are working on the buzzer, this should be the state of your product HARDWARE tab :slight_smile: :

Now, follow the CODE tab as given above. Hope that helps !

Thanks for the question. Please try again with values in the range ( 0-255 ). Hope that helps.

Hey was wondering if y’all could help me out?
I was having the same issue as stated in this thread. I tried the above solution y’all had stated, was still facing issues but then it worked when i connected the positive buzzer terminal to the “0” pin. What i don’t understand is that, isn’t the “0” pin a digital pin? and how is it reading analog values??
Note: the “0” pin, not “A0” pin.

2 Likes

You can change for the range of buzzer from 0 to 255 by taking analogWrite in place of digutalWrite.