N424l01 wireless fireworks ignition system

I am building a wireless fireworks display system that will trigger my fireworks in different sequences. I currently have 5 buttons on the TX side and 5 leds on the RX side to simulate the igniter. This allows me to see how to sequence will play out for testing.

materials used:
2 x uno
2 X 24l01 wireless tranceivers.RX&TX
5 x leds RX
5 x resistors.RX
5 x buttons on the RX

LIbraries:
ezButton.h

The system is supposed to allow the user to select 1 of 5 buttons or triggers on the TX side. Once that trigger or button is pressed the RX should activate a firing sequence for out put. If I press trigger one trigger 1 on the RX side should activate that firing sequence. right now no matter what trigger you press only the sequence assigned to trigger 1 will initiate.

the issue that I am having is when I press all of the other buttons they only trigger the sequence assigned to trigger instead of the sequence assigned to that button.
no matter what button is pressed with receiver is getting a message to initiate button 1s, sequnce. I was hoping some one could help me with this issue.

I will enclose my code so you are able to see how I have things set up and please feel free to point out any thing you see that would be causing this problem.

THIS IS THE TX
#include <SPI.h>
#include "RF24.h"
#include <ezButton.h>

byte addresses[] [6] = {"0"};
a
RF24 radio(7,8);

ezButton trigger1 (2);
ezButton trigger2 (3);
ezButton trigger3 (4);
ezButton trigger4 (5);
ezButton trigger5 (6);

void setup() {
Serial.begin(9600);
radio.begin();
radio.setChannel(115);
radio.setPALevel(RF24_PA_MIN);
radio.openWritingPipe (0x8675309abcll);
radio.stopListening();
delay(500);

trigger1.setDebounceTime(10);
trigger2.setDebounceTime(10);
trigger3.setDebounceTime(10);
trigger4.setDebounceTime(10);
trigger5.setDebounceTime(10);

}

void loop() {

trigger1.loop();
trigger2.loop();
trigger3.loop();
trigger4.loop();
trigger5.loop();

int trigState1 = trigger1.getState();
int trigState2 = trigger2.getState();
int trigState3 = trigger3.getState();
int trigState4 = trigger4.getState();
int trigState5 = trigger5.getState();

char text []= ("Connected");
radio.write(&text, sizeof(text));

//Series 1
if (trigger1.isReleased()){
Serial.print("trigger1 igniter 1 ");
Serial.println(trigState1);
radio.write(&trigState1, sizeof(trigState1));

}
if (trigger2.isReleased()){
Serial.print("trigger2 igniter 2 ");
Serial.println(trigState2);
radio.write(&trigState2, sizeof(trigState2));

}
if(trigger3.isReleased()){
Serial.print("trigger3 igniter 3 ");
Serial.println(trigState3);
radio.write(&trigState3, sizeof(trigState3));

}
if(trigger4.isReleased()){
Serial.print("trigger4 igniter 4 ");
Serial.println(trigState4);
radio.write(&trigState4, sizeof(trigState4));
}
if(trigger5.isReleased()){
Serial.print("trigger5 igniter 5");
Serial.println(trigState5);
radio.write(&trigState4, sizeof(trigState4));
}
delay(10);
}

THIS IS THE RX

#include <SPI.h>
#include "RF24.h"
#include <ezButton.h>

byte addresses[] [6] = {"0"};

RF24 radio(7,8);

int trigState1;
int trigState2;
int trigState3;
int trigState4;
int trigState5;

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;

int ledarray[6] {2, 3, 4, 5, 6};

void setup() {
Serial.begin(9600);
radio.begin();
radio.setChannel(115);
radio.setPALevel(RF24_PA_MIN);
radio.openReadingPipe (0, 0x8675309abcll);
radio.startListening();
delay(500);

pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);

}

