Arduino Lab 9: Call Button
Background: For patients who are immobile, there is oftentimes a call button to notify the caretaker that they need something. Using a button, a speaker, and some preprogrammed songs, we are going to recreate this functionality.
Goal: Create a call button that plays a song when pressed.
Circuit Setup
- Materials
- 1x Arduino
- 1x Pushbutton switch
- 1x Piezoelectric speaker (buzzer with bare contacts and circuit board material on the underside, looks different than below).
- Setup
- Connect pushbutton so that is connects pin 2 to GND when pressed.
- Connect “+” side of speaker to digital pin 8.
- Connect other side of speaker to GND.
Lab Instructions
Note: There are 4 different files in the starter code. Make sure you download them all.
- I have given you a significant amount of the starting code that handles all the song selection and playing: https://create.arduino.cc/editor/mjdargen_ncsu/231b565e-f8a4-4b80-89dd-4de619c774da/preview.
- If using Arduino Create, go to the link above and click copy to my sketchbook.
- If using Arduino IDE, open the link and copy all 4 files into your program: call_button_starter.ino, pitches.h, songs.h, songs.ino.
- The starting program as is will randomly select a song and staying playing a song over and over again.
- You need to modify the code to only do this when the pushbutton is pressed. You will need to do the following:
- Configure pin 2 as INPUT_PULLUP to read the switch.
- Add an if statement around the two statements in the loop() function that checks to see if the switch is pressed.