Project showcase
Automatic Arduino Goal Counter for Table Football/Soccer

Automatic Arduino Goal Counter for Table Football/Soccer © GPL3+

With photocells in both goals and a bright LED-display on the table, a USB powerbank provides action for at least 30 hours.

  • 5 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
Adafruit 0.56" 4-Digit 7-Segment Display w/I2C Backpack - Red
We mounted the disply inside a sturdy plastic housing, intended for electric home installations, bought at some local DIY store.
Adafruit IR Break Beam Sensor - 3mm LEDs
Watch out. These sensors work on infrared and don't work in bright sunlight. No problem on an indoor table with the sensors inside the shaded goals.
11026 02
Jumper wires (generic)
Adafruit industries ada64 image 75px
Solderless Breadboard Half Size
Any small breadboard
USB Cable Power Switch
We bought an inexpensive 6000 mAh USB powerbank somewhere in town, 2 USB-cables and a USB power switch to be mounted on the display housing as main power switch.
Power switch
Any other solid switch could be used for a back to 0:0 button according to where you place it.

Necessary tools and machines

Flexible hand drill
We think it is necessary to mount the breakbeam sensors behind the metal sheet material of the goal housing. If mounted inside, they would break quickly hit by the balls. So thinking of a way to mount the sensors in your table comes before starting this project.

About this project

A teacher and a student invented an automatic goal counter for the table football at their school. The counter was realized in 2017 and has been working very well for the last 2 years (project update 2019)

Project description on the school website (in German)


Code for automatic goal counter using Arduino with Adafruit 7-segment display and breakbeam sensorsC/C++
  Code for automatic table soccer counter. By teacher Morgenthaler and student Leo at Swiss school
// 3 lines importing libraries for the Adafruit display 
#include <Wire.h>                                 
#include <Adafruit_GFX.h>                         
#include "Adafruit_LEDBackpack.h"

// Initailizing the 7-segment display 
Adafruit_7segment matrix = Adafruit_7segment();   

// Defining varialbes for the two goals
int Rot;                                          
int Blau;

// Defining Arduino's board-LED. For controlling purpose only during coding
#define LEDPIN 13                                 
// Defining the two pins the data connections of the breakbeam sensors 
#define SENSORPIN 4                               
#define SENSORPIN2 2  

// Defining the pin for the back to zero button                            
#define SENSORPIN3 7                              

 // Initalizing and defining states for the breakbeam sensors and the back to zero button 
int sensorState = 0, lastState=0;               
int sensorState2 = 0, lastState2=0;              
int sensorState3 = 0, lastState3=0;              
void setup() {        
  // Initializing Arduino's board LED for output                                                
  pinMode(LEDPIN, OUTPUT);                        
  // Initializing pin for input from breakbeam sensor                                               
  pinMode(SENSORPIN, INPUT);  
  // Activating the pullup resistor for this pin to make the two sensor states clear for Arduino                    
  digitalWrite(SENSORPIN, HIGH);                  

  // Same for other breakbeam sensor
  pinMode(SENSORPIN2, INPUT);                     
  digitalWrite(SENSORPIN2, HIGH);

  // Same for back to zero button
  pinMode(SENSORPIN3, INPUT);                     
  digitalWrite(SENSORPIN3, HIGH);

  // Start value for goals
  Rot = 0;                                         
  Blau = 0;

  //Define address for display

void loop(){                                      
  // Next 3 lines: Read and save states of the 2 sensors and the back to zero button                                               
  sensorState = digitalRead(SENSORPIN);           
  sensorState2 = digitalRead(SENSORPIN2);
  sensorState3 = digitalRead(SENSORPIN3);         

  // The following lines are for displaying the the goal values on the display.
  // This if argument prevents from displaying a zero with numbers under 10
  if(Rot / 10)
  // Display position 0 will show the first position of goal variable Rot
  matrix.writeDigitNum(0, (Rot / 10) );    
    // Display position 1 will show the second position of goal variable Rot      
    matrix.writeDigitNum(1, Rot % 10 );
    // A colon will be displayed between the two varialbes            
 // This if argument prevents from displaying a zero for other variable 
  if(Blau / 10)
    // Display position 3 will show the first position of goal variable Blau                     
    matrix.writeDigitNum(3, (Blau / 10) );   
    //  Display position 4 will show the second position of goal variable Blau     
    matrix.writeDigitNum(4, Blau % 10 );    
    // Display everyting above      

   // 3 if-else arguments following for the two breakbeam sensors and the back to zero button 
   // If sensor light beam is broken, system reads status low and turns the control LED on                                     
  if (sensorState == LOW) {                 
    digitalWrite(LEDPIN, HIGH);             
  // otherwise no power for the control LED
  else {
    digitalWrite(LEDPIN, LOW);            
  // If SensorState does not differ from lastState...
  // (The "!" reverses the signal state to function correclty.
  // Without it, the goal values constantly increase when light beams ar UNbroken)
  if (sensorState && !lastState) {                
    // ...The message Unbroken would be displayed on Arduino's serial monitor                                              
    Serial.println("1 Unbroken");                 
  // If it differs, "Broken" would be displayed and the goal variable Red is increased. 
  if (!sensorState && lastState) {
    Serial.println("1 Broken");                                                               
    Rot = Rot + 1;                                 
  // Same for other breakbeam sensor
  if (sensorState2 && !lastState2) {               
    Serial.println("2 Unbroken");
  if (!sensorState2 && lastState2) {
    Serial.println("2 Broken");
    Blau = Blau + 1;                              
  // Check status of back to zero button 
  if (sensorState3 && !lastState3) {               
  // If pressed, the serial display would show "reset" and both goal variables are reset to zero.
  if (!sensorState3 && lastState3) {
    Blau = 0;                                      
    Rot = 0;
    // Clears everything displayed on LED
 // Save the last sensor states 
  lastState = sensorState;                     
  lastState2 = sensorState2;                       
  lastState3 = sensorState3;
// End of programm. Restart void loop




Similar projects you might like

Automatic Door and Counter Prototype

Project tutorial by Francisc Camillo

  • 1 comment
  • 21 respects

RFID Based Automatic Door System

Project showcase by Robodia Technology

  • 134 respects

Automatic Room Light Controller with Bidirectional Visitor

Project showcase by Team Amrendra Sahni

  • 11 respects

Automatic Humidifier

Project showcase by chenwei19940207

  • 7 respects

4-Digit 7-Segment Counter with LiPo Backup

Project showcase by Ratti3

  • 4 respects

Automatic Gesture Controlled Table Lamp for Study

Project showcase by ashraf_minhaj

  • 6 respects
Add projectSign up / Login