Read The Times Australia

Daily Bulletin

How we built an Arduino-powered ping pong scoreboard

  • Written by: Mark Cipolla, Senior Developer & Content Platform Project Coordinator, The Conversation

At The Conversation, we take table tennis very seriously. After setting up a new ping pong table, and wanting to learn how to use an Arduino, I had a bit of time to build a scoreboard.

An Arduino is a small, programmable device that can take inputs (in this case, two buttons) and control outputs (a LED screen to show the score).

The Arduino, and the components we used

The Arduino board is a relatively cheap one; at A$29, it’s a steal. It’s a great starting board, and easy to get your head around.

The LED matrix is a 32x16 display (512 LEDs in total). It provides a set of pins at the back to wire it up to the Arduino. The wiring documentation is a bit tricky to find, so I’ll save you the trouble.

Nick Browne and I spent quite a while figuring out what buttons would be appropriate. Many were too small, or had a toggle state. Eventually, we settled on some that had the right feel; we were after a tactile, satisfying click.

Additionally, we also bought a number of small components. These aren’t quite the ones we bought, but the links show equitable parts.

Prototyping the idea

When we started prototyping, we used some push buttons to act as inputs to the digital pins on the Arduino.

During the ping pong game, each player pushes a button at their end of the table to increment their score after winning a point.

In the prototype, the buttons were a break in the circuit. Pushing the button connected the circuit, which we detected as the input.

image Arduino, with two small breadboards to prototype the buttons. Author provided

The buttons are wired into a digital input pin and an analog ground pin. I’ve used pins 2 and 3, as you will be able to see in the code later on.

Wiring up the LED matrix to the Arduino was a challenge. The cable provided didn’t work for us, and we think might have been faulty. We ended up using a bunch of individual wires.

image Arduino wired to the LED matrix. Author provided

Writing some C

Arduino is programmed in C, and runs a set of C/C++ functions. I’ve not written in a static-typed language before this project, nor a compiled one either, so this was new to me.

The Arduino looks for two specific functions, setup() and loop(). setup(), unsurprisingly, is run once and sets up the things you need for when the program is running.

Before you declare setup(), you can write a number of structs and constants.

All the data on a player, for example, can be written as a struct. Here’s a cut down version of it:

typedef struct Player {
  int pin;
  int buttonInputState;
  int buttonState;
  int score;
} Player;

We also set the constants that measure what state the game is in.

The setup() is where we’ve set up all the default values: it sets player1pin and player2pin to inputs, and tells your Arduino to listen on certain pins. digitalWrite lets you listen for certain voltages, and so, listen for button presses.

Then, we’re setting up the default values for the two player structs.

Here’s a cut down example of the setup() method in the code.

void setup() {
  // initialize the pushbutton pin as an input:
  pinMode(player1pin, INPUT);
  pinMode(player2pin, INPUT);
  digitalWrite(player1pin, HIGH);
  digitalWrite(player2pin, HIGH);

  for (int i = 0; i < NUMBER_OF_PLAYERS; i++) {
    players[i].buttonInputState = LOW;
    players[i].buttonState = UNPRESSED;
    players[i].score = 0;

    // the last time the output pin was toggled
    players[i].lastDebounceTime = 0;
  }
}

We use constants to set the states, and the loop() progresses to the correct state once each small method is completed.

const int GAME_WAITING = 0;
const int GAME_START = 1;
const int GAME_ON = 2;
const int GAME_OVER = 3;

The loop() is what runs continuously, and we’re using a variable named game_state to know which stage of the game we’re at. It then runs smaller methods that control each stage.

void loop() {
  switch(game_state) {
    case GAME_WAITING :
      game_state = wait_for_players();
      break;
    case GAME_START :
      game_state = tell_players_its_on_like_donkey_kong();
      break;
    case GAME_ON :
      game_state = game_on();
      break;
    case GAME_OVER :
      game_state = game_over();
      break;
  }
}

The GAME_WAITING state scrolls text across the screen telling the players that pressing both buttons will start. It listens for the two simultaneous button presses, and if both pressed, sets the state to GAME_START.

The GAME_START state flashes START on the screen for five seconds, giving the players a chance to get ready! Once this timer is done, it sets the state to GAME_ON.

The GAME_ON state does the majority of the work in the program. It listens for buttons pushes and then increments the count. Then, it draws the scores on the LED matrix.

It keeps track of the scores, checking if either score is above 21, and if a player’s score is more than two points greater than the other. If these conditions are met, it sets the state to GAME_OVER.

The GAME_OVER state figures out who won, and shows either P1 WINS or P2 WINS. Then, after waiting for a few seconds, it resets the state to GAME_WAITING.

I’ve made the source code for the Arduino available in a GitHub repository. Please take a look!

Wiring everything up

We simplified how buttons worked as inputs. We were able to remove the resistors and use the internal ones available on the Arduino’s digital inputs.

pinMode(pin, INPUT);     // set pin to input
digitalWrite(pin, HIGH); // turn on pullup resistors

The buttons keep the circuit connected, and pushing the button broke the circuit, which we used to detect the input.

image Wiring schematic of the buttons connected to the Arduino. Author provided

