Basketball smartboard endlessly transmits shot scored

I’ve been working on trying to get this arduino project I found to work but I’ve been encountering some problems.

The project was designed for an Arduino mega 2560 but I’ve been using my UNO and breadboard for it along with the Software Serial library. I’m very, very new(first project) to working with Arduinos so if there are any basic things I might be missing please do mention them.

Components:

  • Arduino UNO
  • Bluetooth HC-05 module
  • E18-D80NK Proximity Sensor
  • Saeed Grove 420 Proximity Sensor
  • 10k Ohm resistor
  • Breadboard
  • The included app in the above link

The issues I’m facing are

a)Initially, the proximity sensor would detect if I e.g. moved my hand infront of it and send the data to the app and it would increment the score and play the sound. However, somehow it now just keeps endlessly transmitting that a shot has been scored and it keeps incrementing.

b)If I try flicking the vibration sensor and not moving my hand infront of the proximity sensor, a miss wouldn’t be recorded. Initially, even just flicking the proximity sensor would record a score as well, but later it would just do nothing.

Also, the code I’ve pasted below is after including the SerialSoftware library header and after deleting all the code for setting the LED lights which is still available in the link above. Just didn’t want to include the LEDs in my project.

Any help would be really appreciated, thank you!! If there’s any information I’ve missed out on, please let me know.

#include <SoftwareSerial.h>
SoftwareSerial Serial1(10, 11); // RX, TX

//----------------------------------------------------------------------------//
// Filename : Scoreboard.ino //
// Description : Smart Basketball Scoreboard //
// Version : 1.1.0 //
// Author : Marcelo Avila de Oliveira marceloavilaoliveira@gmail.com //
//----------------------------------------------------------------------------//

//----------------------------------------------------------------------------//
// DEFINITIONS //
//----------------------------------------------------------------------------//

// TURN ON DEBUG MODE
// #define DEBUG
// #define DEBUG_PROX
// #define DEBUG_VIBR

//----------------------------------------------------------------------------//
// CONSTANTS //
//----------------------------------------------------------------------------//

// PINS
const int prox_pin = 2;
const int vibr_pin = 3;

// TIME
const unsigned long wait_interval = 3000;

//----------------------------------------------------------------------------//
// VARIABLES //
//----------------------------------------------------------------------------//

// TIME
unsigned long wait_time;

// STATUS
boolean prox = false;
boolean vibr = false;
boolean wait = false;

//----------------------------------------------------------------------------//
// FUNCTIONS (SETTINGS) //
//----------------------------------------------------------------------------//

void setup() {
// INITIATE PINS
pinMode(prox_pin, INPUT);
pinMode(vibr_pin, INPUT);

// INITIATE SERIAL COMMUNICATION
Serial.begin(9600);

// INITIATE BLUETOOTH COMMUNICATION
setup_bluetooth();

#ifdef DEBUG
Serial.println(“Board is alive”);
Serial.println();
#endif
}

void setup_bluetooth() {
#ifdef DEBUG
Serial.println(“Setting Bluetooth”);
Serial.println();
#endif

Serial1.begin(38400); // Set baud rate
Serial1.print("\r\n+STWMOD=0\r\n"); // Set to work in slave mode
Serial1.print("\r\n+STNA=Arduino\r\n"); // Set name
Serial1.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
Serial1.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
Serial1.print("\r\n+INQ=1\r\n"); // Make the slave inquirable
delay(2000); // This delay is required.
while (Serial1.available()) { // Clear data
delay(50);
Serial1.read();
}
}

//----------------------------------------------------------------------------//
// FUNCTIONS (CHECK) //
//----------------------------------------------------------------------------//

void check_prox() {
if (!prox) {
if(digitalRead(prox_pin) == LOW) {
#ifdef DEBUG_PROX
Serial.println(“Proximity detected”);
Serial.println();
#endif

prox = true;
if (!vibr) {
wait = true;
wait_time = millis() + wait_interval;
}
set_shot(1);
}
}
}

void check_vibr() {
if (!prox && !vibr) {
if(digitalRead(vibr_pin) == HIGH) {
#ifdef DEBUG_PROX
Serial.println(“Vibration detected”);
Serial.println();
#endif

vibr = true;
wait = true;
wait_time = millis() + wait_interval;
}
}
}

void check_wait() {
if (wait && millis() > wait_time) {
if (!prox) {
set_shot(0);
}
reset();
}
}

//----------------------------------------------------------------------------//
// FUNCTIONS (MIS) //
//----------------------------------------------------------------------------//

void set_shot(int mode) {
// MODE:
// 0 = WRONG SHOT (MISS)
// 1 = RIGHT SHOT (SCORE)

Serial1.print(mode);
delay(1000);
}

void reset() {
vibr = false;
prox = false;
wait = false;
}

//----------------------------------------------------------------------------//
// MAIN //
//----------------------------------------------------------------------------//

void loop() {
check_prox();
check_vibr();
check_wait();
}

Alright, issue resolved. I hadn't set the correct baud rate in the Bluetooth setup portion. Should've been 9600.