Wack a Mole
Hit the mole back in his hole
Hello, I am an MCT student from Hogeschool Howest.
I am 18 years old and this is my first year in Howest. In our last semester we had to make a big project and in this instructable you can see how I did it.
Features
- You can play a game
- You can choose your difficulty (Easy - Hard)
- Live sensor data on a chart
- Earn the highest score (Only with account)
- Login and register
Supplies
- Raspberry pi 4B (Cheap computer that runs on linux where you can where you can control the GPIO pins - You can do much more than that like running a server on it etc.)
- Pneumatic Cylinders( a cylindrical object that arises when you let air pass through it on one side and down the other side)
- Solenoid Valve(An electrovalve or solenoid valve is an electromagnetically operated device that is used to allow or not allow liquid or gas to pass through)
- TMP36 (Temperature sensor)
- Light sensor
- RFID (a technology for storing and reading information from a distance from so-called RFID tags that are on or in objects or living beings.)
- LCD (A little display)
- 3D Models (See files down below)
- Compressor
If you want more detail about my supplies you can find everything in my BOM (File below).
What Did I Make?
I made an Arcade game. The name of the game is Wack-A-Mole. You have to smash the moles when they come out of their hole. You can earn points by hitting the top. The moles will also go back to their hole if you miss hitting them. So it's basically an arcade game where you can earn points and break your own high score!
Schematic
If you begin with this project you need to have a good Schematic for your electronics. I made 2 schemes. You can see in the pictures how I did it.
These are the 3 cables colours you have to know.
- Orange cable: 3.3V
- red cable: 5+V (Watch out because for my solenoids I needed 24v and for my lcd 5v)
- black cable: ground
I used a Raspberry pi module 4B.
Getting Things Ready
You need a raspberry pi for this. When you have one u need to have an SD card (8 or 16gb recommended). Then you have to install Raspberry pi Imager. You can follow this quick tutorial of how to use the software. You can choose the hostname and password yourself and you can already setup your wifi on your Pi but we don't have to do it because we have an image that you can download. Write the Image on your pi and follow this link how to setup your ipv4 : link
and set your ipv4 to 192.168.168.100
Now download putty and open it. Do the same things in the photo, BUT change your hostname IP to 192.168.168.169
Connect and login with hostame: Student and password: W8w00rd
Now enter this command.
sudo raspi-config
Enabling ports and file expand
Choose: (6) Advanced > (1) Expand Filesystem then choose (3) Interface > Enable VNC and enable SPI and reboot your Pi.
Wifi
sudo -i wpa_passphrase <your_SSID@Home> <your_wifi-password> >> /etc/wpa_supplicant/wpa_supplicant.conf
Change 'Your_SSID' to the name of your network!
wpa_cli -i wlan0 reconfigure wget www.google.com
The last command is to test if you can surf to google.
Apache2 and MariaDB
Now install Apache2 for a webserver.
apt install apache2 -y
Now Install MariaDB for a database.
apt install mariadb-server mariadb-client -y
Secure MariaDB
mysql_secure_installation
- First you will be asked to enter the current root password for MariaDB. Since there is none yet you can just press Enter here.
- Next you can change the password. Choose a password that you can remember for sure! Default password is W8w00rd
- The next step is to remove anonymous users. Choose y here.
- Prohibit root from logging in remotely. Choose y here.
- Next remove test database and access? Choose y.
- Finally reload privilege databases: y
Create user for MariaDB
- Next, we configure the user student with password W8w00rd on the MariaDB serverver
- mysql -u root -p to access the MariaDB server
- grant all on *.* to 'student'@'localhost' identified by 'W8w00rd'; grant option on*.* to 'student'@'localhost'; Creates a new user student with password W8w00rd who will be granted rights to all databases.
- Flush privileges Reload rights
- Exit the MariaDB server
Now install MysqlWorkBench. You can find online how to setup the software.
Create a new connection.
- Under Connection Method, choose Standard TCP/IP over SSH
- SSH Hostname: 192.168.168.169
- SSH Username: student
- SSH Password: W8w00rd (Save this if possible.MySQL Hostname: 127.0.0.1MySQL Server Port: 3306)
- Username: student
- Password: W8w00rdSave this if possible.
Install Visual studiocode and python. You can also find online how to do it.
- Open Visual Studio
- Install the Remote-SSH
- Tap F1 and enter SSH .Choose the Remote-SSH option: Add New SSH Host
- Tap ssh student@192.168.168.169 -A
- Choose an option to save the file. Press F1 and enter SSH. Choose the option Remote-SSH: Connect To Host
- Choose the option 192.168.168.169
- A new window will open and the password for the RasPi will be prompted.Tap W8w00rd
- Then Visual Studio Code connection will open and install some things on the RasPi.Be patient. It takes a little longer the first time.
Open a new terminal and install this
pip install flask-cors pip install flask-socketio pip install mysql-connector-python pip install gevent pip install gevent-websocket
Now import your Database in MariaDB
You can find an .SQL file in the folders, Just copy the content and past it in MySQL workbench and run the code.
- Surf on your PC to http://192.168.168.169.
- you will now see the Apache2 Debian Default Page, this is the default page of Apache that is currently in the /var/www/html/ folder on the RasPi. We will not use this default directory, but will use the front-end directory from the repo you just cloned.
- If you are no longer sudo: sudo -i
- nano /etc/apache2/sites-available/000-default.conf
- Use down arrow to go to line where it now says DocumentRoot /var/www/htmlof DocumentRoot /home/student/<name_of_your_repo>/front-end and change this to DocumentRoot
- /home/student/<name_of_your_repo>/front-endSave by doing Ctrl + x, followed by Y and Enter
- Then restart Apache by doing service apache2 restart
- Now we have to set the permissions on the root folder correctly.open nano /etc/apache2/apache2. conf and use the down arrow to look for the following lines:
- <Directory /> Options Follow
- SymLinks Allow
- Override All Require all denied
- </Directory>
- and change them to:
- <Directory />
- Options Indexes FollowSymLinks Includes ExecCGI
- AllowOverride All
- Require all granted
- </Directory>
- Save by doing Ctrl + x, followed by Y and Enter
- Followed by restarting Apache by doing service apache2 restart
- Checking if apache started correctly: service apache2 status
- You should get approximately the following output:Loaded: loaded (/lib/systemd/system/apache2. service; enabled; vendor preset:enabled) Active: active (running) since ...
This is it. You can find my code here and test my project.
Database
This is were I store my actions of my sensors and my users. I used 5 tables for this.
Actie (Action)
This is were I store the description of my action (Example: Turn on RFID)
Historiek (History)
Here, I store my DeviceId, ActionId, Date (When the action is activated), value(Example Temprature) and the description.
Device
In this database table I store my name, brand, description, type, price, measuring unit, status and number of devices. This is important because this is linked with history so you have more information of what device is used.
Score
This is where I store my score, Most hitted mole and date when the user played.
Gebruiker (User)
Here, I store the user his firstname, name and password
Backend
The Backend is programmed in Python.
The backend is a background server where you can create API endpoints, sockets and threads. That is important to send data to the front-end of your website.
You can find my code of my backend here.
First of all you should go to config.py to change your username and password and database name so you can connect to your database.
Fronted
I used Adobe XD to make wireframes of my website first. then I had a clear view of how the website will look. When my wireframes were done I gave them a layout and color.
You can find my javascript code and images that I used here.
Sketch Housing
First of all I drew my housing. It's important to know how long and tall it should be. If you go blindly in then you have to redo your housing. I made my front perspective first then my upper. After I finished my two perspectives, I had a clear view. Then I combined then two perspectives into one draw.
Housing - First Part
I had to think first of what material I should make my housing. I came with the idea of plywood sheets, because my pneumatic cylinders are powerful and can break my housing if I used a weak material. After I finished my bottom housing I placed my electronic inside of it so I can go to the next step.
Housing - Second Part
After I had my bottom part of my housing, I could go further. I made the front and side walls of my housing first. This wasn't that hard because I just had to screw the multiplex to my bottom part. You can see on the photo's how I did it.
Housing - Third Part
In this part I made the top of my housing. For this I had to saw 3 holes in my multiplex with a whipsaw. I used a cup that I found in my kitchen to draw a circle on my multiplex so I can see where I to cut the multiplex. In the second and third photo you can see that I made 3 holes for my 3 moles. After I made 3 circles all I had to do was connect the upper part to the side and front part of my housing. In the first photo you can see I cut the holes with a whipsaw and in the last photo you can see I used a cup to draw my circles.
Housing - Last Part
My housing was almost done. All I had to do was just the back of my using although I struggled with it. I had to think first for a second, because if I just connect to back to the rest I couldn't open and work on the electronica. So I used magnets to connect the back with the rest of the part. In the first and second photo you can see that I used magnets. I used 6 of them. I also had to connect 2 mini walls to increase the height of my back part. In the third photo you can see a side view of how I did it. The final step was just to connect a little roof for my back part. After all these steps my housing was almost done. I filled the little holes with some wood filling and I added handles to the side so I could transport it easily.