Introduction: WebFoos - a Smart Foosball Table
For my school project in my first year at Howest, I decided to make a smart Foosball table. The table registers goals and saves played matches, match statistics and user/team statistics to an online website.
Step 1: The Parts
To build your own smart foosball table, you will need the following (or similar) parts:
- 1 x A Raspberry Pi 3 Model B (€39,90)
- 2 x HC-sr04 Ultrasonic Sensor (€2,79 each)
- 1 x RFC522 RFID Sensor (€11,90)
- 1 x LCD Screen (€13,90)
- 1 x PVC Piping 50mm (€2,49)
- 8 x PVC Piping 50mm Corner (€1,59 each)
- 2 x PVC Piping 50mm T (€3,39 each)
- A couple of connector cables (€4,95)
Total Price Estimate: €123,17
Prices may vary from supplier to supplier but these are the approximate prices that I got my parts for.
Step 2: The Sensors: Circuitry
To connect the sensors to the Raspberry Pi, follow the fritzing scheme above using the connector cables.
The resistor connected to the V0 pin on the LCD screen can be replaced by a potentiometer so that you can adjust the contrast on the LCD screen. Simply connect the two outer pins of the potentiometer to the ground and te 5V, then connect the middle pin to the V0.
Make sure all of your cables are long enough so that you can place all of your sensors correctly on/inside the table (see following step).
Step 3: The Sensors: HC-RS04
Before we can place the HC-SR04 in its correct place, we need to put together the PVC parts to make 2 similar tubes to conduct the ball from te goal past the HC-SR04:
- Connect 2 of the 45° corner bits to 1 of the T-shaped PVC connectors (1st picture)
- The HC-SR04 fits perfectly in the part that sticks out (2nd picture)
- Use 2 other 45° connectors to further conduct the ball to where you want it to lead (3rd picture)
- Drill a hole in the bottom of the goal, through which the ball can now fall down into the pipe
- Cut off a part of the long PVC tube, you can use this part to support the pipe you built
- Glue the pipe to the table like on the 3rd picture (Make sure you don't forget to connect your HC-SR04 to the Raspberry Pi first!!!)
Repeat the steps above for the second HC-SR04
Step 4: The Sensors: RSC522
The RSC522 RFID Sensor can be glued to the inside of the wall next to one of the goals. The wood is thin enough so that you can scan your card through the wood.
Step 5: The Sensors: LCD Screen
To mount the LCD screen on top of the table, I just drilled some holes for the cables to fit through te top of the table, then glued the LCD to the table itself.
Step 6: The Pi
For this project, I assume you already have a working debian image installed on your Raspberry Pi. If not, you can find an easy tutorial on the official raspberry pi website.
If you've successfully installed Raspbian, fenter the following commands on your Pi:
- Install Packages:
- sudo apt update
- sudo apt install -y python3-venv python3-pip python3-mysqldb mariadb-server uwsgi nginx uwsgi-plugin-python3
- Create a virtual environment:
- python3 -m pip install --upgrade pip setuptools wheel virtualenv
- mkdir project1 && cd project1
- python3 -m venv --system-site-packages env
- source env/bin/activate
- python -m pip install mysql-connector-python argon2-cffi Flask Flask-HTTPAuth Flask-MySQL mysql-connector-python passlib
- Making the Database:
sudo mariadb
CREATE USER 'project1-admin'@'localhost' IDENTIFIED BY 'sdfgh';
CREATE USER 'project1-web'@'localhost' IDENTIFIED BY 'sdfgh';
CREATE USER 'project1-sensor'@'localhost' IDENTIFIED BY 'sdfgh';CREATE DATABASE project1;
GRANT ALL PRIVILEGES ON project1.* to 'project1-admin'@'localhost' WITH GRANT OPTION; GRANT SELECT, INSERT, UPDATE, DELETE ON project1.* TO 'project1-web'@'localhost'; GRANT SELECT, INSERT, UPDATE, DELETE ON project1.* TO 'project1-sensor'@'localhost'; FLUSH PRIVILEGES;
Run the sql files in project1/sql
- Downloading the code:
- git clone https://github.com/NMCT-S2-Project-I/project-i-pieterdebois/tree/master/Project-I
sed -i s/pi/$USER/g conf/ (!changes pi in the config files to your own username)
- Setup nginx:
sudo cp conf/nginx /etc/nginx/sites-available/project1
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/project1 /etc/nginx/sites-enabled/project1
sudo systemctl restart nginx.service
- Run the code:
sudo systemctl enable project1-*