Air Hockey Robot
By Nicola King. Posted

When Ondřej Sláma and Dominik Jasek, two students from the Czech Republic studying at Brno University of Technology, needed to write their course thesis, they chose a rather engaging project – an Air Hockey Robot controlled by Raspberry Pi.
“I always dreamed of building some human vs machine project,” Dominik tells us. “At the university, I got an idea to build an air hockey robot. What inspired me the most in designing the robot was definitely a project from JJRobots. I chose good parts from that and replaced bad ones and hopefully improved it. Luckily for me, Ondřej joined me very soon and took care of the Raspberry Pi. We made a great duo.”
Advertisement
Starter electronics: how to build and program circuits with a Raspberry Pi or Raspberry Pi Pico.
Out of thin air
The pair built the whole project from scratch, taking about a year. “A lot of work had to be done before even thinking about the actual implementation of the robot controlling the other side of the table,” reveals Ondřej. “It would be hard to pick the most difficult element. We had to overcome a lot of challenges, including electrical wiring of all the chosen hardware, robot movement control algorithms, computer vision, game strategy algorithms, user interface etc.”
After designing the table in Fusion 360, it was constructed from spruce and plywood with an Alubond playing surface. To ensure smooth gliding of the puck, a square mesh of 920 holes was drilled into the game board, enabling air to flow through from two fans located under the table.
As for the mechanical aspect, the pair opted for an ‘H-bot’ design to move the robot’s paddle. Held in a 3D-printed housing, the paddle is moved around using a pulley and belt system, with two stepper motors controlled by an Arduino Micro. “[The H-bot design] is really the best solution for this problem as both steppers are stationary,” explains Dominik.
Look and learn

The processing power for the robot’s optical puck recognition and AI strategy is provided by a Raspberry Pi 4. It is connected to a Camera Module V1 mounted in the overhead part of the frame, along with LED strips to ensure good lighting. With the camera capturing frames at around 80 fps, OpenCV is used to recognise the bright green puck so its position can be determined.
For the robot’s strategy, Ondřej and Dominik originally planned to use machine learning. That proved a step too far, however, given all the other fine-tuning issues that they faced in making the project. “Using machine learning was the plan from the beginning,” says Ondřej. “But, trust me. We tried. We tried a lot to make it work. But it was literally impossible to implement, given how hard it is to train an agent in such a complex state space with even more complex action space.”
Instead, they manually programmed four types of strategies with slightly different algorithms – you can find the code on GitHub.
The project’s Raspberry Pi is also connected to a touchscreen with a GUI made using Kivy. Apart from the purposes of setting up the game and keeping score, this makes it possible to “set all kinds of parameters ranging from camera properties/calibration and motor speeds to the type of strategy,” explains Ondřej.
The Air Hockey Robot was a very complicated and time-consuming project, but the result is indeed a brilliant piece of engineering and programming, where only the quick-witted can win. So, how often have they actually beaten the robot? “30-40% of the time. More at the beginning when things were not tuned out,” says Dominik. “But, it got harder and harder. Especially for the not so good players that we are.”
Subscribe to Raspberry Pi Official Magazine
Save up to 37% off the cover price and get a FREE Raspberry Pi Pico 2 W with a subscription to Raspberry Pi Official Magazine.
More articles

Unusual tools: corner‑cutting shear
The tool that makes cutting corners at work an acceptable practice.
Read more →

‘Friends’ – a Raspberry Pi-powered self‑balancing sculpture
This trio of robots was part of an exhibition called ‘Que Rien Ne Bouge’, which means ‘Let Nothing Move’.
Read more →

Starter Electronics in Raspberry Pi Official Magazine 157
After you’ve built your own simple circuit, why not think a little bit bigger – like building a product, and getting that product verified as officially Powered By Raspberry Pi? We take a look at some of the brilliant gadgets with Raspberry Pi at their heart. If you want to build a submarine, you might […]
Read more →
Sign up to the newsletter
Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.