In this project we used the arduino to hook up a motor and make a spinning pinwheel. Because using a motor would require more power than just the power connected through the USB, we also had to have a 9V battery along with the snap to attach it to the board, to give the motor the extra power that it needs to run as hard as it needs to. We hooked up the breadboard to power and ground as per usual, then added a switch to the board which will be used to activate the pinwheel once everythinng is hooked up. The switch is powered and connected to Digital Pin #2, and grounded with a 10kOHM resistor. We place the transistor down, and connect it to power, and ground, while also connecting it towards the diode, Digital Pin #9, and the ground. We hook up our 9V battery to the other side of power and ground and the diode that is also connected to the transistor. With the Circuit set up, we move onto the code. This is a pretty simple code, where we make constants for the switch and a variable to have the different states of the motor for when we press the switch or when it is not pressed. In the setup, we declare the pins for the constants. Then, in the loop, We make the if statement to switch between the switch being pressed and not.
Published March 20, 2023
Comments
Please log in or sign up to comment.