How do I make a Scoring System my Arduino Project?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

How do I make a Scoring System my Arduino Project?

Post by animefruit »

Hello Bill.
This is Neal.
I am making Nerf Target Sensor Vests for my Nerf Tag game.

What I made happen is that when the piezo sensors senses pressure, the number of pressure is subtracted from a bigger number until it hits 0. And when it hits zero my servo closes a blind over the goggles of the person to tell them that they have been tagged. After a certain amount of time the blinds open back up so that the person can play again. Also there are LEDs that light up when the person is tagged. Also the numbers are displayed on a LCD the person wears as a watch.

Here is my code:

Code: Select all

     #include <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"


#define LED 13// FOR LED



Adafruit_LiquidCrystal lcd(0);

Servo myservo1;
Servo myservo2;

//cant do A4 and A5(they are for lcd)
// Analogs 0 to 5
const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;


const int threshold = 50;
int health = 500;

// 6 total sensor readings (from 0 to 5)

int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;


int pos =0;



int deaths=1;// gonna be number of deaths



void setup()

{
 // pinMode(LED_BUILTIN, OUTPUT); //LED ON ARDUINO
  pinMode(LED, OUTPUT);//FOR LED

  Serial.begin(9600);
  Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");

// sg90

  lcd.begin (20 , 4);
  lcd.clear();


  Serial.begin(9600);
  myservo1.attach(9);
  myservo1.write(0);//was 0

  myservo2.attach(10);
  myservo2.write(45);//was 179




}

void loop()
{
  do
  {


    myservo1.detach();
    myservo2.detach();

    sensorReading = analogRead(knockSensor);
    

    lcd.setCursor(0, 1);
    Serial.println(health);
    lcd.println(health);

    if (sensorReading > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading;

      
      
      Serial.print(sensorReading);
      lcd.print(sensorReading);


      int sensorValue = analogRead(A0);

      Serial.println(sensorValue);


      
      


      
      delay(1);

    }

//duplicate 

sensorReading1= analogRead(knockSensor1);

 if (sensorReading1 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading1;

      
      
      Serial.print(sensorReading1);
      lcd.print(sensorReading1);


      int sensorValue = analogRead(A1);

      Serial.println(sensorValue);


      delay(1);

    }

  

//duplicate

sensorReading2= analogRead(knockSensor2);

 if (sensorReading2 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading2;

      
      
      Serial.print(sensorReading2);
      lcd.print(sensorReading2);


      int sensorValue = analogRead(A2);

      Serial.println(sensorValue);


      delay(1);

    }


 

//duplicate 

sensorReading3= analogRead(knockSensor3);

 if (sensorReading3 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading3;

      
      
      Serial.print(sensorReading3);
      lcd.print(sensorReading3);


      int sensorValue = analogRead(A3);

      Serial.println(sensorValue);


      delay(1);

    }

 

//duplicate 



sensorReading4= analogRead(knockSensor4);

 if (sensorReading4 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading4;

      
      
      Serial.print(sensorReading4);
      lcd.print(sensorReading4);


      int sensorValue = analogRead(A6);

      Serial.println(sensorValue);


      delay(1);

    }

 

//duplicate 

sensorReading5= analogRead(knockSensor5);

 if (sensorReading5 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading5;

      
      
      Serial.print(sensorReading5);
      lcd.print(sensorReading5);


      int sensorValue = analogRead(A7);

      Serial.println(sensorValue);


      delay(1);

    }







  } while (health > 1);

  
  
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);//was 2000             // FOR LED IN ARDUINO
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
 
 
  /*
digitalWrite(LED, HIGH);
delay(2000);                 //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
 */
  myservo1.attach(9);
  myservo2.attach(10);

  delay(15);

 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);    // waits 15 ms for the servo to reach the position
  
  
  }

 delay(1000);


 lcd.setCursor(0, 2);
      Serial.println(deaths); //showind number of deaths on the lcd
      lcd.println(deaths);


deaths= deaths + 1;// adding deaths






  
  health = 500;
}
              
Now I made Two Nerf Target Vests with Arduino Nanos and I am wondering how to make a Scoring System for them.

I would like to do a basic scoring system like the ones used for laser tag when the score shows how many times the player has been tagged for both teams that will show up on the LCDs of their vest.

