Reaction Trainer

by TiboKnockaert in Circuits > Raspberry Pi

76 Views, 0 Favorites, 0 Comments

Reaction Trainer

DSC_0122.jpg

My project is called the Reaction Trainer. It’s a game system I built using a Raspberry Pi to help people improve their reaction speed and memory. The player uses arcade buttons, a joystick, LCD display, and lights to play different game modes, and everything is tracked through a responsive website and kept in a database.


I created this project because I wanted to build something that’s not only fun but also useful for people of all ages. Kids, gamers, athletes, drivers, and even older adults can use it to train their reflexes and stay mentally sharp. I find reaction speed and memory essential in life. It's often taken for granted but don't underestimate it's power!

Supplies

Raspberry Pi 4 with adoptor and 16GB SD card.jpg
MB102 with adaptor.jpg
RFID-RC522.jpg
MPU.jpg
joystick, MCP.jpg
button.jpg
all components arcade button.jpg
WS2812B.jpg
LCD, PCF, potentiometers.jpg
breadboards.jpg
Raspberry Pi T-cobbler.jpg
transistors and resistors.jpg
jumper cables.jpg

Here is a list, photo's, and an estimated price (if you don't own anything listed) for what you need to make this project.


Hardware (In the BOM you can find also everything you need with links to stores where you can buy these items.):

