Build it step by step
0 of 8 doneWire the LEDs
D6 to D9 through 220 ohm, left to right.
Wire the knob
Outer legs to 5V and GND, wiper to A0.
Wire the button
D2 to GND.
Upload the sketch
Open the serial monitor at 9600.
Read the LEDs
Add up the values of the lit ones.
Dial your answer
Turn the knob until the monitor shows it.
Press the button
Check the answer and see the score.
Keep going
Try to get ten in a row.
How do you build a binary flash-card quiz?
Four LEDs show a number in binary and you dial the decimal answer with a knob, with a score for each round. You need Arduino Nano, LED 5 mm red × 4, Resistor 220 Ω × 4, Potentiometer 10 kΩ, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 8 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 7
Parts list
- Development BoardsBuyArduino Nano × 1
- SemiconductorsBuyLED 5 mm red × 4
- PassivesBuyResistor 220 Ω × 4
- PassivesBuy
- SwitchesBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| LED 1 (value 8) anode | 220 ohm to Nano D6 | Leftmost bit, worth 8 |
| LED 2 (value 4) anode | 220 ohm to Nano D7 | Worth 4 |
| LED 3 (value 2) anode | 220 ohm to Nano D8 | Worth 2 |
| LED 4 (value 1) anode | 220 ohm to Nano D9 | Rightmost bit, worth 1 |
| All four LED cathodes | Nano GND | Common ground |
| Pot outer legs | Nano 5V and GND | Knob across the supply |
| Pot wiper (middle) | Nano A0 | Your guess, 0 to 15 |
| Answer button | Nano D2 and GND | Press to lock in the guess |
Code
Binary is the number system computers use, where each digit, or bit, is either 0 or 1 and each position is worth twice the one to its right. With four bits the positions are worth 8, 4, 2 and 1, so a lit LED in the second position and the last position means 4 plus 1, which is 5. The quiz picks a random number from 0 to 15 and lights the matching LEDs. You turn the knob to the decimal number you think it shows, and the serial monitor displays your current guess so you can adjust it. A press of the button checks the answer, flashes the LEDs twice for a correct answer or once for a wrong one, prints the right answer with its binary form, and starts a new round with the score updated. The knob is read with the analog input and divided into sixteen steps. Practise until you can read each pattern instantly, then challenge a friend. Later you can extend it to eight LEDs for numbers up to 255, which is the range of one byte.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const int LEDS[4] = {6, 7, 8, 9}; // bit 3, bit 2, bit 1, bit 0
const int KNOB = A0, BTN = 2;
int secret = 0, score = 0, rounds = 0, lastGuess = -1;
bool wasPressed = false;
unsigned long lastPress = 0;
void showBinary(int value) {
for (int i = 0; i < 4; i++) digitalWrite(LEDS[i], (value >> (3 - i)) & 1);
}
void newRound() {
secret = random(0, 16);
showBinary(secret);
lastGuess = -1;
Serial.println("New number. Turn the knob to your answer, then press the button.");
}
int readGuess() {
return constrain(analogRead(KNOB) / 64, 0, 15); // 1024 / 16 = 64 counts per step
}
void flashAll(int times) {
for (int k = 0; k < times; k++) {
for (int i = 0; i < 4; i++) digitalWrite(LEDS[i], HIGH);
delay(150);
for (int i = 0; i < 4; i++) digitalWrite(LEDS[i], LOW);
delay(150);
}
}
void setup() {
for (int i = 0; i < 4; i++) pinMode(LEDS[i], OUTPUT);
pinMode(BTN, INPUT_PULLUP);
randomSeed(analogRead(A1));
Serial.begin(9600);
newRound();
}
void loop() {
int g = readGuess();
if (g != lastGuess) { // show the guess when the knob moves
lastGuess = g;
Serial.print("Guess: "); Serial.println(g);
}
bool pressed = (digitalRead(BTN) == LOW);
if (pressed && !wasPressed && millis() - lastPress > 40) {
lastPress = millis();
rounds++;
if (g == secret) {
score++;
Serial.println("Correct!");
flashAll(2);
} else {
Serial.print("Not quite. The LEDs showed "); Serial.print(secret);
Serial.print(" which is 0b"); Serial.println(secret, BIN);
flashAll(1);
}
Serial.print("Score "); Serial.print(score); Serial.print(" out of "); Serial.println(rounds);
newRound();
}
wasPressed = pressed;
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Guess: 7 Guess: 8 Guess: 7 Guess: 8 Guess: 7 Guess: 8
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Power on | A pattern of LEDs and a prompt on the monitor |
| Knob fully left | Guess 0 |
| Knob fully right | Guess 15 |
| Correct answer | LEDs flash twice and score goes up |
| Wrong answer | One flash and the correct binary value printed |
If it does not work
No guess shown
Check the wiper is on A0 and the serial monitor is at 9600 baud.
LEDs in the wrong order
Bit 3 is on D6 and bit 0 is on D9.
Guess jumps
The knob may be noisy, turn it slowly.
Same number again and again
Check the random seed line is present.
LED dim
Check 220 ohm values and the LED direction.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the binary flash-card quiz?
Arduino Nano, LED 5 mm red × 4, Resistor 220 Ω × 4, Potentiometer 10 kΩ, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.
How long does the binary flash-card quiz take to build?
About 90 minutes for a beginner maker, in 8 steps.
How do I know the binary flash-card quiz works?
Power on: A pattern of LEDs and a prompt on the monitor. Knob fully left: Guess 0. Knob fully right: Guess 15.
No guess shown: what should I check?
Check the wiper is on A0 and the serial monitor is at 9600 baud.
LEDs in the wrong order: what should I check?
Bit 3 is on D6 and bit 0 is on D9.
Guess jumps: what should I check?
The knob may be noisy, turn it slowly.
Same number again and again: what should I check?
Check the random seed line is present.
