Step by step instruction to add gate sensor to foosball (football table)
Here you can find circuit diagram and Arduino sketch for foosball sensors works with Scoreboard application
1- connect all wire as per below diagram to connect Bluetooth module HC-06 and IR obstacle modules FC-51 to Arduino Uno R3
2- Connect Arduino Uno R3 microcontroller to your computer via USB cable
3- Upload below mentioned sketch to Arduino and upload it to your Arduino Uno R3 microcontroller
4- Disconnect Arduino from computer
5- Connect 9V battery to barrel connection
6- Go to your smartphone Bluetooth menu and search for new devices
7- Find HC-06 Bluetooth devise and pair it with your smartphone
8- Open Scoreboard application and tap on "Connect" button
9- Select HC-06 from paired device list and done, Scoreboard app must be to communicate with sensors and change the score every time any object (here foosball ball) pass in front of sensors
And here is the Arduino Sketch you have to upload to your Arduino microcontroller to make Scoreboard application able to communicate with gate's sensors
/*
Project: Connect Foosball gate sensor to Arduino
Bluetooth HC-06 ZS-40 module to detect score by using Scoreboard android
application developed by EACentury21
Function: Connect
the HC-06 ZS-40 module and communicate using the serial monitor
The HC-06
enters AT mode by default when powered on.The default baud rate is 9600.
The HC-06
requires all AT commands to be in uppercase. NL+CR should not be added to the
command string
It must be
No line editing selected in serial monitor and 9600 bps.
Pins
Arduino - Bluetooth HC-06 ZS-40
5V pin VCC pin
GND pin GND pin
RX pin to Arduino Digital
1 TX pin through a voltage divider
TX pin to Arduino Digital
0 RX pin (no need voltage divider)
interrupter pin 2
for blue team foosball gate
interrupter pin 3
for red team foosball gate
*/
//*********************************************************************
#include <SoftwareSerial.h>
//**********************************************************************
SoftwareSerial BTserial(0, 1); // RX | TX
// connect the HC-06 TX to the Arduino RX on pin 0.
// connect the HC-06 RX to the Arduino TX on pin 1. Through
a voltage divider.
const int encoderInRed = 2; // Red team input pin for the interrupter
const int encoderInBlue = 3; // Blue team input pin for the interrupter
const int statusLED = 13; // Output pin for Status indicator
int detectStateRed=0; // Variable for reading the sensor
status
int sensorStateRed = 0; // Current state of the sensor
int lastSensorStateRed = 0; // Previous state of the sensor
int detectStateBlue=0; // Variable for reading the sensor
status
int sensorStateBlue = 0; // current state of the sensor
int lastSensorStateBlue = 0; // previous state of the sensor
void setup()
{
BTserial.begin(9600);
Serial.begin(9600);
pinMode(statusLED,
OUTPUT); //Set pin 13 as output
pinMode(encoderInRed, INPUT);
//Set pin 8 as input
pinMode(encoderInBlue, INPUT);
//Set pin 8 as input
}
void loop() {
// read the sensors
input pin:
sensorStateRed =
digitalRead(encoderInRed);
sensorStateBlue =
digitalRead(encoderInBlue);
// compare the
sensorState to its previous state
if (sensorStateRed
!= lastSensorStateRed) {
// if the state
has changed, increment the counter
if (sensorStateRed
== HIGH) {
BTserial.write("RG");
Serial.println("RG");
}
// save the current
state as the last state, for next time through the loop
lastSensorStateRed =
sensorStateRed;
}
// compare the
sensorState to its previous state
if (sensorStateBlue
!= lastSensorStateBlue) {
// if the state
has changed, increment the counter
if
(sensorStateBlue == HIGH) {
BTserial.write("BG");
Serial.println("BG");
}
// save the current
state as the last state, for next time through the loop
lastSensorStateBlue
= sensorStateBlue;
}
}

Comments
Post a Comment