A math practice toy for kids, part 1: Plus and minus on a 16x2 LCD
Part 1from the A math practice toy series · 4 parts in all
This is the first in a series of articles about a project that grew for years: a math practice toy for my kids, built from spare parts. Part 1 is the simplest version — NANO-MathToyPlusMinus100-1602 — an Arduino Nano, a 16x2 LCD, and two buttons, generating addition and subtraction questions with results from 0 to 100.
The whole design, in three sentences
On power-up the sketch generates a random question like 37 + 45 = ? and shows it
on line one of the LCD. The child types the answer on a numeric keypad (or, in this earliest
version, presses a button to reveal the answer), the sketch compares and shows a smiley or a
correction, then moves on. Score and streak are tracked in RAM.
Code structure — deliberately boring
Beginners often think real projects need classes and layers. A toy like this does not. The
repository is one .ino file with three sections:
- Config constants — which pins, the maximum operand (100), timing values.
- Question generation —
random()with a guard: for subtraction, swap operands if the result would be negative; for addition, re-roll if the sum exceeds 100. This "re-roll until valid" trick is the honest, simple way to constrain random ranges. - The loop — read input, update the display, check the answer, repeat.
Why a Nano and not something fancier
Because the point was the child, not the hardware. A Nano costs a few dollars, runs from a USB power bank, and the 16x2 LCD is visible in daylight. If you want to see where this line of projects ended up — graphics displays, WiFi clocks, backlight auto-dimming — read parts 2, 3 and 4 of the series, and the shared library article about ESP8266-Functions-Common.
Repository: github.com/bobhuang1/NANO-MathToyPlusMinus100-1602