Arduino Controlled Pinball Machine
Since I always wanted a pinball machine I soon realized that fully working pinball machines in good condition are rather expensive and require quite a bit of maintenance and knowledge, especially the old electromechanical (EM) machines. Searching for a way to build a pinball machine myself, I stumbled upon various homemade pinball projects utilizing Arduinos as the “brain” behind the pinball mechanic. I found Bob Blomquists project page and videos especially helpful in starting my own project. My first idea was to build everything myself, however I soon realized that buying pinball parts is also quite expensive. I found an old pinball playfield with most parts still intact on EBAY and decided to use this as a foundation to build my own machine. If you’re rather interested in building your own machine from the ground up, just buy only the parts you need and use a blank piece of wood instead of the used playfield, the process is exactly the same. The advantage of an existing playfield is that you don’t have to think about the layout and placement of parts, the downside of course is that you are restricted by the original design. The machine is controlled by a single Arduino Mega 2560. If you want to see the machine in action, go to this link, or watch here:
As you can see from the picture, I build a simple wooden case (using MDF) fitting the playfield.
You have to decide what your machine should look like and consider your options beforehand. I opted against building a “standard” machine with legs and a “back” (used to keep scores) since I wanted to be able to pick up the machine and move it or store it with minimal space requirements. Therefore I build the case with a bottom that opens to the side, with this you can place the machine on any surface (for example a table), play it and then store it upright, taking up very little space. For maintenance, the side opening panel allows easy access to all the parts.
The bottom panel houses the power supplies, the Arduino and the power distribution is mounted on the side panels. The playfield rests on brackets mounted on the side panels and is secured with screws. The case and playfield surface is built at a right angle, to play you angle the playfield elevating the back end of the case. This will be done by legs in the future, currently I simply use a solid piece of wood to get the playfield to a 7 degree angle. I didn’t yet install a lid, this will be a simple piece of Plexiglas mounted on the surface of the case with some hinges.
Pinball mechanisms and components
A pinball game usually consists of a core set of components and mechanisms which you need to address and include in your project.
Sensors can be of varying types depending on the specific part, but generally it’s a kind of switch which sends a signal once it is triggered by the ball. Most common are leaf switches, rollover switches, targets and micro switches. These will be the main source of inputs coming into our Arduino.
Lights are an important part, giving the playfield “life” and giving a direct feedback about objectives, points, bonuses and so on. I used simple LEDs, soldered them to an appropriate resistor and mounted them directly under the playfield. This is a very cheap (10 cents per mounted LED) and very lazy way of doing this, using bulbs and sockets is of course a better method, especially for maintenance purposes. This will be the main source of outputs coming out of our Arduino.
Flippers, Pop Bumpers and Slingshots
These are the core components of most pinball machines. If you buy them (or strip them of an old playfield) you are left wondering what to do with them at first, clear instructions are rarely found.
This site is a necessity for everybody thinking about building a pinball machine, all the basics are explained and you can find helpful pictures. The heart of every one of these components is a solenoid, which is simply a tightly wound coil of wire. Once powered, it produces a magnetic field. This is used to propel a “plunger”, s rod of metal into the coil, powering the different, mechanical actions.
Wiring the Flippers is best demonstrated using this picture from above mentioned site.
I used the “old” style of coils and wiring, meaning I use coils with 3 contacts. The principle behind flipper coils is that they have to be very strong for the first “kick”, propelling the ball. However, if you continue to hold down the flipper button the coil would simply melt due to the high amperage flowing through it for a prolonged time. “Old” coils use an End-of-Stroke (EOS) switch which mechanically opens once the flipper has reached its maximum elevation. This “forces” the current to go through a second set of wiring with a much higher resistance, resulting in a lower heat production and the survival of the coil for a prolonged amount of time. Coils from modern machines are regulated via the CPU, power send to the coil is reduced after a certain amount of time. This could probably be done with an Arduino, however, I went for the mechanical solution, the upside being that it’s simple and reliable. In addition, “old” coils from the EM era used low voltages of 24V, making them easier to handle in general. The flippers are the only part of the machine not linked in any way to the Arduino, they are triggered (or short circuited) by a simply pair of micro switches and push buttons.
Slingshots generally consist of 2 sensors (leaf switches) and a coil powering a “kicker” which propels the ball away one it triggers the switches. I found a nice blogpost about slingshots and solenoids on this site. Again, like in the case of the flippers, you have to decide how to trigger them. On old EM machines, these coils were linked directly to the power supply, making them very responsive and fast. The switches therefore don’t send a signal but simply short circuit the coil. Since we still need a signal, the triggering of the coil mechanically activates a leaf switch mounted underneath it, this is our signal for the Arduino.
Bumpers give the ball a good kick once it makes contact. This is made possible by the white disc seen around most pop bumpers. When a ball rolls onto the white disk it pushes a shaft down and triggers a leaf switch.
I choose to trigger them with the Arduino for 2 reasons. If you go for a mechanical solution (like with the slingshots) you will only get a weak “kick” out of your pop bumpers since the coils are activated for a very short amount of time before the ball is propelled out again. Originally this was solved by adding a second set of switches which were triggered when the coil had been fully energized. Only then power to the coil was cut, allowing for a good, powered kick. Modern machines are triggered by the CPU, the switch sends a signal to the CPU (our Arduino) which in turn energizes the coil for the right amount of time. You probably know that 24V and the Arduino do not work well together; therefore we have to use MOSFETS (metal–oxide–semiconductor field-effect transistor) as our mediators. I used IRL540N MOSFETS, they are logical level MOSFETS (meaning you can reliably trigger them with the 5V signal from the Arduino) and can handle the currents and amperage involved. For the wiring I used this basic layout, please do some research on the topic beforehand though, 24V will kill your Arduino quickly if your wiring is incorrect.
This however allows for a precise timing (and scoring) of the pop bumpers. Since we have a very quick action here, delays are not practical (and shouldn’t be used anyway…more in the code section). I used millis() to time the start and end of the bumper activation, try and error left me with 40 milliseconds activation as a good value.
I used a generic I2C display. This is pretty standard and can be customized as to your needs, I use it to display the score, high score and number of balls played.
I used a MP3 shield board based on the VS1053B for the sound. This was in hindsight a bad choice. This board is cheap and relatively easy to use, however, the processing time and resulting delay is too high for some pinball actions. This is probably not noticeable in most applications, however the pop bumpers with their 40 milliseconds timing are thrown of just enough to disrupt gameplay. Sound is therefore restricted to “slow” actions like rollover switches, targets and general music.
Arduino and coding
As you can see from the picture, including the mp3 shield and the display, I used up every one of the available pins from an Arduino Mega 2560. To go further, I would have needed to use shift registers, this would have been cleaner, but I’m no expert and the project was complicated enough already, next time perhaps when I need even more pins….
The Arduino is the brain behind everything, it determines when switches are activated, it turns lights on or off accordingly, it keeps track of the scoring, it displays the score and ball number, it supplies the coils with energy and keeps track of the game logic.
I tried to keep the code simple and clean (and failed in most cases…) using separate functions (void) for nearly everything. Besides the simple in/out relations between signals (if target is hit, turn of light A, turn on light B, set condition X to 1, etc..) there is some game logic involved.
I based this on the original game (AZTEC pinball), for example if you manage to spell out the word AZTEC you activate the bonus ball feature, meaning if you manage to hit the centre target you are awarded an extra ball. This also included the activation of double bonus features, extra points, and so on. You are free to do what you like, since we are not restricted by the old EM limitations of witches and relays, you can make the game logic as complicated or as simple as you like.
If you are interested in building you own machine, I’m sure you will find bits and pieces of my code helpful, especially the pop bumper timing was a lot of try and error and might come in handy for your own projects.
The machine also includes a very basic “Attract” mode, meaning it does something while you are not playing. I went for a simple lightshow using the LEDs controlled by the Arduino. If you take a look at this section of the code, beware! This was towards the end of the project and is a disgrace, using delays, no arrays and is basically a wall of copied text and commands. You can start playing by pushing the start button at the front, this is possible by using the Interrupt feature of the Arduino.
If you want to see the attract mode in action, go to this link, or watch here:
To power the machine, I use 3 different voltages. A 24 volt power supply powers the coils, a 12V power supply powers the ambient lighting and a 5V power supply powers the Arduino.
I can’t tell how much wire went into this machine, let’s just say a lot! Since this was my first project of this magnitude, my wiring is a mess and should serve as a deterrent. I have no colour coding (didn’t have enough wire of the respective colour and was too impatient to wait for more) and I didn’t construct a wiring harness….lazy. On the upside I can at least say that there are no loose wires, I tied everything down and I used crimp terminals for all the connections. This allows me to quickly disconnect and exchange parts and component without additional soldering. Despite claims to the contrary, I never had a problem with crimp terminals coming loose despite the “action” of the pinball machine.
I hope this mess encourages you to do better, I know I will with my next projects.
I hope I could be of some help if you are interested in a similar project. It was a lot of work, and you will undoubtedly discover obstacles and challenges on the way. However, it was (and is) a lot of fun and is definitely a worthwhile project if you like pinball.