Introduction: Passive Buzzer Interrupt
In this tutorial, I will be showing how you can use interrupts to perform actions immediately even if things are happening in the loop function. The buzzer should loop through a scale, and when the button is pressed, it will interrupt the scale and play a C.
Step 1: Add Button
Attach a button to your breadboard. This button will attach to an interrupt pin.
1. Attach a 10k Ohm resistor from the bottom right pin of the button to the ground rail.
2. Attach a wire from the top right pin of the button to pin 2 on the Arduino.
3. Attach a wire from the top left pin of the button to the power rail
4. Attach a wire from the power rail to the 5V pin on the Arduino.
5. Attach a wire from the ground rail to the Ground pin on the Arduino.
Step 2: Passive Buzzer
Attach the passive buzzer to the Arduino and breadboard.
1. Use a male to female cable to connect the positive side of the passive buzzer to the power rail.
2. Use a male to female cable to connect the negative side of the passive buzzer to pin 8 on the Arduino.
Step 3: Run the Code
Run the code in the file that is provided with this step. Once the code is running, the speaker should play through a scale continuously. When the button is pressed, it will interrupt the scale and play a C on the buzzer. This shows how an action can be performed in the middle of a loop. Note that you must include the pitches.h library.