Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
61 views2 pages

Buzzer With An Arduino Uno

The document provides instructions for wiring and coding both active and passive buzzers with an Arduino Uno. It includes specific pin connections, sample code for each type of buzzer, and steps for uploading the code using the Arduino IDE. After uploading, the active buzzer will beep every second, while the passive buzzer will play a tone for one second followed by a pause.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views2 pages

Buzzer With An Arduino Uno

The document provides instructions for wiring and coding both active and passive buzzers with an Arduino Uno. It includes specific pin connections, sample code for each type of buzzer, and steps for uploading the code using the Arduino IDE. After uploading, the active buzzer will beep every second, while the passive buzzer will play a tone for one second followed by a pause.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

buzzer with an Arduino Uno

Wiring the Buzzer

1. Active Buzzer: An active buzzer has a built-in oscillator, so it can generate sound
when power is applied.
o Connect the positive terminal (long pin) of the active buzzer to digital pin 8
on the Arduino.
o Connect the negative terminal (short pin) to the GND (ground) pin on the
Arduino.
2. Passive Buzzer: A passive buzzer requires a PWM signal to generate sound.
o Connect one pin to digital pin 9 on the Arduino.
o Connect the other pin to GND.

Code for Active Buzzer:


// Define pin for the buzzer
const int buzzerPin = 8; // Connect to the active buzzer

void setup() {
pinMode(buzzerPin, OUTPUT); // Set the buzzer pin as an output
}

void loop() {
digitalWrite(buzzerPin, HIGH); // Turn the buzzer on
delay(1000); // Wait for 1 second
digitalWrite(buzzerPin, LOW); // Turn the buzzer off
delay(1000); // Wait for 1 second
}
Code for Passive Buzzer:
// Define pin for the buzzer
const int buzzerPin = 9; // Connect to the passive buzzer

void setup() {
pinMode(buzzerPin, OUTPUT); // Set the buzzer pin as an output
}
void loop() {
// Play a tone
tone(buzzerPin, 1000); // Play 1kHz tone
delay(1000); // Wait for 1 second
noTone(buzzerPin); // Stop the tone
delay(1000); // Wait for 1 second
}

Uploading the Code

1. Open the Arduino IDE on your computer.


2. Copy and paste the desired code (for active or passive buzzer) into the IDE.
3. Select the correct board and port from the Tools menu.
4. Click the Upload button (right arrow icon) to upload the code to the Arduino.

Testing

 Once the code is uploaded, the buzzer should start sounding according to the code you
uploaded:
o The active buzzer will beep on and off every second.
o The passive buzzer will play a tone for one second, then pause for one second.

You might also like