Everything you need to wire:

  1. Raspberry Pi 4 model B (also works with the Raspberry Pi 3 and 5)
  2. Adapter for Raspberry Pi (5V)
  3. SD card (at least 16GB)
  4. MB102
  5. Adapter for MB102 (9V)
  6. RFID-RC522
  7. MPU 6050
  8. NFC cards (you can use anything that has an NFC chip in it like a bankcard, ID card, costumercards, ...)
  9. Joystick module (OT620-B36)
  10. Micro switch (6mm x 6mm x 13mm)
  11. Arcade buttons (60mm x 60mm, in Red, green, blue, and yellow)
  12. Ledstrip WS2812B (Buy max 1 meter (even that is too much but we're gonna cut it so make sure its cuttable), don't buy 60 LED's or more for every meter because that takes too much energy from our 5 Volt.)
  13. LCD1602A
  14. 3D filament (I used black PLA but you can choose your own color and material of course, you also need access to a 3D printer for the housing or change the housing)
  15. Breadboard (enough to wire everything but if you solder everything you don't need a breadboard. I used 2 breadboards (165mm x 55mm), there is a mount for this build in the 3D print file/STL for these exact measurements so be careful if you differ from these measurements.)
  16. Raspberry PI T-cobbler (Is optional but makes it easier to wire everything to your Pi.)
  17. Resistors (7 x 470 Ohm, 4 x 1K Ohm)
  18. Jumper cables (can't place a number on this because this completely depends on how you wire or if you solder. You best buy a set if you aren't sure (I used a set with male to male and female to male jumper cables).)
  19. Potentiometer 10K Ohm
  20. MCP3008
  21. PCF8574
  22. 2N2222 (x 4)

Estimated price: € 235,25


Software:

Every program you need to install on your computer (with links on how to install):

  1. Visual Studio code (how to install Visual Studio Code)
  2. MySQL Workbench 8.0 CE (how to install MySQL Workbench 8.0 CE)

Making the Housing

Screenshot 2025-06-19 011913.png
Screenshot 2025-06-19 011515.png
Screenshot 2025-06-19 122819.png
housing with supports.jpg
housing bottom.jpg
housing top.jpg
housing without components.jpg

We will start with 3D printing our housing. I used an Bambu Lab X1 Carbon to print and it took around 13 hours and 600 grams of filament. If you want to do something while it prints you can go to step 3. Make sure to enable support to prevent problems! I had to file to bigger the gap where the MPU comes (see step 2) a little bit because it was too small. If you want you can prevent this by changing the STL before you print.


When it's printed we just need to remove our supports from the bottom housing and then step 1 is already completed!

Putting in Our Components and Wiring Them

arcade led in cover.jpg
arcade led with cables attached.jpg
arcade led and button with cables attached.jpg
bottom view top with neccessary attached components.jpg
place neccessary components on the top.jpg
attach LED's and button to the arcade covers.jpg
place Pi and breadboard.jpg
place MPU.jpg
entry WS2812B and RFID.jpg
place neccessary components in bottem.jpg
finished project.jpg
Screenshot 2025-06-19 125605.png
Screenshot 2025-06-19 125654.png

The arcade buttons:

If you have bought arcade buttons with cables already attached consider yourself lucky. Otherwise you need to solder cables to the button and the LED. That's 4 cables in total for every arcade button and you need to do this for the 4 arcade buttons. If you aren't sure on how to set up the arcade buttons or you want some more information I watched this video. Before you place it in the cover for the arcade button place the cover first in the top housing otherwise it will not fit. If the arcade cover is placed in the top and secured then you can place the LED's and buttons in its cover.


The top:

We can also place the LCD in the middle and the joystick above it. Place the joystick holder around the joystick (who expected this, right?) on the bottom and glue it so it doesn't fall off (I used super glue and it's been working great). I recommend that you already place wires on the LCD and joystick but not connect them to the Pi yet. This will make the wiring a bit easier.


The bottom:

Start by placing the Pi and the breadboards. Then place the T-cobbler, connected to the Pi (how to connect T-cobbler), and external power supply on the first breadboard. Third we can place our sensors and actuator (RFID, MPU, and WS2812B) in the designated places. You can look at the photos if you aren't sure where to place them. Finally we can place the transistors, resistors, MCP and PCF on the second breadboard.


The wiring:

Now it's time to wire everything! I made a 2 schemes using fritzing where you can see how to wire everything. It's 2 different visuals but the wiring is the same. You can download these schemes in fritzing (.fzz), pdf (.PDF), and you can also use the screenshot I uploaded. I'm not gonna lie, the wiring was a hassle so here are a few tips/guide that may help you:

  1. Put the adapter already in a stopcontact and connect it to the external power supply and test if it works. Keep it on because always turning it on and off is a risk. Power it off by pulling the plug from the socket.
  2. Start by wiring the sensors and actuator in the bottom to the Pi/T-cobbler.
  3. Then wire the transistors and resistors.
  4. Wire the MCP and PCF to the Pi and energy supply and Pi/T-cobbler first, not the LCD and joystick itself yet.
  5. Put the top on it, open it at an degree where you can look inside. Now place wire by wire in the correct place according to the scheme.
  6. Keep calm and take your time! Better once slowly then multiple times fast.


You think everything is wired? Congratulations, you passed the hardest part of this project! We will see if it's wired correctly but first we will set up our database.

Setting Up Our Database

Screenshot 2025-06-19 143910.png
Screenshot 2025-06-19 161540.png

Install MariaDB

  1. Open a terminal on your server.
  2. Run the following command to install MariaDB Server and Client: apt install mariadb-server mariadb-client -y


Secure the MariaDB installation

  1. Run the security script: mysql_secure_installation
  2. When asked for the current root password, just press Enter (there is no password set yet).
  3. Choose to set a root password. For this guide, use the password: r00tP@ss
  4. When prompted:
  5. Remove anonymous users? Type y
  6. Disallow root login remotely? Type y
  7. Remove test database and access to it? Type y
  8. Reload privilege tables now? Type y
  9. Optional: If needed, you can manually activate password authentication for the root user later with the SQL command: SET PASSWORD = PASSWORD('r00tP@ss'); (see StackOverflow).


Configure MySQL Workbench to connect over SSH

You will now set up MySQL Workbench on your own computer.

  1. Open MySQL Workbench on your laptop.
  2. Choose a connection name (name doesn't matter)
  3. Click to create a New Connection.
  4. Set the Connection Method to Standard TCP/IP over SSH.
  5. Fill in the following fields:
  6. SSH Hostname: 192.168.168.169
  7. SSH Username: student
  8. SSH Password: P@ssw0rd (or your own password)
  9. MySQL Hostname: 127.0.0.1
  10. MySQL Server Port: 3306
  11. MySQL Username: root
  12. MySQL Password: r00tP@ss
  13. Save the connection if possible.


Create the database and tables

  1. Open the connection you just created in MySQL Workbench.
  2. Create a new SQL query tab.
  3. Copy the text from Database_Reaction_Trainer.txt.
  4. Paste the text in the empty query tab you made.
  5. Execute the file (press on the lightning bolt).


The database

This project is made in Dutch so that includes the database. But I will give here the translations and explain what each table does in the database. If you want you can change the name of the tables but then you will also need to change the python and javascript code. If it's requested/I have some time, I will try to set all the code in English.


  1. gebruikers – Users (This table stores information about the players.)
  2. Each user has a unique ID.
  3. It saves their name, password, and NFC tag.
  4. spelmodi – Game Modes (This table defines different game modes)
  5. Each mode has an ID, a name (like Minuut Challenge), and a description.)
  6. spelsessies – Game Sessions (Each time a user plays a game, a session is stored here.)
  7. Links to a user, game mode, Actuator Data, and Sensor Data.
  8. Records the start time, end time, and the score achieved.
  9. sensoren – Sensors (This table contains all available sensor types.)
  10. Each sensor has a name and a type.
  11. sensorendata – Sensor Data (This logs every sensor reading during a game session.)
  12. Each entry links to a session and a sensor.
  13. Stores the value read and a timestamp.
  14. actuatoren – Actuators (This table defines the hardware that provides output.)
  15. Each sensor has a name and a type.
  16. actuatorendata – Actuator Data (This logs every time an actuator is activated.)
  17. Records the action, whether it was successful, and the timestamp.
  18. Links to the session and actuator.


Relationships

The database uses foreign keys to link data:

  1. A game session is linked to a user and a game mode.
  2. Sensor and actuator data are linked to their respective sessions.
  3. This structure allows you to track exactly what happened during each game in terms of inputs and outputs.


Configuring for the Code

Set up Wi-Fi on the Pi

  1. Run: sudo -i
  2. Run: wpa_passphrase <your_SSID@Home> <your_wifi-password> >> /etc/wpa_supplicant/wpa_supplicant.conf
  3. Replace your_SSID@Home with your Wi-Fi network name and <your_wifi-password> with your Wi-Fi password.
  4. Run: wpa_cli -i wlan0 reconfigure
  5. Run: wget www.google.com to check if internet is working.


Full update/upgrade

  1. Run: apt update
  2. Run: apt upgrade
  3. Type Y if prompted for confirmation.
  4. Wait until it finishes.


Install rpi-lgpio

  1. After updates (kernel >= 6.6), RPi.GPIO may stop working with GPIO functions like interrupts.
  2. Solution: use rpi-lgpio, which has the same syntax.
  3. Remove old library: apt remove python3-rpi.gpio -y
  4. Install new library: apt install python3-rpi-lgpio -y
  5. Check via pip that RPi.GPIO isn’t installed.
  6. If you get: RuntimeError: Failed to add edge detection, run:
  7. pip3 uninstall rpi-lgpio RPi.GPIO
  8. pip3 install rpi-lgpio


Configure VS Code

  1. Open Visual Studio Code
  2. Install the extension: Remote-SSH
  3. Press F1, type SSH
  4. Choose Remote-SSH: Add New SSH Host
  5. Enter: ssh <here name Pi>@192.168.168.169 -A
  6. Choose where to save the file
  7. Press F1, type SSH
  8. Choose Remote-SSH: Connect To Host
  9. Select 192.168.168.169
  10. Enter password: <choose your own password>
  11. Wait while VS Code connects and installs components (first time takes longer).


Clone the repo

  1. Run in the terminal in VS: git clone https://github.com/howest-mct/2024-2025-projectone-mct-KnockaertTibo


Create virtual environment (venv)

  1. For Windows: py -m venv venv
  2. For Mac: python3 -m venv venv

Then close and reopen the terminal in VS Code and check if the venv is active.


Install packages

  1. For Windows: pip install -r ./requirements.txt
  2. For Mac: pip install -r requirements.txt

requirements.txt is already in the repo. You might need to add extra packages later.


Adjust database config

  1. Make a copy of config_example.py and name it config.py
  2. Fill it in, config.py:
  3. [connector_python]
  4. user = USER_HERE
  5. host = 127.0.0.1
  6. port = 3306
  7. password = PWD_HERE
  8. database = reactiontrainer

  9. [application_config]
  10. driver = 'SQL Server'


Install Apache

  1. Install: apt install apache2 -y
  2. This replaces the Live Server from VS Code for the webserver.

Note: All files (frontend + backend) will go in one folder. Adjust Apache’s default folder and permissions once your structure is ready. Set permissions:

  1. sudo chown student:www-data /<here comes your path to the front>/https://github.com/howest-mct/2024-2025-projectone-mct-KnockaertTibo/front
  2. sudo chmod 0750 /<here comes your path to the front>/https://github.com/howest-mct/2024-2025-projectone-mct-KnockaertTibo/front

The Code

Screenshot 2025-06-19 174640.png
Screenshot 2025-06-19 174833.png

If you have done everything correctly you will see left in VS lots of code files in a folder structure. To help you understand most of it I will explain the two most important folders, and the files in these folders.


Backend

  1. Purpose: Contains all backend (server-side) code for your project, including the main application, hardware integration, configuration, and database logic.
  2. Key files:
  3. app.py: Main entry point for the backend server. Controls and directs all hardware, sends data to database and frontend.
  4. config.py: To make an connection with the database.
  5. main.py: To test all components together without threading, javascript, .. .
  6. arcadeknop.py, joystick.py, knop.py, lcd.py, led.py, mpu.py, rfid.py, ws2812B.py: To test every component alone (buttons, joystick, LEDs, LCD, RFID, etc.).
  7. gamemodes.py: To test how game modes are selected.
  8. repositories/: Contains data access logic (database queries).
  9. models/: Contains data models (classes representing database tables).
  10. klassen/: Contains helper classes to make it easier in app.py and other files


Frontend

  1. Purpose: Contains all frontend (client-side) code, including HTML, CSS, JS, and static assets.
  2. Key files:
  3. index.html: Welcome page.
  4. login.html: Login form.
  5. createAccount.html: Account creation form.
  6. thuis.html: Main game/home page.
  7. statistieken.html: Statistics page.
  8. instellingen.html: Settings page.
  9. termsAndPrivacyPolicy.html: Legal info.
  10. screen.scss: Main stylesheet (Sass).
  11. app.js: Main JavaScript file for frontend logic.

How to Play

Nice, everything is made so how do we play this thing?

  1. Plug your adaptors from your external power supply and Raspberry Pi in.
  2. Start the code (run app.py (don't forget to add sudo for the command because otherwise the ledstrip will not work and we will get errors): sudo /<here comes your path>/2024-2025-projectone-mct-KnockaertTibo/venv/bin/python /<here comes your path>/2024-2025-projectone-mct-KnockaertTibo/backend/app.py)
  3. Scan your NFC card (don't forget to make an user first on the site that is connected to that card).
  4. Select your game mode that you want to play.
  5. Press the joystick button.
  6. And play!


If you want to see your statistics, change your name, add user, ... You need to go to the site:

Type in the browser the IP of the Pi

  1. If the device on which you're searching the site is connected with ethernet cable to your Pi, search: 192.168.168.169
  2. If the device on which you're searching the site is not connected with ethernet cable to your Pi:
  3. Open the terminal in VS
  4. Run: hostname -I
  5. You will see 2 IP addresses
  6. 192.168.168.169 (This is not the IP from your Pi.)
  7. 192.xxx.xxx.xxx or 172.xxx.xxx.xxx (The second IP is from the Pi.)
  8. Type in your browser the second IP address (the one from the Pi).


Have Fun

So, with that comes this project to an end. Of course you can always add more hardware, game modes, ... And I would recommend everyone that builds this project (or any other project) to do this and add your own touch to it. You can for example make your own game mode! If you have any questions, errors, recommendations or you build it yourself/gave it your own touch I would love to hear about it in the comments!