As a basic electronic component that generates sound, we always encounter Buzzers in life, whether it's in a computer, an alarm clock, or a printer, a scanner, etc. It is widely used, and its usage is extremely simple. In this section, we will learn some relevant knowledge of the buzzer.
1． Programming of the buzzer to get different tones.
2． Get familiar to the programming for Arduino and some relative functions
Buzzer on your MiniQ 2WD Robot
On this robot you’ll find a passive buzzer, which may be a bit difficult to use, but the tone is nice to control, so it is a worthwhile. The buzzer can be used for playing simple music which adds some extra flavor to the robot. Now let’s upload a sample code of buzzer to have a try:
Open the file “buzzer.ino” under the folder “buzzer” :
1. the code
Use the USB cable to connect the robot with the computer, turn on the power of the robot, then click the “upload” button to flash the code into robot. When the uploading is finished, you can hear two different types of tones.
If you feel too simple, then you can upload the “song.ino” under the “song” folder, then you can hear a simple song, much better than the tones. At the same time you can learn from the code about how to control buzzer frequency and maybe you should master the “for” statements.
Define “BUZZER” as pin 16 which attach to buzzer#define BUZZER 16
In initial function we initialize the pin to OUTPUT statevoid setup() //initial function
pinMode(BUZZER,OUTPUT);//initialize the pin to OUTPUT
The codes to play tonesfor(i=0;i<80;i++)
digitalWrite(BUZZER,HIGH);//set pin 16 to 5V(HIGH)
delay(1); // delay 1ms
digitalWrite(BUZZER,LOW);//set pin 16 to 0V(LOW)
delay(1); //delay 1ms
Knowledge about Buzzers
Buzzer is an integrated component which uses the DC power supply, and is widely used in computers, printers, photocopiers, alarms, electronic toys, automotive electronic equipment, telephones, timers and other electronic products as voice devices.
Buzzers can be divided into passive buzzer and active buzzer.
The active buzzer is directly connected to the rated power (new buzzers have labels on the top) and once the power is in, it rings; while passive buzzers are as the same as electromagnetic speakers, need to be connected to the voice source in the audio output circuit.
Note: The "source" here does not mean power, but to oscillation source which means an active buzzer has an oscillation source inside, so as long as the power is on, it works; and a passive buzzer doesn’t have an internal oscillation source, so if use DC power indirectly, it can't ring. We must use 2k - 5KHZ square wave to drive it. Active buzzer is often more expensive than the passive, because the oscillation circuit inside.
The advantages of passive buzzer;
2. The sound frequency can be controlled as acoustic spectrum
3. In some special cases, it can reuse pins with LED
The advantage of active buzzer;
1. Convenient to use
The drive part of the circuit is shown in the figure below, Q1 is a transistor, U1 is the buzzer, R1 is a resistor, and D16 is Arduino digital No.14 pin.
2. Buzzer circuit
This is a visual figure of the circuit diagram above：
3. Buzzer connection diagram
In figure 3, the current from the positive polar pass through the resistance and buzzer, then disconnect on the triode, because normally the triode is cut off, so the buzzer is not working. When the chip controlled the triode on, the triode will allow current to pass, we just need the current pass or not by a frequency, the buzzer will ring. Of course, because the way we setup the connection diagram, the triode can only accept 0V or 5V signal, the current passed the buzzer is equal to the chip to the power of the cathode current multiplied by the magnification of the triode.
After the study of how to use a buzzer, it is not enough if you just let the buzzer sing few times, in the outclass study, you can use a buzzer hint if a button is pressed, the robot’s speed, environmental temperature and humidity condition. And also use it in temperature alarm, over-speed alarm, or the obstacles ahead alarm, etc.
Next class will also learn the use of photoresistance, and then we can make good use of the buzzer.
Since we have studied something about buzzer, let us learn about other device usage and function below:
1. The triode: the full name should be semiconductor triode, also known as triode transistor, is a kind of component whose current is controlled by current, its does the amplification work to change weak signal into radial value larger electrical signals, also used as a non-contact switch.
Since the chip can only provide small current, if this small current is used to make buzzer working, the volume will be small or unable to be heard. In the robot, the solution is to attach the buzzer to a triode, just control the triode switch pin. In this way, the chip could control the triode then indirect control the buzzer.
In physics we call the inhibition of electric current “resistance”, this sounds blurry. The role of resistance in circuit: the famous Ohm's law can be used to control voltage and current in the circuit resistance. In the image above，R1 is an resistance, the function is to limit the current in the circuit. So now that we have already used the triode amplifier current why resistance for limiting current is needed? First we explain why we want to limit the current, we know that buzzer has its own power rating (power needed for normal work), if more than rated power use for a long time, the buzzer will be damaged fast, a simple example is to give the old flashlight bulb double voltage instead the voltage it needed previous, the light bulb will soon be destroyed. Let’s look back above the circuit, if D16 pin gave a high voltage, the transistor Q1 should be conducted, the circuit flow from the positive (VCC) to the negative (GND) terminal, if there is no resistor (R1), the current in the circuit will be very big, because there is nearly zero resistance (the resistance is very small, just buzzer and triode itself), the volume will be very loud (could be considered beyond the rated power). As a result, you can see that R1 played a protective role in the circuit. Part of its function is to control the buzzer volume, control noise in order to not affect other people, after all, we are delighted of controlling buzzers when others perhaps in meditation or exercises on programming, it is also the key point where we should note in the study.