Overview
In this lesson, we will learn how to program the Arduino to make an active buzzer beep.
Components
- 1 * Arduino UNO
- 1 * USB cable
- 1 * Active buzzer
- 1 * 1 kΩ Resistor
- 1 * NPN Transistor (S8050)
- 1 * Breadboard
- Several jumper wires
Principle
A buzzer or beeper is an audio signaling device. As a type of electronic buzzer with an integrated structure, which uses DC power supply, buzzers are widely used in computers, printers, photocopiers, alarms, electronic toys, automotive electronic equipments, telephones, timers and other electronic products for voice devices. Buzzers can be categorized as active and passive buzzers (See the following pictures).
Place the pins of the buzzer face up, and then you can see the two types of buzzer are different - the buzzer with a green circuit board onside is a passive one.
In this lesson, the buzzer we used is active buzzer. Active buzzers will sound as long as they are powered. We can program to make the Arduino output alternating high and low levels to make the buzzer beep.
A slightly larger current is needed to make a buzzer beep. However, the output current of Arduino GPIO is too low, so we need a transistor to help.
The main function of a transistor is to enlarge the voltage or current. It can also be used to control the circuit conduction or deadline. Transistors can be divided into two kinds: NPN, like the S8050 we provided; PNP, like the S8550 provided. The transistor we use is as shown below:
There are two kinds of driving circuit for buzzer:
Figure 1 Figure 2
Figure 1: Set the Arduino GPIO as a high level. Then the transistor S8050 will conduct, and the buzzer will make sounds. Set the GPIO as low, the transistor S8050 will be de-energized, and the buzzer will stop beeping.
Figure 2: Set the Arduino GPIO as low level. The transistor S8550 will be energized and the buzzer will beep. Set the GPIO as a high, and the transistor S8550 will be de-energized, and the buzzer beeping will stop.
Procedures
Step 1. Build the circuit
2. Program
/*********************************************************** File name: 02_activeBuzzer.ino Description: Arduino uno Continuous beeps control buzzer. Website: www.adeept.com E-mail: support@adeept.com Author: Tom Date: 2015/05/02 ***********************************************************/ int buzzerPin=8; //definition digital 8 pins as pin to control the buzzer void setup() { pinMode(buzzerPin,OUTPUT); //Set digital 8 port mode, the OUTPUT for the output } void loop() { digitalWrite(buzzerPin,HIGH); //Set PIN 8 feet as HIGH = 5 v delay(2000); //Set the delay time,2000ms digitalWrite(buzzerPin,LOW); //Set PIN 8 feet for LOW = 0 v delay(2000); //Set the delay time,2000ms }
3. Compile the program and upload to Arduino UNO board
Now, you can hear the buzzer beeping.
Summary
After learning this lesson, you can master the basic principle of the buzzer and transistor. Also you've learned how to program the Arduino and then control the buzzer. Now you can use what you've learned in this lesson to make some interesting things!