Introduction: Arduino Pinball Machine
This instructable was created in fulfillment of the project requirement of the Makecourse-Art at the University of South Florida (www.makecourse-art.com)
Step 1: Cut the Wood
Using half inch plywood, cut two 19" by 6" pieces with a one inch slope. The front-most piece is 10" by 5" and the back piece is 10" by 8". Drill 2 holes in the back piece. One in the lower right about .5" diameter, and the other about 2.5" above the bottom on the center about 9/16" diameter. On the same piece, drill 6 1/8" holes on the top but not in the middle. These will where the LED's are placed. Drill a 1" hole on the front piece on the right side. Feed the pinball launcher through the front hole. Put the spring on it and use a small 1" by 1" piece of wood with a .25" hole drilled through it afterward as a stopper. Then place a small rubber tip on the tip of the launcher. The base of the machine is 20" by 10".
Step 2: Paint the Wood
Identify which face of each side is the correct one. Then paint it with whichever color is appropriate or wanted. Paint both sides of the wood so it looks good.
Step 3: Glue and Drill the Front
Place wood glue along the bottom of the front side. Then place it on the front of the base. Use clamps to secure it and pre-drill using an 1/8" bit. While the glue is still wet screw 2x 3/4" long screws into the base to the front side. Leave until dry.
Step 4: Glue and Drill the Sides
Once the front is dry, clamp down one side without gluing it down. Line it up and pre-drill through the front side. Then place glue on the bottom and front of whichever side is done first. Clamp it down again and screw the appropriate screw. After they dry, turn the machine on its top and carefully pre-drill and screw the base to the sides and the front.
Step 5: The Ramp
This step can be done either before or after the right side is glued down. Measure the highest side of the ramp, at most 4.5" above the bottom, and the lowest at 3.5" from the bottom. The higher the slope, the harder it will be to launch the ball. The ramp is 19" by 1 1/4", glue it down and use 2 1/4" x 1/4" x 12" micro-lumber to secure the ramp on the wood, one on top of the ramp and the other on the bottom of it. The divider is 10" by 5" by 1/4", paint it and wait for it to dry. Then glue the divider so the ball doesn't get lost underneath the board.
Step 6: The Under-board
There will be two plastic boards, the board and the under-board. The under-board is placed at a slope, with the top left corner higher than the other corners, at 4 3/4" from the bottom. The bottom right corner is the lowest corner, but it's still higher than the ramp at 3 3/4" from the bottom. Make 4 19" long by 1/2" wide sticks to support the boards. Don't glue the boards to the sticks so that they're easy to install and remove.
Step 7: The Board
The board is the main part of the machine, so extra care and thought has to be put into it. It is 19" by 9 1/2" Use two of the 19" long sticks to support this board. Make sure there is enough space in between the boards for the ball to travel through, however this is only necessary below the farthest hole from the player. There should also be enough space for the ball at the highest point of the board so that it doesn't hit the plexi-glass. Drill six holes into it, these are the scoring holes. Place 3 right above each other, two on the other side and one closest to the player. There will be a wood piece with a curve cut out that will lead the ball to the launcher. The closest hole should be far enough away from the curve so the ball doesn't fall easily into it, but not too far so that it is too close to the other holes. Cut an extra hole wherever you would like to place the rudder.
Step 8: 3-D Printed Parts
The ramp and the cover are both 3-D printed parts. The ramp is 4" by 5", and the cover is 5" by 1 1/2". The cover should have three slots into it, far enough so the ball can come in and fall into the hole. Both were created in Autodesk Maya, but any 3-D modeling software can be used. Paint these in the dominating color. The wiper is 2 7/8'' long, 1/2'' tall, 5/8'' wide at the base and 3/8'' wide at the tip. It has a slight raised edge on top just for looks. On the bottom is a hole made to fit the attachment for the servo, but it could also be made to go onto the servo directly. It was painted to match the other parts, with a black edge for accent.
Step 9: The Holes
Using either a laser cutter or a drill, make seven 3/4" holes in to the board. Using these holes, mark on the under-board where the sensors will be placed. Make sure that these holes are 1/8" and that they are closer to the player, as the ball will fall in that direction. The rotor hole should be 1/4" so that the cable can be fed through easily. Place a small wooden stick below the bottom hole to lead the ball back to the launcher. Also place smaller sticks below the sensors that are above each other at an angle, so that the ball doesn't activate them all when it drops.
Step 10: Circuit Schematic
Setting up the control system is probably the most difficult part of this project. There are a lot of wires involved. From the included schematic, you can see the main components are two Arduinos, two breadboards, a Schmitt trigger, six photocells, six LEDs, an LCD screen, and a servo. The photocells act as sensors, since they change their resistance with the amount of light they detect. So when the ball goes into one of the holes, that photocell will change it's resistance and the voltage sent to the Arduino will change. This is how the score is kept for the game.
Start by placing the Schmitt trigger on the breadboard. This chip turns a variable signal into either a high or low signal, so it is good for using with the photocells. Then set up the voltage dividers for the six photocells. They go from the power rail, to the photocell, through two 1 kiloOhm resistors (equivalent 2 kiloOhm resistance), and then to ground. Do this for each photocell. Then make a connection from between the photocell and resistor to the input ports on the Schmitt trigger. Then connect wires from the output ports to pins 8-13 on the first Arduino.
Next, set up the LEDs. For this project, there are two green, two yellow, and two red LEDs, even though the schematic was only able to show red. The pairs of LEDs are connected in series, so only use pins 2-4 on the first Arduino. In series with each pair of LEDs is a 220 Ohm resistor.
Also connect the LCD screen to the first Arduino, making sure to have the correct connections for "SDA" and "SCL". Then connect the servo to pin 9 on the second Arduino. A second Arduino was used because incorporating the servo movement into the first Arduino's program would have slowed down the loop too much. Make sure each Arduino is providing power to one of the breadboards. Now the control system is set up.
Step 11: The Code
The code for the first Arduino is the main one used for gameplay. It starts out by including the library for the LCD screen, which can be downloaded online. Then it defines all the pins that are used for the photocells and LEDs. In the setup loop, the LCD screen is initialized and the beginning of the game is printed to the screen. Also the modes for all the pins are established, and the LEDs are written to LOW to ensure they are off to begin with.
Just before the main loop, a variable "i" is defined that is used to keep score. Inside the main loop, there are a series of "if" statements. The first six "if" statements are checking the photocells. If the voltage from one of the photocells is HIGH, then add the appropriate number of points to the score and flash the appropriate LEDs. This part can be customized, as point values are able to be changed.
The seventh "if" statement is checking if the maximum score has been reached, which again can be changed. For this example it was set to 500. So if the score is greater than or equal to 500, then the words "You Win!" are displayed on the screen and all the LEDs flash for about 3 seconds. After that it resets the game and prints the beginning to the screen again.
At the end of the main loop after all the if statements is where the game displays the current score on the screen when nothing else is going on.
The code for the second Arduino is simple. It first includes the servo library. Then it sets up the servo and writes it to a neutral 90 degree position. In the main loop, it simply alternates the servo between 160 degrees and 30 degrees, with 1 second delays in between. This is what creates the constant wiper movement.
Both Arduino codes have been included.
Step 12: Wiring
Carefully feed the sensor from above, and connect them to female to female connectors that are wired to the breadboard. They should be above the board so that they don't activate by themselves. If needed, put a small amount of hot glue on the hole so that the sensors don't move. Feed the wire for the servo and glue it to the board so that it also doesn't move. Move the LED's through the middle hole in the back side, and the Arduino USB connectors through the bottom hole.
Step 13: Sensor Fixes
The sensors will be the most difficult part of building this. They are sensitive and once the board comes in, they will activate all the time. In order to fix this problem, we placed several lights underneath the board, directly above where the sensors are placed. Make sure that they are not too bright as they might keep the sensors from activating, but if for some reason one is not enough, put two close to each other on whichever sensor isn't working.
Step 14: Finishing the Machine
Once all the wiring and parts are in place, the plexi-glass can be slotted in. Make sure that it is clean on both sides and handle it with gloves on. Once it is secure, the back side is all that's left. Don't glue it to the other sides, so that it is easily removable. This way, down the line if there are faulty parts, they are easily replaced or fixed. Plug the arduinos into a computer and run the program. The pinball machine should be up and running.
We have a be nice policy.
Please be positive and constructive.