Do you know how I could do this?

It surely isn't too hard because laser tag has it.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: How do I make a Scoring System my Arduino Project?

Post by adafruit_support_mike »

Once your code has recognized a hit from the piezo sensor, your code can do anything with it. To count the number of hits, all you need to do is keep a global variable named 'hits' and add 1 to it.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I make a Scoring System my Arduino Project?

Post by animefruit »

Yes. But I want to have the scoring system connected to multiple vests so that it counts the number of hits for two teams just like laser tag.

Each vest has an Arduino Nano with Pezio Sensors.

I would think this means I need something to connect the Arduino Nanos wirelessly.

And than I can make it count the number of hits for each Nano wirelessly.

I would also like the the wireless connection to extend kind of far for my tag game.

How could I do this?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: How do I make a Scoring System my Arduino Project?

Post by adafruit_support_mike »

For wireless communication between boards, you'll want something like packet radio:

https://www.adafruit.com/?q=packet+radio&sort=BestMatch

You can give each board its own address, and use the addresses to select the board you want to talk to. Technically all the boards hear the transmission, but only the one whose ID matches the address in the transmission pays attention.

The transmission protocol is lightweight and good for situations like this, where you only want to send small amounts of data.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I make a Scoring System my Arduino Project?

Post by animefruit »

Ok. That sounds great.

But how do I give each board its own address, and use the addresses to select the board I want to talk to?

I can’t really find how to do that in this article about the RFM69 Packet Radio:

https://learn.adafruit.com/adafruit ... erview


Can you help me find out how to do that?

Can it talk to my Arduino Nanos?

Also , I am thinking of getting the Adafruit Feather M0 RFM69HCW Packet Radio - 433MHz - RadioFruit.

Link:
https://www.adafruit.com/product/3177

Is that a good choice?
Last edited by animefruit on Tue Nov 22, 2022 5:04 pm, edited 1 time in total.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: How do I make a Scoring System my Arduino Project?

Post by adafruit_support_mike »

You assign each board an address in its code, and choose the address of the board it wants to talk to in the code.

There are example sketches in the tutorials:

https://learn.adafruit.com/adafruit-rfm ... -breakouts

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I make a Scoring System my Arduino Project?

Post by animefruit »

Just to make this clear,

Do I have to connect each of my Arduino Nanos to a Radio Packet to talk to each other?

Or do I use One Radio Packet to talk to all my Arduino Nanos?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: How do I make a Scoring System my Arduino Project?

Post by adafruit_support_mike »

Each Nano needs a radio. Otherwise there's no way for them to communicate.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I make a Scoring System my Arduino Project?

Post by animefruit »

Ok. That’s what I will do.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I make a Scoring System my Arduino Project?

Post by animefruit »

I’m going to use these connections from this website for both of my Arduino Nanos:

https://learn.adafruit.com/adafruit ... wiring

Also I have a photos attached that shows the connections I will do from the website.

Just to make sure, will this work?
Attachments
CF09DE59-5EF5-4684-B4F3-3CFE84221E68.png
CF09DE59-5EF5-4684-B4F3-3CFE84221E68.png (284.64 KiB) Viewed 176 times
CA164D35-314F-43B7-A414-61E66EACC269.jpeg
CA164D35-314F-43B7-A414-61E66EACC269.jpeg (166.17 KiB) Viewed 176 times

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I make a Scoring System my Arduino Project?

Post by animefruit »

Ok.

I connected my Arduino Nano just like the image from the last post.

Although, now it seems like it is not working.

I am following the guide from this website:
https://learn.adafruit.com/adafruit- ... radio

I uploaded the code "RadioHead69_RawDemo_TX" after adding the "RadioHead file to my library.

Here is the code from the website:

Code: Select all

        // rf69 demo tx rx.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing client
// with the RH_RF69 class. RH_RF69 class does not provide for addressing or
// reliability, so you should only use RH_RF69  if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example rf69_server.
// Demonstrates the use of AES encryption, setting the frequency and modem 
// configuration

#include <SPI.h>
#include <RH_RF69.h>

/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
//#define RF69_FREQ 915.0
#define RF69_FREQ 433.0

#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     7
  #define RFM69_RST     4
  #define LED           13
  
