Buzzer:
A buzzer or beeper is an audio signalling device,which may be mechanical, electromechanical, or piezoelectric (piezo for short range). Buzzers are used as alarm devices, timers, and confirmation of user input such as a mouse click or keystroke.Buzzer |
Hardware Required:
- Breadboard
- Buzzer
- 100 ohm resistor
- Arduino
Software Required:
- Arduino UNO
Steps to connect :
Step 1: Connect the buzzer in the breadboardStep 2: Connect 100 ohm resistor across the buzzer, resistor is used to avoid damage to the buzzer
Step 3: Now connect the positive side of buzzer (RED wire) to the digital pin 9 through resistor
Step 4: Connect the negative terminal of buzzer (Black wire) to the ground.
Arduino with Buzzer |
Code:
const int buzzerPin = 9;
void setup()
{
Serial.begin(8600);
pinMode(buzzerPin, OUTPUT);
void loop()
{
tone(buzzerPin,1000);
delay(1000);
noTone(buzzerPin);
delay(1000);
}
Coding Explanation:
const int buzzerPin = 9:
It indicates that buzzer is connected to 9th pin of arduino
pinMode(buzzerPin, OUTPUT):
It informs arduino such that buzzer is made as an output
tone(buzzerPin,1000):
It orders the arduino to tone buzzer pin with 1KHz signal
noTone(buzzerPin):
It orders the arduino not to tone buzzer pin
delay(1000) :
This provides a delay of 1 sec between on and off of buzzer