Wiring Diagram and How it Works - abner722/Final-Project GitHub Wiki
##The wiring diagram:
How it works
Input: pin 2, which reads the state of the button and controls the speaker and motor. Output: pin 3 and pin 9, Pin 9 is the output for the speaker and pin 3 is output for the motor.
The button pin is powered by 3.3v and the speaker and motor are powered by 5v. Both power sources come directly from the Arduino UNO so no external power source.
The push button requires a pull down resistor(10k ohms), connected to ground, to continually pull the button state low. The low state allows the digital signal to flow to the speaker and motor allowing them run which simulates the box lid being open. When button state reads high(button pressed) this represents the lid of the box being closed and turns off the motor and speaker.
The speaker requires a 330 ohm resistor to protect the speaker from to much power.
To operate the motor properly you will need a 330 ohm resistor, NPN transistor, and a diode( an LED with work as well). The transistor acts as a switch for turning the motor on and off based on a digital output pin. When the output pin reads high it allows power to flow to the motor until the button state changes to back to HIGH.