Simon Says

Handheld Electronic Game using Arduino

Miles Hitchen

Issue 36, July 2020

When a maker wants to teach his 7 year old great-nephew electronics and have fun at the same time, he turns an old classic game into a handheld game for hours of fun.

Miles created a breadboard kit that builds a retro memory game, then turned it into a hand-held version on a PCB. The game is based on the “Simon” electronic game of the 1980s where the player has to repeat the sequence of lights randomly chosen by the brains of the game (in this case, an ATmega328P).

Thank you for submitting your project to us via our website. Can you tell our readers a little about yourself and how you got into electronics?

I’ve been a software engineer forever (well, 30 years seems like forever). I got into electronics about 5 or 6 years ago when I started to watch Ben Heck and Dave Jones on YouTube. They are great ambassadors for electronic hobbyists and their enthusiasm is contagious.

A friend bought me a couple of intro books to electronics and I bought an Arduino and some components, including a bunch of 8x8 LED matrix’s and some MAX7219CNG IC’s. I was able to use my programming skills with the Arduino and loved the fact that I could build something physical.

Back in 2017, I submitted a project to DIYODE that I made for my godson and was lucky enough to win the Editor’s Choice award, which I put toward buying an oscilloscope – an amazing Rigol DS1054Z.

Oh yes, the Sensory Board project of yours that we published in Issue 4 (Oct 2017) was amazing. It seems like your Nephew is lucky to have a Great-Uncle with electronics prowess. You mentioned you made him a Theremin before building this Simon-like game to teach him about electronics.

My great-nephew Blake, who is 7 years old, has always been interested in how things work and making things, and his mum had bought him a clip-together electronics kit that he really enjoyed. I thought he might like to build a “real” electronics circuit with some raw components and a breadboard. The Theremin was quite basic (an oscillator IC, LDR and a speaker) and not too many jumper wires, but was really interactive, using a torch or your hand to light or cover the LDR and change the tone coming from the speaker.

Blake building the Theremin project.
Theremin build.

It’s great to be able to build circuits using commonly available components that have practical outcomes that kids can engage with. What was the inspiration for progressing from the Theremin to your Simon game?

I wanted Blake’s next project to be a bit more challenging, but also rewarding, so I was thinking that some sort of game that kept a score and he could try to beat his best score, or challenge his mum or friends to see who could get the highest score. I remembered playing “Simon” when I was around his age and thought that was something that I could prototype using an Arduino. The initial game-play I developed didn’t seem quite right, so I turned to Google & Wikipedia, to find out what the original gameplay was. https://en.wikipedia.org/wiki/Simon_(game)

It is such a simple but addictive game, and we like your approach to ‘gamify’ the project to keep Blake entertained. Can you give us an overview of how your circuit works?

The circuit is pretty simple, 5 tactile switches, 5 related LEDs (with current limiting resistors), the score-module and one speaker.

  • The player initiates the game by pressing the start switch (white LED).
  • This resets the score module to “00”.
  • A random coloured LED is then lit and an associated tone is played, the coloured LED is then unlit.
  • The player must then press the button under the LED that was lit.
  • If they press the wrong switch then the game ends.
  • If they press the correct switch then the score module is clocked and the score increases by 1.
  • A new random colour LED is then added to the sequence, and each one lit and associated tone played.
  • The player must press the associated switches in the correct sequence, with each correct switch press increasing the score by 1 (the length of time the tones are played for increases as the player reaches specific scores).
  • This continues until the player presses the wrong switch or they reach a score of 99, when a winning tune is played through the speaker.

On the PCB version I increased the number of 7-segment displays so that the score could go higher than 99.

Tell us more about your small 7-segment display PCB.

It’s used to keep the score and makes use of some 4000 series ICs (CD4026BE) that are combined decade counters and 7-segment display drivers, I had these components left over from a previous project. Besides power, the module only needs a few pins to drive it.

Did you find the game-play code online, and were there any modifications you needed to make?

Although I could probably have found some code online, being a software engineer, I wanted to write it from scratch myself. There were a few tricky points:

RANDOMLY GENERATING THE LIGHT SEQUENCE: I looked at a couple of approaches, but finally settled on using the Arduino’s millis() function (the number of milliseconds since the Arduino was turned on). When the player presses one of the tac switches, we can get the value of millis() Modulus 4, to give a pseudo-random number between 0 and 3, using this as the index for the next light in the sequence. This seems to work well.

SOUNDS: I also wanted to use the tones from the original game (as these were chosen to always be harmonic, whatever order they’re played in).

So I needed to do some more googling to work out how to convert the notes to a frequency that could be used with the Arduino tone() function.

Also, on the topic of audio, the original game had a pretty poor note sequence when the player completed a level, so I improved on that by using some audio code from: https://dragaosemchama.com/en/2019/02/songs-for-arduino/

Great! Good advice for any of our readers wanting to develop their own game on their Arduino. What other challenges did you need to overcome to get the prototype to work?

Low power consumption on the ATmega328, so that it could use two or three 1.5v cell batteries. I was able to achieve this by modifying the board file so that the fuse settings for the Brown-Out value was lowered.

