This was my first real Arduino project and is also my first instructable so be kind in the comments :) I wanted to try and answer the questions that took me some time to figure out and provide detailed instructions so if you're very familiar with hobbyist electronics then you can probably skim through each step but if you're new to this it should provide you with everything you need.
The aim of the project was to create a 12 x 12 pixel screen in a coffee table that can be controlled via bluetooth and used as a cool room light/play games on it.
For this build you will need these parts:
- Arudino Mega (or clone) - https://www.amazon.co.uk/Arduino-Mega-2560-R3-Micr...
- Arduino micro SD Card Shield (I used this one and and soldered the headers on) - https://www.sparkfun.com/products/12761
- Micro SD card - Any size will do but it must be formatted in FAT32
- 5m WS2812B Addresable LED strip - https://www.amazon.co.uk/gp/product/B01EJ0EXXQ/ref...
- HC05 Bluetooth module - https://www.amazon.co.uk/gp/product/B01G9KSAF6/ref...
- 5 V 6 Amp Power supply - (I used this but there are a hundred others on ebay) http://www.robotshop.com/uk/power-supply-5v-6a.htm...
- Ikea LACK table (the hobbyists classic) - http://www.ikea.com/gb/en/products/tables/coffee-s...
- Access to a laser cutter for 3 mm plywood (or a very steady hand). You can order laser cut parts online at various places (http://www.hobbytronics.co.uk/laser-cutting for example)
- White spray paint
- 2 m aluminium T section (1 1/2 x 1 1/2 x 1/8) - http://www.aluminiumwarehouse.co.uk/Aluminium-T_S...
- 450 mm x 450 mm x 6 mm glass top (most local glaziers can cut custom pieces for you but I used these guys http://www.taylorsglass.co.uk/)
- 1 x 100 micro Farad Capacitor
- 2 x 1k resistor
- 1 x 2k resistor
- 1 x linear rotary potentiometer
- Various jumpers (probably a dozen during the prototyping)
- At least three colours of relatively thick cables for soldering (this can draw some large currents so I would not recommend jumper wires for the power)
- Stripboard for the internal circuit (don't worry it's very simple)
- A soldering iron + solder
- A pair of snips
- Wire strippers
- A Dremel or jigsaw of some kind to hack the table apart. I used this https://www.amazon.co.uk/gp/product/B0078LENZC/ref... with spiral cutting bits https://www.amazon.co.uk/gp/product/B0035PTRNI/ref...
Step 1: Initial Test and Layout
The first port of call is to cut up the LED strip into the lengths you need. This LED strip is really easy to use because it only has 3 pins and makes the Arduino do the real work. I cut the spool into 12 sections each of length 12 LEDs as shown in the figure and laid them out on the back of the table to help me visualise where I was going with this.
I then had a few LEDs left over so I connected them up to an Arduino UNO I had to test if they worked (you can use the Mega mentioned in the project outline too). To do this I cut and stripped some male to male headers and soldered them to the pads on the end of the LED strip. On the WS2812 strip I used the 5V wire is red, ground is white and data is green. Make sure you pay attention to the directional arrow printed on the WS2812B strip so that you don't try and send data in the wrong direction. I connected the 5V line to 5V on the Arduino, Ground to GND and Data to pin 6 with a 1k resistor in series. Bare in mind that the Fritzing schematic of the WS2812B LEDs is slightly different to the ones I had delivered - suffice to say, just make sure data is connected to pin 6, Gnd is connected to ground and 5 is connected to 5V.
With so few LEDs (5 or so) the Arduino should be fine to provide the power; however you can't power many as when they are on full white the LEDs draw up to 60mA each and can quickly overwhelm the Arduino.
Assuming you have the Arduino IDE (if not download and install it) set the chipset type to the Arduino you have and set the COM port to the one that shows an Arduino in the options. Now download the FastLED library and install it (http://fastled.io/). Open the striptest.h example and set the number of LEDs in the sketch to however many you have (I had 5 left). Hit verify and (assuming all goes well) upload it to the Arduino and you should see the lights on the little strip come on and change colour.
Step 2: Soldering the Matrix and Stripboard
Now it is time to start creating the LED matrix.
Cut 11 short lengths of each of the three colours of wire you have. Make sure they are long enough to go from the end of one strip to the beginning of the next one. When laying the LED strips out you need to make sure that the data flow arrow follows a snake. Once this is laid out, carefully solder each led row to the next one as shown in the figure. This is significantly easier if you use the same colour for each type of connection.
Now, more soldering, we need to create the stripboard that will handle the power from the mains power supply. I soldered two columns on the stripboard together for both the 5V and GND so that it handles the current better. See the attached schematic for the circuit you need to create. When soldering the capacitor, ensure that the negative end is attached to the GND rail, not the 5V one. Once the stripboard is finished we need to connect the +VE and GND to the LED strip and also use the other half of the jumpers we cut earlier to connect the Arduino to the power supply and the stripboard. Now would be a good time to add the SD breakout board to the Arduino so that we can save files to it and read from it later. Once the SD breakout board is in place we can connect the 5V rail to the Vin pin and the GND to any GND pin on the Arduino.
Lastly, we can connect a potentiometer to analog input A0 as shown so that we have a way of controlling the brightness of the LEDs.
Once all this is done we can upload the striptest sketch again changing the number of LEDs to 144. Make sure you have the power supply active before you upload this sketch. Hopefully all the LEDs should light up in the patterns of the striptest sketch so we know everything is working.
Step 3: Bluetooth Module Integration
Last piece of wiring now, the HC05 unit connects to the Arduino Mega as shown in the schematic. Ensure that the HC05 unit connects to the Rx1 and Tx1 ports on the mega - this makes it much easier to program and avoids using the use of the "softwareserial" library.
NB. The HC05 unit will take either 5V in or 3.3V in and generally operates on 3.3V logic so I connected it to the 3.3V rail. Some other instructables have shown the Tx (on Arduino) to Rx (on HC05 unit) with a potential divider circuit to knock the 5 V logic from the Arduino into the native level for the HC05 module. This is the reason I had the 1k and 2k resistors in the parts list; however, I didn't bother and it seems perfectly happy on my table :)
Step 4: Table Hacking
Now we need to start cutting the table apart to give our LEDs and electronics a new home.
First mark out a 450 mm x 450 mm square in the middle of the top of the LACK tabletop. Using the Dremel (or a jigsaw) cut the square out as best you can to keep it straight. Now we can remove the top and the cardboard inner pieces leaving you with a hollowed out tabletop as shown in the picture. Using the Dremel again we can drill a hole in the corner of the bottom of the table so we have somewhere to route the mains cable through.
Once the table is prepared we can tape the LEDs down in roughly the right positions before we move on to the next steps. I found it useful to make sure that the electronics were right after every step so try out the striptest sketch again.
Once you're comfortable everything is in its right place then you can drill a couple of small holes to mount the power supply inside the table edge using small bolts. I chose to mount the Arduino outside the table so I can reprogram easily if I want to but it is mounted upside down to the bottom of the table and is not easily visible. I also mounted the potentiometer through the bottom of the table so that the brightness control looks nice and professional.
Step 5: Laser Cut Parts
Now we need to introduce the laser cut parts that form the matrix of squares so we have defined pixels. I have included the dxf files for the laser cut parts that form the wooden matrix and also images of them so you know what they should look like. They are made of two separate pieces, one goes along each row of LEDs and the other crosses them. The parts that cross have a 10 mm high gap cut out at the bottom to allow the wiring to pass through.This gap could be reduced to 5 mm as I appear to have a little bit of light leakage from one pixel to the next.
11 of copies of both parts need to be laser cut out of 3mm plywood and then assemble them to make sure they fit correctly. Once you are happy, take the matrix apart again and spray it white to improve the reflective characteristics of the table. When dry put them back together again and place them over the LEDs. It might be a bit harder to fit them together after spraying as they are now a bit thicker but don't worry just gently tap them into place before you put the matrix into the table.
Step 6: Glediator
Now we have all the hardware implemented we can start looking at software. I downloaded and installed software called Glediator to create animations for the LEDs (http://www.solderlab.de/index.php/software/glediat...). The installation instructions can be a bit fiddly but follow the website closely and you should be fine. We also need to download the sketch from the Glediator website to upload to the Arduino (http://www.solderlab.de/index.php/downloads/catego...). We are using WS2812B LEDs so make sure you download the right one (WS2812 Glediator Interface). Once you open this sketch, change the NUMBER_OF_PIXELS to 144 and upload it to the Arduino.
Once Glediator is installed we can start playing animations on the table. Firstly we need to set the matrix size to 12 x 12 in the Glediator software and also set the output type to HSBL - Horizontal Snake (starting) Bottom Left as this is the way we have wired up the LEDs and change the colour order to GRB (this is what the LEDs take data in for). On the output tab, open the COM port and the LED matrix should start displaying the LED pattern on the middle screen of the Glediator software.
You can create animations and record them to a .dat file that we can upload to the SD card meaning that your favorite animations can be displayed on the table without the need for a PC to be connected. There are a few tutorials online about this (https://hackaday.io/project/5714-glediator-from-sd... for example). I have modified a few different sources of code to work for this so my code should be fine.
When saving your animations, make sure you save them as "animX.dat" where X is any number from 1-15. You could implement more by changing a couple of lines in my code.
NB- When recording Glediator files, the software has a bug in it that means it doesn't remember how you wired up the LED strip. In my code I have implemented a simple function to reverse the order of even-numbered rows meaning it all displays correctly
Step 7: Bluetooth Serial Control
Setting up bluetooth communication between a smartphone and the Arduino proved surprisingly tricky but there are a few simple steps that will make this much easier. Firstly, you will need to download an app for your smartphone. I used https://play.google.com/store/apps/details?id=com.... but there is probably an iphone equivalent (that you have to pay for ;p )
You may have noticed that the HC05 module has a small switch on it. If you power it up with this switch pressed down it enters AT-mode which means you can interrogate parameters on it and change them if you wish.
Upload the attached sketch to the Mega and set the serial rate on your PC to 9600. Disconnect the power to the HC05 unit and then press the button on it down when you reconnect it. The blinking should now be approximately once every two seconds - now the HC05 is in AT-mode.
Now in the serial monitor we can send commands to the HC05 and see its response. Type "AT" and press send and you should see "OK" come back on the serial monitor - now we know it is listening. The bluetooth name of the device can be changed by typing "AT+NAME=XYZPQR" where XYZPQR is what you want the module to be called. I called mine LightWave. The default passcode for the bluetooth module is 1234 (or 0000) but this can be changed too by sending "AT+PSWD=9876" for example. Finally, we can change the communication rate of the HC05 by sending "AT+UART=38400". This is the default rate for most HC05 modules but mine was set differently so it is good practice to set it to be sure. There are lot's more details about these commands here : https://www.itead.cc/wiki/Serial_Port_Bluetooth_M... and there are also instructables about this step that have much more detail https://www.instructables.com/id/Modify-The-HC-05-...
Now we can try sending commands to the module via a bluetooth device. Firstly disconnect the power to the HC05 module and then reconnect it. You should see that the flashing rate of the LED is much faster - this means it is now waiting to pair. On your smartphone, open the Arduino Bluetooth Controller app and find the HC05 module. If you haven't changed the name it will likely be called HC05 or similar. When given the options of how you would like to connect, select Terminal mode. Now try sending some numbers and text and seeing if the serial monitor on the PC reports that they have been received. Hopefully they have so we can move on, if not there are plenty of instructables that might give you a few hints (https://www.instructables.com/id/Bluetooth-Hc-05-W... for example).
The last thing to do here is to map the controller inputs to numbers the Arduino can do something with. I used the following values:
Up = 1,
Down = 2,
Left = 3,
Right = 4,
Start = 5,
Select = 6.
Step 8: Games
I take no credit for the game code. I used the source code found here https://github.com/davidhrbaty/IKEA-LED-Table written by davidhrbaty. However, I have modified it in a few different ways:
- I added a brightness constrain function based on the potentiometer value so we can change the brightness
- I removed the bricks game because I could not get it to compile
- I changed the colour coding of the tetris blocks so they were all different colours
- I reordered the menu
- I implemented an option to play animations from the SD card
- I added high score tracking and a high score display option in the menu
The attached code should just work straight away but if not my suggestion would be stripping out games that seem to be causing error messages and verifying the code again until you find out where the problem is.Then gradually add back in more complexity.
The original author of this code did a fantastic job building something that is really modular and easy to add in to. It is not that difficult to add in extra cases to add more functions into the table.
The options in the menu are:
- SD Card - Plays animations stored on the SD card
- Dice - Random nuber generator between 1 and 6
- Animation - A collection of animations from the FastLED library
- Stars Animation - EDIT - I have now implemented Conway's Game of Life instead of this animation
- Rainbow Animation
- High Scores - Displays high scores for tetris and snake
Before you start playing you need to create two txt files on the SD card, one called "teths.txt" and the other called "snkhs.txt". In both of these files put the number 0 then save them on the root folder of the SD card. These are the high score tracking files and will be updated every time the high score is beaten. If you want to reset it, just change the values back to 0 on a PC.
Once you upload the LED_table program to the Arduino you can open the serial monitor and you should be able to see the bluetooth commands as you send them - this way you know everything is working fine.
Step 9: Enjoy
All that's left to do is to upload the main LED table code to the Mega and then enjoy playing and let me know your high scores!
I am still waiting for the parts for the table top to arrive (Aluminium T section and glass) but the table now functions fine and I can play games on it.
Let me know if you have any comments, edits or spot any mistakes I made.
Step 10: Update
Now it is completely finished! :)
I finally took delivery of the aluminium T section for the edging and did my best job at mitering the joint (turns out 45 degrees is one of the harder angles) but it is almost completely square. For the top I decided to get a thicker sheet of glass (425 x 425 x 8mm) and I frosted the underside using Rustoleum glass frosting spray. I used regular caulk (silicone sealant) to joint the top and the angle pieces so that there is a little bit of flex in the joins if required.
Updated update. Now I've added in Conway's Game of Life as option 7 in the menu rather than the stars animation as I never used it. If you don't know what this game is, Google it, but basically it's a zero player game which shows evolution based on three simple rules. Conway's Game of Life