Go Down

Topic: Volume Control (for buzzer) (Read 26600 times) previous topic - next topic

iwanna4get

So I read somewhere that you can control a buzzer sounds with a pot (so I'm guessing you can control it with the resistance).
Here: http://www.learningaboutelectronics.com/Articles/How-to-vary-the-volume-of-a-buzzer

So I had this idea, I am suppose to make an up/down binary counter application and I'm thinking about making a volume control application with a buzzer and said counter.

The idea is quite simple I have 15 levels max for the volume. I'm planning on using the code in arduino named fading.

This one
Code: [Select]

/*
Fading

This example shows how to fade an LED using the analogWrite() function.

The circuit:
* LED attached from digital pin 9 to ground.

Created 1 Nov 2008
By David A. Mellis
modified 30 Aug 2011
By Tom Igoe

http://arduino.cc/en/Tutorial/Fading

This example code is in the public domain.

*/


int ledPin = 9;    // LED connected to digital pin 9

void setup()  {
  // nothing happens in setup
}

void loop()  {
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(30);                           
  }

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(30);                           
  }
}



except i change the LED with a buzzer will it still work? (I wonder)
as for the application of the up/down counter. I have my basic idea for it and I need to know if this code will work(If i exchange the LED with a buzzer).(I have no buzzer in hand right now and I will be able to acquire 1 next week but this experiment is due next week xD).

Will it work?

JimboZA

Why not try Tone instead of Fading? Maybe you can canibalise a small speaker out of an old radio or something if you have no buzzer.
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

iwanna4get

#2
Mar 07, 2013, 05:15 pm Last Edit: Mar 07, 2013, 06:13 pm by iwanna4get Reason: 1

Why not try Tone instead of Fading? Maybe you can canibalise a small speaker out of an old radio or something if you have no buzzer.


This seems to change the tone of the sounds, and not change the volume? as for cannibalizing a small speaker, I would very much love to do that, so I will :D



Thank you for the idea, I got it working :D and now all i have to do is make my up/down counter and hook em up :D and I'm done

Erdin

The toneAC library can adjust the volume, http://playground.arduino.cc/Code/ToneAC
But you have to keep in mind that it is a PWM volume control. So the base frequency stays the same, but the higher frequency parts change if the volume is changed.
There are many other sound libraries, see the Playground 'sound' section, http://playground.arduino.cc//Main/InterfacingWithHardware#Audio

fr_pal

Why not try Tone instead of Fading? Maybe you can canibalise a small speaker out of an old radio or something if you have no buzzer.
you can totally do this, i recently salvaged a couple of 6 ohm speakers from an old computer stereo and both an electret microphone and a speaker from an old tuve pone, they work great for tone commands

DVDdoug

Quote
you can totally do this, i recently salvaged a couple of 6 ohm speakers from an old computer stereo and both an electret microphone and a speaker from an old tuve pone, they work great for tone commands
Do NOT directly connect a 4-8 Ohm speaker!    Or, do so "at your own risk".   

The "absolute maximum" current from the ATmega chip is 40mA.    From Ohm's Law we can calculate the minimum resistance/impedance as 125 Ohms (5V / 0.040).   If you connect a speaker you should put a resistor in series (which will substantially reduce the volume) or you can use a transistor or MOSFET driver to boost the current (and optionally boost the voltage).

Go Up