i mange to get the NRF2401 to transmit on one module and Receive one a second module with the code below.
Transmit sketch
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
//Contacts from the radio to connect NRF24L01 pinamnam -> Arduino
//SCK -> 13
//MISO -> 12
//MOSI -> 11
//CSN -> 10
//CE -> 9
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL; // fax transmission channel
//button connected to these pins
int buttonPin1 = 2;
int buttonPin2 = 3;
void setup(void){
radio.begin();
radio.openWritingPipe(pipe); // Open channel
}
void loop(void){
//until the button (buttonPin1) pressed send the package (111) Arduino ?2
if (digitalRead(buttonPin1) == HIGH){
msg[0] = 111;
radio.write(msg, 1);
}
if (digitalRead(buttonPin2) == HIGH){
msg[0] = 112;
radio.write(msg, 1);
}
}
and this is the receive sketch
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
//Contacts from the radio to connect NRF24L01 pinamnam -> Arduino
//SCK -> 13
//MISO -> 12
//MOSI -> 11
//CSN -> 10
//CE -> 9
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL; // channel address
//LEDs connected to these pins
int LEDpin1 = 2;
int LEDpin2 = 3;
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe); // Open one of the 6-channel reception
radio.startListening(); //Begin to listen
pinMode(LEDpin1, OUTPUT);
pinMode(LEDpin2, OUTPUT);
}
void loop(void){
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(msg, 1);
//if the packet came from Arduino ?1 (111), the LED (lights) LEDpin1, HIGH
if (msg[0] == 111){
delay(10);
digitalWrite(LEDpin1, HIGH);
Serial.println("Led 1 On");
}
else {
digitalWrite(LEDpin1, LOW);
Serial.println("Led 1 Off");
}
delay(10);
if (msg[0] == 112){
delay(10);
digitalWrite(LEDpin2, HIGH);
Serial.println("Led 2 On");
}
else {
digitalWrite(LEDpin2, LOW);
Serial.println("Led 2 Off");
}
delay(10);
}
}
}
and works but i can not figure out how to gets a Third module to transmit to the receiver. can someone please help me out not even sure what to do to extend the sketch. when i add the same sketch to the third module i can hit a button from the third module and it shows the same leds turn on in the receiver but not the new leds. i added. I really need help can some one help me please?