More than a few times I’ve peeked in at night to find my son in bed with a calculator in one hand and a flashlight in the other, sound asleep after pushing “1 + = = =” and watching the numbers climb until he couldn’t keep his eyes open. So, for his fourth birthday I decided to build him a dedicated machine that would do nothing but count up and count down at his command.

My initial idea was simple: a large multi-digit seven-segment LED display, two big arcade
buttons to add and subtract, and a 10-position rotary switch in the middle. Turn the rotary switch to choose a value from one to 10, then push a button to increase the number displayed on the LEDs by that amount. Push the other
button and it would go down by the same.

The Circuit

The circuit came first in this project, since the size of the case would depend on the size of the finished electronics package.

Figure A

At the core of it all is an ATmega328, one of the most common Arduino processors. A pair of 4-digit LED clock displays show the number, driven by a Maxim MAX7219 LED display driver chip capable of handling 64 LEDs, or 8 seven-segment digits, using only 3 output pins on the ATmega.

After building the circuit on a breadboard and writing a basic test program, I had my first introduction to switch bounce, the electronic noise or chatter on the millisecond level as a switch’s contacts open or close. What seems like one button push to us can be read by a microprocessor as dozens, hundreds, or more. Fortunately, the arcade buttons I ordered happened to be double-throw switches. These allow a fairly simple debounce solution in hardware using 2 NAND logic gates for each switch. A 74HC00 integrated circuit provided all 4 required gates in one chip.

The rotary switch was binary coded, so it was only a matter of connecting its 4 pins — one for each of the bits required to count to 10 — to the ATmega’s input pins, reading each and combining them, then converting to decimal.

Now that the circuit could count, I needed a way to store the current value of the display. You don’t want to get your Counting Box up to an amazingly high number only to lose it when you turn the power off. This should be an easy job for the ATmega’s internal EEPROM, but when I looked at the specs it was only rated for 100,000 write cycles. With a display that could go up to 99,999,999, that seemed inadequate. Instead I found the 24LC256 EEPROM memory chip with 1,000,000 write cycles — still not as high as the Counting Box could reach, but a lot closer. In actual use, though, the ATmega’s onboard memory would more than likely be sufficient.

I did my prototyping and programming with an Arduino Duemilanove, but for the final build I used the same ATmega chip to build a standalone circuit on stripboard. I prefer a standalone microcontroller in my projects because it uses less space than building in an entire Arduino board, costs less, and leaves my Arduino free for the next project.

The LED display is on its own board, connected by ribbon cable to the main processor board. The 99,999,999 count that the 8 digits allow is definitely overkill, but using the 4-digit LED displays saved a lot of wiring and soldering compared to using individual digits.

For power, I planned on using rechargeable AA batteries.

The Software

The software has 3 primary functions: handling button pushes to increase and decrease the number by the selected amount, displaying the number, and storing the number to memory.

Button pushes come through as interrupts, which do pretty much what it sounds like they would — interrupt any other actions taking place in the program. The alternative to this is to constantly poll the button to see if it’s being pressed, but this is inefficient compared to essentially asking the button to let you know when it’s being pressed.
When a button is pressed, the program reads the value of the rotary switch, adds or subtracts that amount from the variable, then breaks it into individual digits to send to the MAX7219 for display. In every loop, the program compares the current value of the variable to the value of the variable on the previous loop. If they’re different it stores the new value to the EEPROM memory chip.

You can zero the Counting Box by setting the number selector to 8 and holding down the decrease button when you power it on. Similarly, setting the number selector to 3 and holding the increment button during power-up will display statistics such as highest and lowest numbers reached and total number of button presses over the life of the box.
To save power, the ATmega goes to sleep and the LED display goes dark if no buttons are pushed for one minute. Pushing either button will wake the system.

Building the Box

With the circuit and software done, I set them both aside. They could definitely stand some further optimization, but their only real requirement was that they work. The box, though, would be seen every day and had to look as good as it could. It had to be friendly to young hands and resilient enough to withstand the occasional drop. Wood was the perfect material, but I don’t have the precision woodworking skills or shop to build what I wanted. Laser cutting to the rescue!

