I wanted to make a physical snake game like the ones I used to play on the old Nokia phones, where the snake goes around eating food and getting longer. I had a look around and saw a number of great instructables about how to make the grid, like this one by https://www.instructables.com/id/Make-Your-Own-10x...
Once I've made the grid, I coded created an Android app to send the movement commands over bluetooth so you can move the snake with just a swipe.
If you like this project, please vote for it in the microcontroller competition (the button on the top right of this page or click here. Thanks!
So without further ado here's what I did.
Step 1: Bill of Materials
So there are two different sides to what you need, the stuff that I actually used and the stuff I'd use if I were to do it again from scratch (I learnt a lot along the way).
- Ardunio Nano (or similar) - I used this one as it's dirt cheap, fantastically easy to program (using the arduino IDE and has all the connections you need for this project)
WS2812B 5050 RGB LED Strip - These are individually addressabe LEDs, each with red, green and blue LEDs allowing you to make (pretty much) any colour you want, and on a strip that can be cut to whatever length you want
HC-05 (or HC-06) Bluetooth UART module - I used one like this. The pins you need for this are just power, ground, Tx and Rx so any that have these 4 pins as a minimum are good to use.
Other: There were a few things that I had lying around but you'll need to buy if you don't already have them
-DC Jack for power
-AC/DC power adapter capable of providing ~2A @ 5V
-Strip board like this
-Resistors (preferably 1k and 2k)
-Wire...So much wire
- A table (or something else you want to embedded the lights into) - I used the super cheap LACK Table from IKEA. Not only is it cheap at only £5, but it's actually made of cardboard honeycomb inside making it very easy to route out.
- Foam board like this
- Plywood - to mount the light strips on
- Opal acrylic - I got mine from The Plastic Man
- Soldering iron
- Stanley knife/scalpel
Step 2: Making the Grid
This was by far the least pleasant part of the whole project. After spending a weekend learning how to use inkscape and created a lovely template to send of for laser cutting (attached below), I cheaped out. Not wanting to spend the ~£50 to get it all professionally cut, I printed out the template, bought some foam board and started cutting.
This was very do-able but fiddly and because it was all done by hand, some of the lines weren't straight meaning when I put it all together, it wasn't square. I fixed this by sticking a few nails in the wood to hold the foam exactly where I wanted it and keeping everything in line.
It didn't take too long but needless to say I was happy when it was all done.
Step 3: Power Calculations
I did some rough calculations for power consumption for my project.
Each LED draws ~20mA when on (ref). Assuming we want the ability to turn all of them on at once so we'll be drawing 200mA per data pin, about 4 times what they're rated for.
Times that by 10 and we're looking at 2A for the lights alone (absolute max) plus a little bit extra for the bluetooth and arduino power.
What all this basically means is we need to connect the power pin of the LED strip to the DC jack input NOT to the power on the arduino. If you do this you run the risk of damaging the arduino as well as not having your LEDs run properly
Step 4: Soldering the Circuit
For this table, I made a 10x10 LED grid at 33x33cm so just bought a 4m row of lights and cut them into 10x10 LEDs (with some spare for playing with later).
The circuit was wired up as per the picture and I put on the adafruit neopixel library to test the connections. The library is great and this guide is very well written.
In the diagram, I've only shown 3 out of the 10 lights but you get the idea. Each strip has 3 inputs, DataIn (wired up to the arduino data pins), power and ground. Slight oversight with the circuit, it doesn't have an on/off switch. It doesn't affect functionality but it does mean you have to either have it always on or yank out the power adapter - just a bit annoying and something I'll be rectifying later.
Assuming everything has been done correctly up till now, you can see the colourful LEDs light up (something that all electroinc projects build up to) and go through a demo display.
The circuit also shows bi-directional UART connections. Although currently, all data flows from the Android app to the table, in the future I might want to add comms back to the phone (e.g. to keep track of the score) so thought I'd wire it up now. If you do the same, you need to be careful that you're HC06 can handle 5v UART, which is what the Arduino outputs . If not you need a simple potential divider to drop the voltage down to 3v3.
NOTE: When programming the arduino, make sure the HC06 isn't in place as it really doesn't seem to like it (I assume there is contention on the UART lines but don't know for certain). So ensure you use headers pins and sockets as much as possible so you can easily remove/replace components as you need to. I used them for the arduino and the HC06.
Step 5: Opal Acrylic
Once all the lights were working, I had a look around and got a few samples of the acrylic used to cover the lights. I wanted just the right amount of diffusion, enough so each block was clearly visible whilst still allowing the light to completely fill the entire square.
I also decided to just get one big piece to cover the entire table, not just a piece to cover the grid section. This way it gave the look I wanted of the lights just appearing from the table.
Step 6: Coding Up the Arduino
There were probably a number of different snake-like games already out there but I thought it would be fun to code up my own, and it turned out to be surprisingly easy.
I'd really encourage people to have a go at writing your own version of it but if you want some inspiration or just can't be bothered, I've put my version on GitHub here
Step 7: Table Preparation
Once I'd got all the electronics mounted on the board, it's time to prepare the table. The IKEA table I was using only has a thin layer of wood on the top and bottom with the middle part being a cardboard honeycomb.
This was also the first time I'd used a router but I'm pleased to say it was much easier than anticipated. Once everything was marked up, I used the edge guide on the router to cut out the square on the top of the table and just pulled out the honeycomb with some pliers. I also drilled a small hole through the bottom for the power jack.
I had deliberately made the hole slightly larger than the light board to make sure there was still space for the electronics but this meant some light spillage out the side. The simple solution to this (as with many of life's problems) was gaffa tape. A bit round the end edges and the problem was solved.
Step 8: Android App
The android app is very basic on the UI front but is functional - you just swipe to move the snake, and you can also change colour. It's available on github, here . The easiest and quickest way to get using this is to clone it into Android Studio, the free Android IDE which is actually pretty good. From there, you can just plug your phone in and deploy it straight from Android Studio. If there is a demand, I could publish it to the app store - just let me know in the comments and I'll see what I can do.
There are a few features of it that are called out in the readme but the most important is you have to pair the HC06 and phone through the default android settings before opening the app.
Soon I'm going to be putting a bare bones android app that just connects to the HC06 to send and receive UART commands (and nothing else) as a demo for people to pull from so keep your eye on my repo at https://github.com/jimbotops
Step 9: All Done
Sit back, relax and enjoy your wonderful creation.
This is the first techy instructable I've done so please leave feedback and questions in the comments.
Enjoy and thanks for reading
Second Prize in the
Microcontroller Contest 2017