Introduction: Arduino Pocket Slot Machine
I’ll be honest up front and say that this project never would have happened except that I’m sheltering in place during the coronavirus outbreak, I happened to see that Instructables is running an “LED Strip” contest, and I have some LED strips in a box that have gone unused for years. I feel much better getting that off of my chest. What I ended up building is sort of a pocket version of the slot machine I built for my grandkids in an earlier Instructable. This one doesn’t have a slot for coins or a trap door for payouts but it does have flashing lights and sound effects. I’ll see what the kids think whenever we get out of exile.
Step 1: LED Strips
Most of the time these strips are used as decorative lighting but I wanted to figure out something to build where I could just use some small pieces. Some of the strips are sealed for waterproofing but I also have some that are easy to snip into pieces. As you can see in the picture, they even show you where to cut. Soldering wires to the copper tabs is easy but make sure you use a relatively low heat soldering iron and don’t leave it on the strip too long because the whole thing is basically plastic. The strips I have mount six LEDs in one section and nine LEDs in the next section. These sections alternate to make up the length of the strip.
Step 2: Hardware
The schematics are shown above. The first one details the Arduino connections. As I’ve done previously, I developed the software on an Arduino Nano and then programmed a standalone ATMega328 chip for the final assembly. That helps reduce both the size and the current consumption for this battery operated project. The switch can be any momentary contact, normally open type. The buzzer is a standard piezo type that runs on voltages as low as 1.5 volts.
The second schematic details the connections to the LED strips. As shown, the typical strip has the power source run through a current limiting resistor and then the LEDs are wired in series. I used the sections with six LEDs so they would fit my project box. Of the six LEDs, two are red, two are green, and two are blue. The strips have an adhesive backing so it was easy to stick them to a breadboard. I replaced the normal black cover of the project box with a piece of 1/8-inch white Plexiglas. The LEDs are bright enough to shine through.
The LED strips normally run on 12 volts, but mine work fine on 9 volts so I chose that in order to reduce current consumption. Because the voltage is higher than the Arduino likes to see on its pins, I had to put transistor drivers in place. I have a bunch of cheap 2N3904 transistors so I used those but any small signal NPN type should work. I used 7.5 k-ohm resistors on the base but that value is not critical. You can use lower resistance but remember that it will increase current consumption.
The power for this project comes from a standard 18650 3.7 volt lithium battery. Like previous projects, I connected it to a small charger board so I can use a USB phone cable to recharge the battery. The output of the charger board goes through an on/off switch to two different places. One connection is to the ATMega328 which runs fine at the lower voltage. The other connection is to a DC-to-DC boost board that I have also used in previous projects. Usually I boost the voltage to 5 volts and then run everything off of that. This time, however, I boosted it to 9 volts specifically for the LED strips.
Step 3: Software
The software is pretty simple. The main routine just loops continuously until the “Start” switch is pressed. While the main routine is looping, it is incrementing the variable “Random”. It will simply overflow back to zero the loop after it hits 255. When the “Spin” routine is called it uses the modulus 27 value in “Random” to index into a lookup table of which LEDs to light on each strip. The lookup table has 27 total entries with three of them being matching colors. That sets the odds of winning at 1 in 9. The “Spin” routine runs a loop to flash different combinations of LEDs from the table and then finally settles on one. As in the original Slot Machine software, the “Clickit” routine simulates the sound of the wheels turning. If all the colors match, then the “Winner” routine is called. The “Winner” routine momentarily lights all of the LEDs on a strip and then each strip is turned on/off in sequence. The buzzer also emits an on/off tone during this time.
Attachments
Step 4: Video
The video doesn’t quite do the game justice because the LEDs look washed out and the phone didn’t pick up the audio. It does, however, provide a basic look at the operation of the game.