LED Puzzle

 

Cover Photo.jpg

Simply put, this project is a handheld game. When the device is turned on, each of the 6 LEDS are semi-randomly set to be on or off (details below). From there, the players goal is to turn on each light simultaneously. Pressing any of the buttons will invert the state of the light above it, however it will also invert the state of the lights to the left and right of it. Winning or losing resets the game to a new random configuration, so that it may be played again. For the game in action, see the video below.

Overall, this project was significantly more complex compared to my light switch. It taught me about soldering (both on and off a PCB), Eagle (both schematic and PCB layout), prototyping, and using a microcontroller without an Arduino.

I’ll talk first about the hardware. As you can see in the Eagle schematic below, the project has 3 main components: The LEDS, the buttons, the microcontroller, and the power supply. Each LED needs its own resistor to limit current draw, and each button needs its own resistor to pull down the digital signal to a constant 0 if the button is not pressed. These are all connected to 12 unique digital pins on the ATmega328. Finally, a coin cell in series with a simple switch provides power all the other components.

Schematic.jpg

While this was my first time designing a PCB, I found Eagle fairly easy to use, and was able to route out an acceptable board fairly quickly. The main difficulty routing the board was trying to create a layout which placed the buttons and LEDS in a way both visually appealing and easy to use if holding the board.

Board Layout.jpg

The PCB layout (Note: Ground plane removed for added clarity)

I ordered the PCB’s online from a Chinese manufacturer. Overall, I was fairly impressed with the board. It arrived promptly and had everything connected as it should be. The only problem was the silk screening on the bottom right. Both the “e” in the title, and the last digit of the date are cut off, despite being properly placed on the board. Another issue I encountered with the boards was that while desoldering and removing the battery holder, the pads from both sides of the board and the through hole plating all came with it! This complete lack of conductive material between the pads meant there were no longer electrical connections to either the power switch or the ground plane. To remedy this, I simply soldered wires from the battery holder to the appropriate contact points on the board.

PCB Back Focused.jpg

The backside of the board. Note the direct wire connections between – Batt and R6, as well as + Batt and its via

The software on the ATmega was written in the Arduino programming language. This is simply because I built the prototype circuit on an Arduino, so it didn’t make much sense to rewrite the program. I burned the Arduino bootloader and programmed the ATmega using the process shown here. My code can be found here. I prioritized readability in this code more then memory optimization. While this is microcontroller code, I was so far under the memory maximum I didn’t mind adding a few more lines to make things more understandable.

 

Lastly, the case is a single plastic piece 3D printed on a Makerbot. The design consisted of a rectangular prism with extrude cuts & chamfers to create the handholds and location for board itself. Lastly, two long, tiny cuts were made for the PCB to slide into. Getting the board to fit was the most difficult part of the case process, as I had to sand the grooves quite intensively to widen them enough so the board would fit into them.

Looking back, there are a few things I would have done differently:

  1. Use pin headers for the ATmega. The first time I tried soldering the board, I directly plugged in and soldered the microcontroller to the PCB. This made modifying code extremely difficult, as I had to desolder the entire microcontroller, update it, and resolder it. I used a header the second time, and found the software debugging process much more enjoyable.
  2. Use rechargeable batteries. While coin cells are fine, the convenience of being able to plug a micro-usb cable into the board would have been much nicer (and cheaper for me!)

Overall, I quite enjoyed this project. I got to learn about and apply many different concepts I didn’t have experience with, and end up with a working project!