Arduino Airhockey Table

by lloydB in Circuits > Arduino

543 Views, 1 Favorites, 0 Comments

Arduino Airhockey Table

airhockey table.jpg
Airhockey Back.jpg

Have you always wanted an air hockey table at home but didn't know how to make one? This easy self-made mini air hockey table is here to help you out, made possible by the Arduino Uno Rev3!

Supplies

1.Arduino supplies

a. Arduino Uno rev3

b. 3, 12V fans

c. 16x2 LCD display with I²C interface

d.8 1.5 V batteries and a holder for them

e. circuit board

f. buzzer

g. 2 lasers and laser recievers

h. 30 or more jumper cables or normal wires

i. Switch

2.Materials

a.4 pieces of sturdy wood for the walls

b. 2 flimsy pieces of wood for the airflow

c. 4 thin pieces of wood for support for the play area

d. a long thin piece of wood for the play area

3.Software

a. arduino IDE or a similar program

(b. Fritzing for the circuit board, optional)

4.Misc

a. a 5V power supply (pc, powerbank etc)

b. screws and nails

c. equipment to use the items from 'b.'

d. a thin plastic sheet for better airflow

e. a 3D printed or useable puck and 2 pushers

Crafting the Box

Airhockey plate.jpg
table airhockey.jpg

First, we'll create the frame of the box. Take two long pieces of wood and cut them into sections measuring 51 x 10.2 cm each. Then, cut two shorter pieces to dimensions of 29.4 x 10.2 cm. Now, to strengthen the frame, attach wooden strips along all four sides. These strips should be positioned about 7 cm from the edges and should measure 1.2 cm in height and matching the length of the sides, you can proceed to tighten the box with screws..

Next, we'll set up the play area. Take two thin pieces of wood. On one piece, draw three squares evenly spaced for fans. Cut out these squares and attach this piece to the frame. Add thin strips around the edges to help airflow. NOw put this on the wooden strips on the edges.

For ventilation, cut small holes about 1.5-2 mm apart on the second piece of wood. Cover it with plastic to prevent snagging, making sure to cut matching holes in the plastic. Finally, place this piece over the first one to complete the play area.

Next, let's create the goals. Cut approximately 11.5 cm from the shorter sides of the box. This ensures that the puck can easily go into the goals.You can either smoothen the wood around the goal area or make it slightly lower than the play area, this will ensure that the puck won't get stuck on the wood.

With these steps completed, you should now have a something like the picture above!

Fans

Fans Airhockey.jpg

Once the box construction is complete, the next step is to install the fans. Take out the playarea and turn it around, make sure that the plate with the sqaure holes is above. Now spread the fans equally as shown in the image, use the carved out bits as refrence. Next, position the battery holder above the middle fan and attach a switch to the side facing the battery holder. Fuse all the components together using wires, preferably using black wires for ground and red wires for power. After connecting the fans to the battery holder, wire the battery holder to the switch that sticks out from the wooden hull. Insert the batteries, and your airflow system should work!

With these steps, your airflow system is now set up and ready to use.

Coding and Wiring

LCD screen.jpg
arduino.jpg

In the next phase, we need to know and confirm the functionality of all components before proceeding to use them into the box. To make this easier, I'll provide the used code for this project in a '.INO' format that also uses the wired schematic provided above or you can use Fritzing for this if you have the application. It's strongly recommended to test this code with an Arduino and a breadboard initially to make any errors easier to fix and prevents any unnecessary damages to the circuit or box.

You can change the following items in the code if you want to:

  1. Buzzer Tones: The code uses seven tones that goes higher each time in pitch, except for the last three notes. You can change these tones to whatever you want. The tones will be activated when a player scores.
  2. Player Identification: Players are denoted as "speler 1:" and "speler 2:". Feel free to change these identifiers to your satisfaction. These texts will be displayed on the LCD screen, make sure to make it not too big or the score count won't fit anymore.
  3. Pin Modes: While you have the option to modify the pin modes of components, remember that any changes you made also needs corresponding adjustments in both the code and the circuit blueprint.

In the code there are a few lines that will say 'include'. Make sure that you have installed all necessary libraries in the Arduino IDE to enable the proper functioning of the code's functions. Most of the names will correspond with the the code.

By testing the provided code with Arduino and a breadboard initially, you can identify and resolve any potential issues before finalizing it on the circuit and box. This step is critical for any troubleshooting and integration of the airflow system.


Code:

#include <LiquidCrystal_I2C.h> // Library for LCD
#include <Wire.h>

#define laser1 2
#define laser2 5 // Pin for the second laser
#define sensor1 3
#define sensor2 6 // Pin for the second sensor
#define buzzer 12

int score1 = 0;
int score2 = 0;
bool score2Triggerd = false;
bool score1Triggerd = false;

float oldTime;
float currentTime;
float deltaTime;

LiquidCrystal_I2C lcd(0x27, 16, 2);

int noteIndex = 0;
float noteTimer = 125;
bool playNotes;
bool isOn;

void setup() {
 Serial.begin(9600);
 pinMode(laser1, OUTPUT);
 pinMode(sensor1, INPUT_PULLUP); // Use internal pull-up resistor
 pinMode(laser2, OUTPUT);
 pinMode(sensor2, INPUT_PULLUP); // Use internal pull-up resistor
 pinMode(buzzer, OUTPUT);
 digitalWrite(laser1, HIGH);
 digitalWrite(laser2, HIGH);
 lcd.init();
 lcd.backlight();
}

