OSZ Täuffelen
Published © GPL3+

Automatic Arduino Goal Counter for Table Football/Soccer

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

BeginnerShowcase (no instructions)10 hours11,309
Automatic Arduino Goal Counter for Table Football/Soccer

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
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.
×1
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.
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
Any small breadboard
×1
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.
×1
Power switch
Any other solid switch could be used for a back to 0:0 button according to where you place it.
×1

Hand tools and fabrication 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.

Story

Read more

Schematics

table_football_sWtHbxb8bn.fzz

Code

Code for automatic goal counter using Arduino with Adafruit 7-segment display and breakbeam sensors

C/C++
/* 
  Code for automatic table soccer counter. By teacher Morgenthaler and student Leo at Swiss school www.oszt.ch
*/
                                           
// 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
  matrix.begin(0x70);                              
}



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            
    matrix.drawColon(true);  
    
 // 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      
    matrix.writeDisplay();                       


   // 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) {
    Serial.println("reset");                       
    Blau = 0;                                      
    Rot = 0;
    // Clears everything displayed on LED
    matrix.clear();
  }
 // Save the last sensor states 
  lastState = sensorState;                     
  lastState2 = sensorState2;                       
  lastState3 = sensorState3;
}                                                  
// End of programm. Restart void loop

Credits

OSZ Täuffelen

OSZ Täuffelen

0 projects • 2 followers
Teacher at public school for kids aged 13 - 16 in Switzerland. Teaching mainly languages and doing computer or robotics technology projects.

Comments