Multiple transmitter to one receiver [3xNRF24L01] / Help.

Hi everyone !I need some help with my programming, 3 days ago I started to play with arduino and C language for a school project but now I am stuck.

I am trying to command an Neopixel ring (16 LED's) with an NRF24L01 when a PIR sensor is activated but this will only work if an contact is closed (garage door open). I made it working individually (1 transmitter, 1 receiver) but when I try to use 2 transmitter I cannot make the pipe (communication correctly) and I also have to make an condition that if TRUE (garage door open) it will enter and light up my neopixel, if not the led remains off.

If you have any tips,help I am here, thank you.

This is what I have :

Sensor Transmitter [NANO 1]

//Include needed Libraries at beginning
#include "nRF24L01.h" //NRF24L01 library
#include "RF24.h"
#include "SPI.h"

#define sensorPin 2 // Sensor switch is connected to Pin 8 on NANO
int etatSensor[1] = {000}; // Used to store value before being sent through the NRF24L01

RF24 radio(9,10); // NRF24L01 used SPI pins + Pin 9 and 10 on the NANO

const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL }; // Needs to be the same for communicating between 2 NRF24L01 

int buttonState = 0; // etat de la sortie du capteur
const int ledPin = 4; // la LED du Arduino

void setup(void){
{
  pinMode(ledPin, OUTPUT); //la broche de la LED est mise en sortie
  pinMode(sensorPin, INPUT); //la broche du capteur est mise en entree
}

pinMode(sensorPin, INPUT_PULLUP); // Define the arcade switch NANO pin as an Input using Internal Pullups
digitalWrite(sensorPin,HIGH); // Set Pin to HIGH at beginning

radio.begin(); // Start the NRF24L01
radio.openWritingPipe(pipes[2]); // Get NRF24L01 ready to transmit
radio.startListening()
}

void loop(void) 
{
  buttonState = digitalRead(sensorPin);//lecture du capteur
  if (buttonState == HIGH) //si quelquechose est detecte
  {
    digitalWrite(ledPin, HIGH); //on allume la LED
  }
  else //sinon
  {
    digitalWrite(ledPin, LOW); //on eteint la LED
  }
  
if (digitalRead(ledPin) == LOW){ // If Switch is Activated
etatSensor[0] = 111;
radio.write(etatSensor, 1); // Send value through NRF24L01
}
else {
etatSensor[0] = 000;
radio.write(etatSensor, 1);
}
}

Contact transmitter [NANO 2]

// NRF24L01 Module Tutorial - Code for Transmitter using Arduino NANO

//Include needed Libraries at beginning
#include "nRF24L01.h" //NRF24L01 library
#include "RF24.h"
#include "SPI.h"

#define SwitchPin 8 // Arcade switch is connected to Pin 8 on NANO

bool etatBtn[1] = {000}; // Used to store value before being sent through the NRF24L01
RF24 radio(9, 10); // NRF24L01 used SPI pins + Pin 9 and 10 on the NANO
const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL };// Needs to be the same for communicating between 2 NRF24L01


void setup(void) {

 pinMode(SwitchPin, INPUT_PULLUP); // Define the arcade switch NANO pin as an Input using Internal Pullups
 digitalWrite(SwitchPin, HIGH); // Set Pin to HIGH at beginning

 radio.begin(); // Start the NRF24L01
 radio.openWritingPipe(pipes[1]); // Get NRF24L01 ready to transmit
 radio.startListening()
}

void loop(void) {

 if (digitalRead(SwitchPin) == LOW) { // If Switch is Activated
   etatBtn[0] = 111;
   radio.write(etatBtn, 1); // Send value through NRF24L01
 }
 else {
   SentMessage[0] = 000;
   radio.write(&etatBtn, 1);
 }
}

Receiver [UNO]

//Include needed Libraries at beginning
#include "nRF24L01.h" // NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24
#include "RF24.h"
#include "SPI.h"
#include "FastLED.h" // FastLED library for WS2812 RGB Stick http://fastled.io/

#define NUM_LEDS 16 // Number of leds on stick
#define LED_PIN 8 // Digital In (DI) of RGB Stick connected to pin 8 of the UNO

CRGB leds[NUM_LEDS]; // FastLED Library Init

bool etatBtn, etatSensor ;
RF24 radio(9, 10); // NRF24L01 used SPI pins + Pin 9 and 10 on the UNO
const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL }; // Needs to be the same for communicating between 2 NRF24L01

void setup(void) {

 FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS); // Setup FastLED Library
 FastLED.clear(); // Clear the RGB Stick LEDs

 // Light up starting LED's
 for (int x = 0; x != NUM_LEDS; x++) {
   leds[x] = CRGB::Red;
 }
 FastLED.setBrightness(50);
 FastLED.show();

 radio.begin(); // Start the NRF24L01
 radio.openReadingPipe(1, pipes[1]);// Get NRF24L01 ready to receive
 radio.openReadingPipe(2, pipes[2]);
 radio.startListening(); // Listen to see if information received

 pinMode(LED_PIN, OUTPUT); // Set RGB Stick UNO pin to an OUTPUT
}

void loop(void) {

 while (radio.available())
 {
   // radio.read(ReceivedMessage, 1); Read information from the NRF24L01

   radio.read(&etatBtn, 1);
   radio.read(&etatSensor, 1);

   if (etatBtn[0] == 111) // Indicates switch is pressed
   {
     if (etatSensor[0] == 111) // Indicates sensor detect
     {
       for (int x = 0; x != NUM_LEDS; x++)
       {
         leds[x] = CRGB::Green;
         FastLED.show();
       }
     }
     else
     {
       for (int x = 0; x != NUM_LEDS; x++)
       {
         leds[x] = CRGB::Red;
         FastLED.show();
       }
     }
     delay(10);
   }

The first sketch will not compile.

Both send sketches flood the medium and will probably generate a lot of collisions.

Once a second or even less when not triggered, directly on trigger and faster while triggered
would be my strategy, this would need a state detection which I would implement via the Bounce2 library.

There is no sender identification inside the packet, you rely on the pipes,
but that will only work with up to six tx nodes.

The receiving sketch does not distinguish between the two senders by pipe (lookup available(uint8_t*)),
but reads two packets while at least one is available.

I very much dislike arrays with one element and setting a bool to 111 seems very strange.

You are aware that numeric literals starting with zero (like 000) are interpreted as octal?
It does not hurt for the 000, but it could present surprises if used on othe numbers like 011.

Why do you use the old uint64_t style for the pipe addresses?
And why is that table three elements long where only two (receiver) or even one (transmitters) are used?

This Simple nRF24L01+ Tutorial may be of interest.

It includes an example with one Master and two slaves which could be extended to a larger number of slaves.

...R

I am new with C language so most of my code are parts from other codes, I only worked with python a little bit that why you see some weird things there.

I don't really have time to answer all your questions Whandall but I will come with an update when I will have time to work again on that project.

Thank you for your replies Whandall and Robin2 ! Have a great 2019 !