void PlaySound() {
 if (!playNotes) return;

 int notes[] = { 260, 360, 460, 560, 750, 750, 750 };
 noteTimer -= deltaTime;
 if (noteTimer <= 0) {
  if (!isOn) {
   tone(buzzer, notes[noteIndex / 2]);
  } else noTone(buzzer);
  isOn = !isOn;

  Serial.println(sizeof(notes));
  noteTimer = 125;
  noteIndex++;

  if (noteIndex >= 7 * 2) {
   noteIndex = 0;
   playNotes = false; // Reset playNotes to false after playing the sound
  }
 }
}

void loop() {
 oldTime = currentTime;
 currentTime = millis();
 deltaTime = (currentTime - oldTime);
 PlaySound();

 bool value1 = digitalRead(sensor1);
 bool value2 = digitalRead(sensor2);

 if (value1 == HIGH && !score1Triggerd) {
  score1++; // Increase score of "Speler 1"
  score1Triggerd = true;
  playNotes = true; // Set playNotes to true for player 1
  PlaySound();
 } else if (value1 == LOW && score1Triggerd) score1Triggerd = false;

 if (value2 == HIGH && !score2Triggerd) {
  score2++; // Increase score of "Speler 2"
  score2Triggerd = true;
  playNotes = true; // Set playNotes to true for player 2
  PlaySound();
 } else if (value2 == LOW && score2Triggerd) score2Triggerd = false;

 // Display player scores on LCD
 lcd.setCursor(0, 0);
 lcd.print("Speler 1: ");
 lcd.print(score1);

 lcd.setCursor(0, 1);
 lcd.print("Speler 2: ");
 lcd.print(score2);
 // Delay for readability and to reduce LCD flickering
}

Downloads

Circuitry and Implementation

circuit.jpg
Airhockey circuit.jpg
FKHRK88LU5J56C9.jpg

To make sure we don't lose track of where everything goes, let's create a simple circuit blueprint. You can either use the one i provided above or make your own. Just be sure to label all the connections so you can follow the wires more easily.

Once the wiring is done, make sure that everything is connected properly from the Arduino to the circuit and from the circuit to the components. Also, make sure the pins are in the right spots on the Arduino. You can use Fritzing for this if you have the application.

Use some tie wraps or something similar to bundle the wires together. This will keep them from getting tangled in the fans and it makes the box a bit nicer to look at.

When everything's in place, The final setup should look something like the last picture provided above.

Finishing the Box and Putting the Components In

FEA22Z1LU5J55K5.jpg
FPKV0R6LU5J56AO.jpg
FKHRK88LU5J56C9.jpg
ITTT VIDEO

Now that most of the heavy lifting is done, let's finish up the remaining tasks. First up, let's finish the lasers. Carefully attach them to the sides of the goals using glue, nails, or screws, ensuring that they reach their respective receivers. This step is crucial for the goal detection. Once the lasers are in place, it's time to craft your puck goal or net. Make sure it's made so it intercepts the laser every time the puck passes through, ensuring that each point is counted. Once everything is secured, you should have two goals that are fully functional.

Next, let's set up the LCD screen. Create a small box in the middle of the long side piece of wood, opposite to the switch. Carefully attach the LCD screen to this box using glue, nails, or screws.

The final result should look like something like the pictures above, but feel free to customize and tweak as you see fit.

Enjoy!!

Experiments, Errors and Notable Observations

BuzzerLaser arduino airhockey.jpg
rn_image_picker_lib_temp_6c400107-6361-4f39-9eb3-1de9ba7de59e.jpg
IMG_20240325_180332.jpg

During the process of creating this project, I encountered a lot of new experiences. This was my first project with a Arduino, and I had to learn everything within a short span of weeks. Initially, I started with understanding the Arduino IDE and its coding, which was a steep learning curve since i was used to java coding.

Constructing the box and implementing the circuitry proved to be challenging and sometimes it was very painful to restart. There were moments of frustration, such as having to redo certain parts of the box multiple times due to oversights in measurements or other complications. Issues like incorrect height for the airflow or pieces of wood being cut too short and broken wood that were damaged by screws.

Secondly, many of my initial ideas had to be shelved due to practical limitations. For example, plans to use a switch to control the fans for added player interactivity had to be abandoned. Similarly, I had to make compromises such as using a smaller table due to limited wood availability.

Soldering the Arduino was particularly nerve-wracking, as I was aware that one wrong move could destroy the entire project. Luckily that didnt go wrong, i got a tip to make sure that everything was correct on paper, if i needed to double check something i could simply take the piece of paper and make sure i didn't do anything wrong, by doing that it would lower my stress significantly and made me think more clearly.

Despite the challenges, I did learn a whole lot of new things. While I had spend €40 extra to complete the project on time, i would say that there was a lot of satisfaction when it was completed. With the amount of knowledge i gained during this project i would say that i could do this project again with (less) errors then before and possibly faster.

(Note: The attached images serve as documentation of experimentation and mistakes and are NOT intended for inclusion in the final project.)