To lay out the pattern of joints on the corners, I used an online utility called BoxMaker (boxmaker.rahulbotics.com). Enter the outer width, depth, and height of your finished box, the thickness of the material, and the kerf (the width of material removed by the cut), and it generates a PDF of all the required pieces.

I imported this PDF to Adobe Illustrator, made a few minor tweaks to the spacing for symmetry between left and right sides, and placed the elements like the window cutout and buttonholes.

Before uploading for cutting, I printed the plans and spray-mounted them onto 1/4″ foam core board, then cut out and assembled the pieces. Foam board is a lot cheaper than laser-cutting, so this stage is a much better place to find errors (like a tab where a slot should be, or a box not deep enough to hold a button).


Not only did the mockup fit together, but all of the components fit into it. With that final check done, I uploaded the design to Ponoko (ponoko.com) to be laser-cut from bamboo plywood.

Two weeks later a package arrived with the crisply cut wood. The pieces were beautiful, but they didn’t fit together. I’d specified too wide of a kerf (the width of a cut), and in compensating for that the BoxMaker program had adjusted the widths of the notches to close up gaps that didn’t exist. With a file and some sandpaper I was able to widen the notches enough to get the box together.


I glued the joints, sanded a radius on all the corners, then finished the wood with a polyurethane gloss for protection and to give the bamboo a warm, amber glow.

The red acrylic window covering the LEDs was laser-cut at the same time as the wood. I was hoping for a tight fit that wouldn’t require any glue so I made 6 different versions of the window, each sized a few hundredths of an inch larger than the last, and used the one that fit best.

As I started putting it all together, I realized I wasn’t happy with the way the AA batteries fit into the case. They were ugly, and taking them out for charging would be a hassle. To replace them, I used a lithium-ion battery pack and USB charger, both from Adafruit (adafruit.com). The 3.7V battery feeds into a voltage step-up circuit to provide the 5V needed.


Like a lot of us, my son likes to look inside things and see how they work. The last-minute power supply change let me put the circuit facing outward where the batteries would have been, allowing the door on the back to serve as a window for him to peek at the electronics inside. To keep fragile wires safe, I covered the circuit with a piece of clear acrylic cut to size and held by standoffs.


The door in the back of the box is held on by four 3mm neodymium magnets epoxied into holes drilled into the door panel and the frame. The magnets are strong enough to keep the door secure in regular use, but they give when pried open using the half-moon cutouts on each side.


Using the Counting Box

In addition to the obvious thrill of seeing how high the numbers can get, it’s easy to come up with games to play with the Counting Box. Ask questions like, “How can you get to 49 in the fewest button pushes? Can you do it with the selector switch set to the same value the entire time?” The Counting Box can also be used to help introduce mathematical concepts like skip counting. More advanced ideas like multiplication and division come quickly when it’s made apparent that they’re nothing more than repeated addition or subtraction.

I’m not sure who’s learned more, me in building it or my son in playing with it, but either way the Counting Box adds up to a lot of fun.

More at hahabird.com.


Nathan Pryor

Nathan Pryor is a software developer and graphic designer who enjoys turning off the computer and building things with his hands. He has a hard time remembering to clean up after his last project before starting the next.

MAKE V33 high Build Notes: The Counting Box

MAKE Volume 33 features our special Software for Makers section covering apps for circuit board design, 3D design and printing, microcontrollers, and programming for kids. Also, meet our new Arduino-powered Rovera robot and get started with Raspberry Pi. As usual, you’ll also find fascinating makers inside, like the maniacs on our cover, the hackers behind the popular Power Racing Series events at Maker Faire.

Try your hand at 22 great DIY projects, like the Optical Tremolo guitar effects box, "Panjolele" cake-pan ukelele, Wii Nunchuk Mouse, CNC joinery tricks, treat-dispensing cat scratching post, laser-cut flexing wooden books, sake brewing, growing incredibly hot “ghost chili” peppers, and much more.

On newsstands now, by subscription, or available in the Maker Shed

Buy now!

blog comments powered by Disqus

Related Supplies at Maker Shed


Get every new post delivered to your Inbox.

Join 28,391 other followers