Fusball scoreboard using UNO R3 Super Start Kit

Hi,

Complete beginner here, trying to create a Table Football/Foosball score board.

I first want to make a prototype using the Superstarter kit, that uses a ultrasonic sensor to detect the ball, and then have a 1 digit seven segment to update the score.

Then, I would like to add in another sensor for the other goal, have two 2-digit seven segment displays on each side, an on/off switch, and a reset button.

Can anyone please suggest how I can go about connecting it all up and developing the code for it?

List of equipment:

  • UNO R3
  • 1 digit 7 segment display
  • 4 digit 7 segment display
  • Ultrasonic sensor
  • NPN transistors x2
  • selection of resistors
  • LCD display
  • 830 breadboard, M-F, M-M wires
  • Button x5
  • 74HC595
  • L293D

Thank you!

Hi - when is the issignment due? This will make a difference to the information I provide. :wink:

Hi, no deadline at all, thank you for your reply :slight_smile:

Create a program flow diagram to visalize what your program should do.
Take into consideration

  • recognize the ball in the goal
  • count the score upwards
  • think about "debounce", to make your goal recognition reliable
  • don't forget to introduce some reset to zero the goal counter
  • learn about arrays to avoid code duplicates when you need a second ball detection and a second display.

A good program starts with paper - not code.

important sketches in the Arduino IDE

State change detection
Debounce
Blink without Millis.

1 Like

Nice, First you need to read an Electronics 101 book, or follow a course on-line to understand electronics basics. Then read and understand the examples supplied with the IDE. When you have a basic understanding of both, draw a flow diagram of the code, and get each part working before going on to the next. With an hour or so a day and a few more at the weekends, you should have a working prototype in 6 - 8 weeks.

1 Like

For the Dive-right-in approach.

Try the examples in the IDE
Get a feel about how the sketch flows.

Take one sensor.
Connect it and run through the tutorial.

Play with the sensor to understand it's strength and weakness.

Then connect a digit.
Work the tutorials on how to use it.

Save you code at that point.
Add comments to the beginning of the code.
Make a copy and add the next thing.

When that is working. SAVE and comment.

I add revison level. r1 r2 at the end.

As you get stuck. Post your code here
Important: read how to post code with code-tags

I'm not sure that an ultrasonic sensor is a good choice for detecting the ball. I can think of at least 3 reasons:

  1. This type of sensor sends out a pulse of sound and measures how long it takes to travel through the air, bounce off an object and travel through the air back to the receiver. The pulses would need to go out at many hundreds of times per second to avoid missing the ball. I don't know if they can go fast enough.

  2. These sensors have a minimum detection distance, which may be longer than the width of the goal.

  3. They are designed to measure distance, and you don't care about that, you only need to detect the ball entering the goal.

So by all means spend some time testing the ultrasonic sensor, but I think a different type of sensor will be more appropriate. An optical beam brake sensor for example. This would consist of an led, perhaps IR, on one side of the goal, and a sensor such as an photo-transistor on the other side.

If you have an IR sensor.
The type with two LED looking things.

You can desolder one add wire and move it some distance away and point it at the other.

The ball passing between will break the beam.

Get one of these (or 2) and get it working first. The rest, adding one to a count and displaying it on a 7-segment display, is straightforward.
https://www.digikey.com/en/products/detail/tt-electronics-optek-technology/OPB100Z/1636780


You can wire up a couple of 74HC595s to drive common anode or common cathode displays. I'd recommend TPIC6B595 or TPIC6C595 shift registers and common anode displays, they do not have the 70mA total current limit (Vcc and Gnd pins) that the 74HC595 has. You can also drive more current, and higher voltage if you wanted to use larger digits.

If you want a 2nd digit, connect Clock and Latch to both devices and DataOut from the first device to DataIn on the 2nd.
This display for example uses TPIC6595s to drive 3 and 6-LED segments from 12V.

int dataPin = 0;
int latchPin = 1;
int clockPin = 2;
int switchA = 12;
int switchB = 13;
int switchC = 11;
int irSensor = A0;
byte counterA = 0;
byte counterD = 0;
byte counterB = 0;
int blueArray[4] = {3, 4, 5, 6};//Defines PWM pins that activate each digit
int redArray[4] = {7, 8, 9, 10};
int digitArray[4] = {0,0,0,0}; 
int intArray [10]= 
{
  B01111110,  // 0
  B00001100,  // 1
  B10110110,  // 2
  B10011110,  // 3
  B11001100,  // 4
  B11011010,  // 5
  B11111000,  // 6
  B00001110,  // 7
  B11111111,  // 8
  B11001111   // 9
};
void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin,  OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(switchA, INPUT_PULLUP);
  pinMode(switchB, INPUT_PULLUP);
  pinMode(switchC, INPUT_PULLUP);
  pinMode(irSensor, INPUT_PULLUP);
  digitalWrite(latchPin, HIGH);
  shiftOut(dataPin, clockPin, MSBFIRST,intArray [0]);
  digitalWrite(latchPin, LOW);
  displayOn();
}
void loop() { 
  displayOff();
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST,intArray[digitArray[counterD]]);
  analogWrite(blueArray[counterD], 0);
  analogWrite(redArray[counterD], 0); 
  digitalWrite(latchPin, HIGH);
  delay(1);
  counterD++;
  if (counterD ==4) {
    counterD = 0;
    }
  
  if (digitalRead(switchA) == LOW){
    counterA ++;
      if (counterA > 9) {
      digitArray[2]=counterA/10;     
      digitArray[3]=counterA%10;
      }
      if (counterA>99){
        counterA = 0;
      }
    delay(1);
  }

    if (digitalRead(switchB) == LOW){
    counterB ++;
      if (counterB > 9) {
      digitArray[0]=counterB/10;     
      digitArray[1]=counterB%10;
      }
      if (counterB>99){
        counterB = 0;
      }
    delay(1);
  }
  if(digitalRead(switchC) == LOW){
    for (int i = 0; i <4; i++){
      digitArray[i] = 0;
      }
        delay(1);
    } 
    if (digitalRead(irSensor) == LOW){
      counterA ++;
        if (counterA > 9) {
        digitArray[2]=counterA/10;     
        digitArray[3]=counterA%10;
        }
        if (counterA>99){
          counterA = 0;
        }
      delay(1);
    }
}

void displayOff() {
  analogWrite((blueArray[0]),255);
  analogWrite((blueArray[1]),255);
  analogWrite((blueArray[2]),255);
  analogWrite((blueArray[3]),255);
  analogWrite((redArray[0]),255);
  analogWrite((redArray[1]),255);
  analogWrite((redArray[2]),255);
  analogWrite((redArray[3]),255);  
}

void displayOn() {
  analogWrite((blueArray[0]),0);
  analogWrite((blueArray[1]),0);
  analogWrite((blueArray[2]),0);
  analogWrite((blueArray[3]),0);
  analogWrite((redArray[0]),0);
  analogWrite((redArray[1]),0);
  analogWrite((redArray[2]),0);
  analogWrite((redArray[3]),0);  
}

I've got it to now display the home and away score on the two 4-digit-segment displays, controlled by one 75HC595, a reset button (switch C), two testing switches to update the score (switch A and B) and also one IR beam sensor to update the score.

It all works great, except that when the IR beam is intercepted/test switches pressed, the score updates during the entire duration of the appropriate pins pulled low.

Is there a way for me to only update the score by 1 increment at a time, for each IR beam interception/button press.

Thanks

This is coding. Of course there is! :grin:

look at the switch de-bounce example.
that is the solution.