We soldered everything together, adding a small prototype circuit board to organise the wiring from the Arduino to the two 3.5mm headphone jack pins.

image The circuit board, with wires running from the Arduino to the two 3.5mm headphone jacks. Author provided

From the headphone jacks, we ran two 3.5mm male to male cables. These connected to two other 3.5mm headphone jacks, fixed into plastic enclosures that also held the buttons.

image The enclosures, with buttons on one side, and a headphone jack on the other, before they’re wired up. Author provided

I’m a bit of an amateur woodworker, so I made up a pine frame to fit the LED matrix panel. Four sides, each with 45 degree cuts, and some small brackets to fit them together.

A little sanding and varnishing, and it looks pretty good.

The finished product

With the LED matrix fitted into the timber enclosure, we’re ready to turn it on and do some testing!

image Enclosure with the LED matrix fitted. Author provided

As you can see in the movie below, both players have to press their buttons simultaneously to start the game. Once it’s started, each player pushes their buttons to increment their score after winning a point.

Once a player has more than 21 points, and has two more than their opponent, we have a winner!

Button pressing in action!

Authors: Mark Cipolla, Senior Developer &amp; Content Platform Project Coordinator, The Conversation

Read more http://theconversation.com/how-we-built-an-arduino-powered-ping-pong-scoreboard-69401

Business News

How Telematics Helps Australian Companies Improve Productivity

Operating a commercial fleet in Australia is a uniquely demanding endeavour. Between the sprawling urban sprawl of cities like Sydney and Melbourne and the immense, unforgiving stretches of the Outb...

Daily Bulletin - avatar Daily Bulletin

Inside the Icon: The BridgeMuseum Officially Opens at the Sydney Harbour Bridge

A bold new way to experience one of Australia’s most recognisable landmarks has arrived, with BridgeClimb Sydney officially opening the all-new BridgeMuseum.  Located inside the Sydney Harbour Brid...

Daily Bulletin - avatar Daily Bulletin

Is Your Brand Showing Up in AI Search? Most Melbourne Brands Aren't.

The New Front Door Nobody Told You About Something changed. Quietly. Without a press release. The way buyers find businesses in Australia has been rewired. Not replaced, rewired. Google isn't dead...

Daily Bulletin - avatar Daily Bulletin

How Australian Businesses Can Measure SEO ROI

SEO can feel vague when you are staring at a dashboard full of numbers that do not clearly connect to revenue. The key is to measure the right signals in the right order, then tie them back to outcome...

Daily Bulletin - avatar Daily Bulletin

How Commercial Roller Shutters Improve Site Security Without Slowing Operations

Security upgrades can be frustrating when they make everyday work harder. A door that takes too long to open, creates bottlenecks at shift change, or fails at the worst time can turn “better protectio...

Daily Bulletin - avatar Daily Bulletin

Why a Document Destruction Service Still Matters for Modern Businesses

Businesses generate large volumes of information every day, from staff records and contracts to invoices, reports and customer files. While attention often focuses on how documents are stored, the way...

Daily Bulletin - avatar Daily Bulletin

Bicycle Rack Safety and Space-Smart Storage

Bike storage problems usually show up as small annoyances first: tangled handlebars, scratched frames, and bikes that topple when you pull one out. Over time, those issues become safety risks, especia...

Daily Bulletin - avatar Daily Bulletin

How to Tell if a Childcare Centre Is a Good Fit for Your Child

Choosing childcare can feel like you’re making a huge decision with limited information. Tours are short, centres are often on their best behaviour, and your child might act differently in a new space...

Daily Bulletin - avatar Daily Bulletin

Car Import Timeline: What Usually Happens at Each Stage

Importing a car into Australia can feel confusing because multiple agencies and checkpoints are involved, and the timeline is shaped as much by paperwork quality as it is by shipping speed. The most u...

Daily Bulletin - avatar Daily Bulletin

The Daily Magazine

Gold Migration Lawyers in Liquidation: How the Closure Affects Your ART Appeal

If your appeal was with Gold Migration Lawyers, a recent change to how the Tribunal decides cases ...

The pressure cooker: life in urban Australia in 2026

Australian cities have always been demanding. Long commutes, rising housing costs, busy schedules a...

What Actually Makes a Good Criminal Lawyer in Melbourne

Most people only think about this question once. That is usually too late. Most people charged wi...

Why Working With A Chatswood Tutor Can Improve Academic Performance

Academic expectations continue increasing for students across primary school, high school, and senio...

Is It Worth Getting Solar Panels in Melbourne?

The real question is not whether solar works in Melbourne. It works. The question is what it is co...

How A Diploma Of Project Management Builds Practical Skills For Modern Work Environments

Developing the ability to plan, execute, and deliver outcomes efficiently is a key requirement in to...

How to Choose the Right Football for Every Level

Choosing a football may seem straightforward, but the right option depends on who will be using it a...

What to Ask a Wedding Photographer Before You Book

Booking a wedding photographer can feel deceptively simple: you like the photos, you like the vibe...

Why Stress Relief For Dogs Is Essential For Emotional Balance And Long-Term Wellbeing

Managing emotional health is just as important as physical care when it comes to pets, which is why ...