#elif defined(ADAFRUIT_FEATHER_M0) || defined(ADAFRUIT_FEATHER_M0_EXPRESS) || defined(ARDUINO_SAMD_FEATHER_M0)
  // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
  #define LED           13
  
#elif defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
  #define LED           13

#elif defined(ESP8266)    // ESP8266 feather w/wing
  #define RFM69_CS      2    // "E"
  #define RFM69_IRQ     15   // "B"
  #define RFM69_RST     16   // "D"
  #define LED           0

#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #define RFM69_INT     9  // "A"
  #define RFM69_CS      10  // "B"
  #define RFM69_RST     11  // "C"
  #define LED           13

#elif defined(ESP32)    // ESP32 feather w/wing
  #define RFM69_RST     13   // same as LED
  #define RFM69_CS      33   // "B"
  #define RFM69_INT     27   // "A"
  #define LED           13

#elif defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17

#endif


/* Teensy 3.x w/wing
#define RFM69_RST     9   // "A"
#define RFM69_CS      10   // "B"
#define RFM69_IRQ     4    // "C"
#define RFM69_IRQN    digitalPinToInterrupt(RFM69_IRQ )
*/
 
/* WICED Feather w/wing 
#define RFM69_RST     PA4     // "A"
#define RFM69_CS      PB4     // "B"
#define RFM69_IRQ     PA15    // "C"
#define RFM69_IRQN    RFM69_IRQ
*/

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

int16_t packetnum = 0;  // packet counter, we increment per xmission

void setup() 
{
  Serial.begin(115200);
  //while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer

  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

  Serial.println("Feather RFM69 TX Test!");
  Serial.println();

  // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
  
  if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }
  Serial.println("RFM69 radio init OK!");
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(RF69_FREQ)) {
    Serial.println("setFrequency failed");
  }

  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:
  rf69.setTxPower(20, true);  // range from 14-20 for power, 2nd arg must be true for 69HCW

  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
  
  pinMode(LED, OUTPUT);

  Serial.print("RFM69 radio @");  Serial.print((int)RF69_FREQ);  Serial.println(" MHz");
}



void loop() {
  delay(1000);  // Wait 1 second between transmits, could also 'sleep' here!

  char radiopacket[20] = "Hello World #";
  itoa(packetnum++, radiopacket+13, 10);
  Serial.print("Sending "); Serial.println(radiopacket);
  
  // Send a message!
  rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
  rf69.waitPacketSent();

  // Now wait for a reply
  uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  if (rf69.waitAvailableTimeout(500))  { 
    // Should be a reply message for us now   
    if (rf69.recv(buf, &len)) {
      Serial.print("Got a reply: ");
      Serial.println((char*)buf);
      Blink(LED, 50, 3); //blink LED 3 times, 50ms between blinks
    } else {
      Serial.println("Receive failed");
    }
  } else {
    Serial.println("No reply, is another RFM69 listening?");
  }
}

void Blink(byte PIN, byte DELAY_MS, byte loops) {
  for (byte i=0; i<loops; i++)  {
    digitalWrite(PIN,HIGH);
    delay(DELAY_MS);
    digitalWrite(PIN,LOW);
    delay(DELAY_MS);
  }
}         
The problem is that when I uploaded this code it does not show what it is supposed to be shown on the serial monitor from the website.

What is supposed to be shown in the serial monitor from the website is shown in the file attached to this post.

The photo of the serial monitor that is attached to this post with random question marks and letters is my serial monitor.

Can you tell me what to make the code work so that my serial monitor looks like the serial monitor from the website?


Also, is it ok to use the same pin on my Arduino Nano for 2 different things?
Right now I have D13 being used from my Arduino Nano on the RFM69 Radio and some LEDs.
Is that ok?
Is that the problem?

Another problem could be that I have to change the code for my Arduino Nano because this code from the website is meant for the Arduino Feather?
Is this the problem, and if so ,how could I change this code to work on my Arduino Nano?
Attachments
3A162300-89B1-48BE-86B2-7E1BB1BC7583.jpeg
3A162300-89B1-48BE-86B2-7E1BB1BC7583.jpeg (252.63 KiB) Viewed 160 times
E89C1C32-49C3-4969-8A3D-B0888BEF6491.jpeg
E89C1C32-49C3-4969-8A3D-B0888BEF6491.jpeg (68.21 KiB) Viewed 160 times

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”