Arduino Sound Effect With Game Handle
Introduction: Arduino Sound Effect With Game Handle
This project is for the class ATLS 3300 at CU Boulder.
Push buttons can make buzzers sound.
Five buttons represented the tone C, D, E, F, G.
There are two modes.
The switch determines the mode and LEDs can indicate which mode we are in.
In mode-1, the game handle can determine which buzzer sound.
In mode-2, the game handle can change the frequency of the sound.
Material:
wires
Button * 5
LED * 2
Switch * 1
Buzzer (low-level trigger) * 4
Resistor * 8
Arduino Uno * 1
Step 1: Step 1: Schematic
Step 2: Hardware 1:
Connect the ground and 5v on the breadboard to the Arduino.
Step 3: Hardware 2:
Add 5 buttons to the board.
Connect Them to the 5v power and ground them with resistors.
Parallel them with digital input on the Arduino (using the port without PWM).
I'm using the port 2,4, 7, 12, 13 for the button 1,2,3,4,5.
Step 4: Hardware 3:
Connect buzzer to the board.
VCC to v5, GND to ground, and I/O to the PWM output on the Arduino.
I'm using 3~, 5~, 6~, 9~ on the Arduino for the buzzer 1,2,3,4.
Step 5: Hardware 4:
Add switch to the breadboard.
Power the middle needle with 5v and ground the left needle with a resistor.
Parallel the resistor with input on Arduino.
I'm using port 8 on the Arduino for the switch.
Step 6: Hardware 5:
Add two LEDs to the breadboard.
Ground them with a resistor.
Connect them with outputs on the Arduino.
I'm using ports 10 and 11 for LEDs 1 and 2.
Step 7: Hardware 6:
Connect GND, + 5V, VRx, and VRy to the ground, 5v, A0, and A1 on the Arduino.
Step 8: Step 7: Add Enclosure
Using cardboard making an enclosure for the project.
Step 9: Code 1:
Test the button.
If everything looks good, change the testing code to the reading code.
Step 10: Code 2:
Test the LEDs.
If the LEDs can light up separately, link the Leads to the mode indicator.
Step 11: Code 3:
Link the switch output to the mode.
If it works well and LEDs can change with the switch, nothing needs to change.
Step 12: Code 4:
Test the game handle.
The Serial should change while you are moving the handle.
If everything works well, delete the debug code and leave only the analogRead code.
Step 13: Code 5:
Test and see whether the busser works.
When pressing the button 1 to 4, the corresponding buzzer should make noise.
Step 14: Code 6:
Test and see whether the buzzer can make a sound in specific Hz.
If it works, delete the debug code.
Step 15: Code 7:
Copy and paste everything in loop(), into a helper function called start().
Add the code in start() to define Hz from the button.
Add two helper functions called mode_1() and mode_2().
Relate buzzer input with game handle in mode_1().
Relate Hz to the game handle in mode_2().
Add all the helper functions to the loop().
Step 16: Step 16: Final Code
Change the input of the buzzer to A5 and cut the power supply when the buzzer needs to quiet.
Final code:
int b[] = {2, 4, 7, 12, 13};
int b_rd[] = {0,0,0,0,0};
int s_rd = 0; int led [] = {10,11};
int s = 8; int hdx = A0; int hdy = A1;
int hdx_rd = 0; int hdy_rd = 0;
int buzzer[] = {3,5,6,9}; int hz = 0;
int hz_array[] = {262,294,330,349,392}; int pw = A5;
int mode = 1;
//int debug = 0;
void setup() {
Serial. 769