[vc_row][vc_column width=”1/1″][vc_column_text]The components used in this experiment are shown below:
The components are one buzzer,two jumper wires, and one breadboard.[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Schematics” tab_id=”1392608409-1-66″][vc_column_text]
The long pin of the buzzer is positive,and the shorter one is negative. This is also marked on the bottom of the buzzer.[/vc_column_text][/vc_tab][vc_tab title=”Wiring Diagram” tab_id=”1392608409-2-89″][vc_column_text]
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.[/vc_column_text][/vc_tab][vc_tab title=”Arduino code” tab_id=”1392609293181-2-9″][vc_column_text]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
}
}
}[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.