I didn’t want (or need) the 16MHz clock, so it was necessary to download a board definition for the 8MHz internal clock. Unfortunately, I bought some ATmega328-U’s (rather than the P-PU’s) which aren’t supported by the Arduino IDE without some modifications to one of the config files.

Those letters at the end of the part number can make all the difference sometimes. Your breadboard prototype was obviously well received by Blake in order to motivate you to turn it into a handheld PCB?

To be honest, I enjoyed playing the prototype version so much, that I wanted to convert it to a handheld PCB version, for myself and to give as unique gifts.

DIY Birthday presents! What steps did you take to go from prototype to PCB design?

I’ve used a couple of schematic/PCB design solutions in the past, RS DesignSparkPCB, EasyEDA, Aisler & JLCPCB. I’ve settled on using EasyEDA & JLCPCB to create a schematic, PCB and get it manufactured.

I like using EasyEDA as it’s quite intuitive, has a simple interface and can be used in a browser, so you only need access to the internet to work with it, it also has a massive library of schematic/PCB parts and a good editor for creating new parts. I did find initially that I had no idea where to start (as I had no experience of creating schematics or PCB’s), but I found a good YouTube video that goes through the basics: https://youtu.be/_3jFsNffzxQ.

Great! It’s so easy for makers to be able to design and source their own boards now. In Issue 34 we started teaching our readers how to use EAGLE.

Tell us, what design challenges did you need to overcome with your PCB design, and how did you find the service and quality of the board from JLCPCB?

Ergonomic component layout and track layout is always more time consuming than you’d expect. Getting the right ergonomic and aesthetic layout for the components took some time. I used some Veroboard to help with the layout (it’s a lot easier and gives a better feel for the final product than laying out in the PCB design software). Also, I’m no expert at laying out the PCB tracks, and although EasyEDA has the capability to auto layout the tracks, the results are rarely as good as a human can achieve with a bit of time and patience. As I use a lot of through-hole components that have a 0.1” pin pitch, I tend to use a display grid of 0.1” and a snap grid of 0.01” (or 0.254mm).

I’ve made quite a few boards using JLCPCB. It integrates well into EasyEDA and I’ve always found their service and board quality great. Their customer service is pretty good too, they even allowed me to change the board colour after submitting it for manufacture.

Using Veroboard to workout the ideal component placement.

The auto track layout feature in EasyEDA and others is handy, but agreed, we can’t rely on it to get it 100% correct. Is this the first time you have used an ATmega328 in a project, and how did you go about programming it?

I’ve used a standalone ATmega328 in a number of projects. I program it using the Arduino board and IDE, then I’ll burn it onto a new chip using a breadboard and the Arduino as an ISP. The Arduino website has a great article on this covering both the use of an external and internal clock: https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard

Excellent! It can be a little daunting knowing how to program a 328. Do you have any plans to make an enclosure for your PCB design?

I designed the component layout to be seen, I think it gives it a retro-look, I know it’s not particularly practical, but I think it looks good. I might look at creating a clear case so that the components are protected, but still visible.

Agreed. Hiding the electronics mean that you can’t admire your handiwork. If you were to start the project again, would you do anything differently?

The circuit has no reverse voltage protection, so I’ve been looking into that. I am considering the approach here that uses a FET (https://www.radiolocman.com/shem/schematics.html?di=588375) This would result in a minimal voltage drop (much lower than a simple diode approach). Also, I’d remove the red power indicator LED as this is redundant due to the 7-segment displays being lit.

Using a FET is an interesting approach instead of a diode that would reduce battery life. Is there anything else about your project that we haven’t covered that our readers should know about?

The PCB version has a few upgrades from the prototype. There’s a “Repeat Sequence” switch that will repeat the sequence of LEDs, if the player hasn’t pressed one of the coloured LEDs. Also, I’ve updated the code so that there’s a “winning” tune played at various milestones e.g. every 5 sequences.

As a teaching/learning tool, the breadboard/prototype project provides a good opportunity for troubleshooting as it’s quite easy to wire things up incorrectly, especially around the LEDs and tac switches. Blake had a few issues with this, but he persevered and figured out where he went wrong, and I’m very proud of him for sticking with it. The feeling of achievement when you complete something that is challenging is definitely worth the effort.

Some great additions there, and we agree, the thrill of getting a circuit to work after a little troubleshooting is a good feeling. If our readers wanted to make one of these for themselves, can they get the schematic, board design, and code?

I have created a GitHub repository for the Arduino code: https://github.com/milesee/arduino_simon_game

I've also made the EasyEDA projects for the Simon Game and Scoreboard Module public:

SIMONGAME: https://easyeda.com/milesee/simon_copy

SCOREBOARD MODULE: https://easyeda.com/milesee/seven-segment-counter_copy

We’ll put the files on our website for our readers to access, thanks a million. Are you working on any other projects for yourself or your nephew?

I’ve been thinking of building a simple 3-wheel robot that has collision detection using the sonic distance measuring modules. I know there are a lot of kits out there already, but I’m interested in building one from scratch.

We’re sure Blake would be over the moon to build and play with a robot. We wish you all the best and thank you for sharing your project build with us.