void loop() {

char text [32];"";
radio.read(&text, sizeof(text));
Serial.println(text);

radio.read(&trigState1, sizeof(trigState1));
if(trigState1 == 1){
Serial.print("trigger1");
Serial.println(trigState1);
for(int i = 0; i < 6; i++){
digitalWrite(ledarray[i], HIGH);
delay(100);
for(int i = 0; i < 6; i++);
digitalWrite(ledarray[i], LOW);
}
}

radio.read(&trigState2, sizeof(trigState1));
if(trigState2 == 1){
Serial.print("trigger2");
Serial.println(trigState2);
digitalWrite(led2, HIGH);
delay(500);
digitalWrite(led2, LOW);
}
radio.read(&trigState3, sizeof(trigState3));
if(trigState3 == 1){
Serial.print("trigger3");
Serial.println(trigState3);
digitalWrite(led3, HIGH);
delay(500);
digitalWrite(led3, LOW);
}

radio.read(&trigState4, sizeof(trigState4));
if(trigState4 == 1){
Serial.print("trigger4");
Serial.println(trigState4);
digitalWrite(led4, HIGH);
delay(500);
digitalWrite(led4, LOW);
}

radio.read(&trigState5, sizeof(trigState5));
if(trigState5 == 1){
Serial.print("trigger5");
Serial.println(trigState5);
digitalWrite(led5, HIGH);
delay(500);
digitalWrite(led5, LOW);
}
delay(10);
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Unusual.

I use that to know if the modules are connected to each other

You need to send something to indicate which trigger was pressed. You're sending a state indication, the transmitter knows which trigger it pertains to but the receiver has no way to know. Whichever trigger is pressed, it sends a 1.

Since fireworks usually need to be super-reliable, I'd avoid wireless. And if you really want wireless you should use a reliable protocol like Wi-Fi or the cell phone network. These have error-checking and error-correction. You won't ALWAYS have a good communication but it can be checked in advance and you should never get a false-trigger (if done properly).

It's not doing what you think it is

You are reading from the radio without ever checking for availability of a packet.

You are assuming a fixed pattern of packets, without any checks.

Better send all your trigger states in one packet.

Hi ryangalaxy,

A couple of things to note when using the nRF24L01 modules - based on my personal experiences.

  1. It’s worth noting that power supply noise is one of the most common issues people experience when trying to make successful communication with the nRF24L01 modules. Generally, RF circuits or radiofrequency signals are sensitive to power supply noise. Therefore, it’s always a good idea to include a decoupling capacitor across the power supply line as close to the nRF24L01 module as possible. The capacitor can be anything from 10uF to 100uF. I used a small 47uF soldered across the power pins of the nRF24L01 :wink:

  2. I've also found adding the following settings in the nRF24L01 Setup on both the receiver & transmitter. This helped improve reliability considerably -

radio.setDataRate(RF24_2MBPS); // Set the speed of the transmission to the quickest available
radio.setChannel(124); // Use a channel unlikely to be used by Wifi, Microwave ovens etc
radio.setPALevel(RF24_PA_MAX); // Set radio Tx power to MAX 

HTH?

I am lost on how I can use one triggerState to send each trigger over to the receiver?

thank you for you reply, I am not sure If I am having power issues since I am using 5v shield for the nrf modules. I seem to be connecting the other module just fine its just not getting the correct information on the RX. If press trigger 2 trigger 1 lights up. Its like it is not able to receive the correct trigger being pushed.

do I need to send this using data structure instead?

struct Packet {
  bool trigger1;
  bool trigger2;
  bool trigger3;
  bool trigger4;
  bool trigger5;
} data;

bool result = radio.write(&data, sizeof(data));

or

bool trigger[5];

bool result = radio.write(&trigger, sizeof(trigger));

How about actually using the references you created?

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;

int ledarray[6] {led1, led2, led3, led4, led5};

Why are only 5 of the 6 members initialized? So when you do this:

for(int i = 0; i < 6; i++);
digitalWrite(ledarray[i], LOW);

The last value is written to pin 0.

That is not the purpose. It's recommended because the device draws large currents intermittently. The capacitor prevents those from overloading the power supply.

Given that there are safety concerns, I suggest that whatever packet structure you choose has a bunch of extra characters in it, even if it's just "ABRACADABRA" and a checksum. If you check for the magic word and the checksum, it'll give you some confidence that the order to fire wasn't just random noise.

You can devise a more secure comms system, but I'd be happy with that as a start.

would this just be on the TX side, what would I write on the RX side?

This would be the null character not pin 0.

Why on earth would you want a null character there? The array doesn't contain characters. Even if you did, shouldn't you make it explicit instead of hiding it?

struct Packet {
  bool trigger1;
  bool trigger2;
  bool trigger3;
  bool trigger4;
  bool trigger5;
} data;

  if (radio.available()) {
    radio.read(&data, sizeof(data));
  }