Twist, pull, press reaction game
Build it step by step
0 of 7 doneTest each control
Print the three readings.
Prepare the card
Record five short tracks.
Test the player
Play each track from code.
Detect the actions
Print which control moved.
Build one round
Prompt, wait, and judge.
Add speeding up and scoring
Shorten the limit each round.
Box it
Mount the controls on a lid.
How do you build a twist, pull, press reaction game?
The game calls out press it, twist it or pull it, and you must do the action in time. You need Arduino Nano, Tactile push button 6 mm, Potentiometer 10 kΩ, Slide potentiometer 10 kΩ, DFPlayer Mini MP3 module, Speaker 8 Ω 0.5 W, SanDisk microSD card 32 GB (A1, Class 10), Battery holder 4 × AA with switch and Resistor 1 kΩ. It takes 7 steps and about 150 minutes.
- Level
- Intermediate
- Time
- About 150 min
- Parts
- 9
Wiring
| From | To | Why |
|---|---|---|
| Button | Nano D2 and GND | Press it |
| Twist pot wiper | Nano A0 (ends to 5 V and GND) | Twist it |
| Slide pot wiper | Nano A1 (ends to 5 V and GND) | Pull it |
| DFPlayer TX | Nano D10 | Replies |
| DFPlayer RX | Nano D11 through a 1 kΩ resistor | Commands |
| DFPlayer SPK1 and SPK2 | Speaker | Voice and sounds |
| 4 AA holder | Nano VIN and GND, DFPlayer VCC to Nano 5V | 6 V battery power |
Code
Each round picks an action at random, plays its voice from the SD card, and gives you a time limit that shortens by about 0.1 second every round. The code compares the resting positions of the pot and slider with their new positions, so you must move the right control by a good margin. The wrong control moving counts as a loss. Record your own voice prompts as short MP3 files with the names shown, in FAT32. Wait for the button to be released between rounds, or a held button would count as the next action. Keep the volume moderate. Power from 4 AA cells through the Nano's VIN pin; do not feed the DFPlayer from VIN, use the Nano's 5 V pin. For a young child's toy, enclose the batteries so the cover needs a screwdriver. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).
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).
// Twist, pull, press game. Libraries: DFRobotDFPlayerMini. Board: Arduino Nano.
// SD card tracks: 0001 "Press it", 0002 "Twist it", 0003 "Pull it", 0004 success sound, 0005 game over.
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
SoftwareSerial mp3(10, 11);
DFRobotDFPlayerMini player;
const int BTN = 2, TWIST = A0, SLIDE = A1;
int baseTwist, baseSlide, score = 0;
unsigned long timeLimit = 3000;
void rebase() { baseTwist = analogRead(TWIST); baseSlide = analogRead(SLIDE); }
int readAction() { // returns 0 press, 1 twist, 2 pull, or -1 for nothing
if (!digitalRead(BTN)) return 0;
if (abs(analogRead(TWIST) - baseTwist) > 250) return 1;
if (abs(analogRead(SLIDE) - baseSlide) > 250) return 2;
return -1;
}
void setup() {
pinMode(BTN, INPUT_PULLUP);
mp3.begin(9600); player.begin(mp3); player.volume(20);
randomSeed(analogRead(A5));
rebase();
}
void loop() {
rebase(); delay(300); // read the resting position of the two controls
while (!digitalRead(BTN)) {} // wait for the button to be released first
int want = random(3);
player.play(want + 1); // say the action
unsigned long start = millis(); int got = -1;
while (millis() - start < timeLimit && got < 0) got = readAction();
if (got == want) {
score++; player.play(4); delay(500);
if (timeLimit > 900) timeLimit -= 120; // speed up every round
} else {
player.play(5); // wrong action or too slow: game over
delay(2500); score = 0; timeLimit = 3000;
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Hear Press it and press the button | Success sound |
| Hear Twist it and press the button | Game over |
| Do nothing | Game over after the limit |
| Several correct rounds | Prompts come faster |
If it does not work
Random game over
Increase the movement margin or check for noisy pots.
No voice
Check the SD card format and the file names.
Prompt repeats too fast
Add a delay after the success sound.
Resets
Use fresh batteries and a good ground.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the twist, pull, press reaction game?
Arduino Nano, Tactile push button 6 mm, Potentiometer 10 kΩ, Slide potentiometer 10 kΩ, DFPlayer Mini MP3 module, Speaker 8 Ω 0.5 W, SanDisk microSD card 32 GB (A1, Class 10), Battery holder 4 × AA with switch and Resistor 1 kΩ.
How long does the twist, pull, press reaction game take to build?
About 150 minutes for a intermediate maker, in 7 steps.
How do I know the twist, pull, press reaction game works?
Hear Press it and press the button: Success sound. Hear Twist it and press the button: Game over. Do nothing: Game over after the limit.
Random game over: what should I check?
Increase the movement margin or check for noisy pots.
No voice: what should I check?
Check the SD card format and the file names.
Prompt repeats too fast: what should I check?
Add a delay after the success sound.
Resets: what should I check?
Use fresh batteries and a good ground.
