Introduction: Experiment 2 Experiment With Buzzer

The components are one buzzer,two jumper wires, and one breadboard.

Step 1: Schematics

The long pin of the buzzer is positive,and the shorter one is negative. This is also marked on the bottom of the buzzer.

Step 2: Wiring Diagram

The positive pin of the buzzer is wired to digital IO pin 7 of Arduino, and the negative pin is connected to GND of the Arduino.

Step 3: Arduino Code

Arduino Code:

int buzzer=7;//Configure the control digital IO pin
void setup()
{
pinMode(buzzer,OUTPUT);//Set the mode of the digital IO pin to be
OUTPUT
}
void loop()
{
unsigned char i,j;//Defined a variable
while(1)
{
for(i=0;i<80;i++)//output a sound with a frequency
{
digitalWrite(buzzer,HIGH);//make a sound
delay(1);//delay 1ms
digitalWrite(buzzer,LOW);//silent
delay(1);//delay 1 ms
}
for(i=0;i<100;i++)//Output a sound with another frequency
{
digitalWrite(buzzer,HIGH);//make a sound
delay(2);//delay 2ms
digitalWrite(buzzer,LOW);//silent
delay(2);//delay2ms
}
}
}