In this tutorial we will learn how to use one arduino UNO’s, one arduino NANO and two NRF24L01 Transceivers to send CTA messages from a safe needle kit vending machine to a monitoring facility.
What it does:
The button is used as a quick remote response for seeking help with troubleshoots at the vending machine while requesting a safe needle kit or a Naloxone kit. When the user pushes the button, the transceiver 1(transmitter ) at the vending machine will send a message to the transceiver 2 (Receiver) at the monitoring facility.
How it works:
Using the NRF24L01 transceiver modules we will demonstrate a simple way to create a wireless communication between two Arduinos that can be up to 100 meters apart. In the first Arduino we will have the pushbutton and one LED light. In the second Arduino we will have a second LED light. The transceiver 1 will send the message to the transceiver 2 through the pushbutton input. This single push button controls both LED lights at both arduinos.
**This tutorial modifies the code from the Arduino Wireless Communication Tutorial, by Dejan Nedelkovski, www.HowToMechatronics.com.

Parts Needed:
– Arduino UNO starter kit
– Arduino UNO Nano micro controller (or a second Arduino Board)
– One push button (or two if you want to make it more interesting!!)
– Jumper wires (female /female, male/female)
– NRF24L01+PA+LNA Wireless Transceiver RF Transceiver Module 2.4G 1100m (2 pcs)
-330K photo resistors (1)
-10k photo resistors (1)
– Antenna in Antistatic Foam Compatible Arduino (2 pcs)
– Yellow and red LED’s (2 pc)
Circuit/wiring
1. Plug in your Arduino UNO and Arduino NANO to their respective breadboards
2. Prepare your two – NRF24L01+PA+LNA Transceivers with the antennas and plug in the wires as shown in the chart and diagram below.
***(if your Arduino has more digital pins, you can change your pins for MISO, MOSI, SCK, CE like in this example: www.HowToMechatronics.com )***


3. Wire your pushbutton and your red LED to the Arduino UNO.
4. Wire your yellow LED to the Arduino Nano.
Code
/*TRANSMITTER CODE
*
* Veronica Rosado
* Tutorial 03: Final Project
*
* In this tutorial we will learn how to use 1 arduino UNO’s, 1 arduino nano and 2 NRF24L01 transceivers
* to send a messages accross two locations without requiring internet or network connection.
* This tutorial helps to create a communication channel between two arduinos. In this case we used it
* to communicate a safe injection vending machine with the organization in charge of it.
*
* Physical Parts Needed:
- Arduino UNO starter kit
- Arduino UNO Nano micro controller or a second Arduino Board
- One push button (or two)
- Jumper wires
- NRF24L01+PA+LNA Wireless Transceiver RF Transceiver Module 2.4G 1100m (2 pcs)
- Antenna in Antistatic Foam Compatible Arduino (2 pcs)
Link: https://www.amazon.com/gp/product/B01IK78PQA/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1
- LED yellow or RED (1 pc)
* Arduino Wireless Communication Tutorial
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*
* Original code used for this tutorial can be found here:
* https://howtomechatronics.com/tutorials/arduino/arduino-wireless-communication-nrf24l01-tutorial/
* circuit_05 from Vilros USK Guide Code
*
*/
//first, we include the libraries needed for this sketch
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//arguments needed to create an RF24 object
RF24 radio(7, 8); // CE, CSN pins
//array which represents the addresses at both transmitters, this allows for the transceivers to send messages accross
const byte addresses[][6] = {"00001", "00002"};
const int button1Pin = 2; //pushbutton 1 pin
//const int button2Pin = 3; //pushbutton 2 pin //A second button could be included to
//send a message from Prevention Point to the Vending Machine
const int ledPin = 6; //yellow LED light at transmitter 2
int buttonState = 0; //integer that determines the state of the button pin
int buttonState_prev = 0; //integer that determines the previous state of the button pin. This allows for the pushbutton read to be more precise.
void setup()
{
// Here we'll configure the parts and pins we're using for the transmitter
Serial.begin(115200); //sets up the serial monitor
radio.begin(); //initializes the radio object
//radio.openWritingPipe sets the address of the receiver to which we will send data
radio.openWritingPipe(addresses[1]); //00001
//radio.openReadingPipe sets the address of the transmitter from which we will receive data
radio.openReadingPipe(1, addresses[0]); //00002
//sets the Power Ampplifier level: use MIN when objects are close, MAX when further apart
radio.setPALevel(RF24_PA_MIN);
// Sets up the pushbutton pins to be an input
pinMode(button1Pin, INPUT);
//sets the LED pin as an OUTPUT
pinMode(ledPin, OUTPUT);
}
void loop()
{
//following are the functions to set up the our transmitter and receivers communication
delay(5);
radio.stopListening(); //sets the module as transmitter
buttonState = digitalRead(button1Pin); //variable that reads the pushbutton state
if (buttonState == LOW){ //if the button is pushed
delay(20);
buttonState = digitalRead(button1Pin);
}
if((buttonState_prev == HIGH) && (buttonState == LOW)){ //if the button_prev state was OFF(HIGH) AND the button state was ON(LOW)
digitalWrite(ledPin, HIGH); //then read the button state and execute the code below
delay(1000);
const char text[] = "HELP at Francis Vending"; //an array of characters to store the message
radio.write(&text, sizeof(text)); //transmitter sends message to the Receiver's Serial monitor screen
}
else
{
digitalWrite(ledPin, LOW);
}
buttonState_prev = buttonState; //restores the button state back to 0
delay(5);
//radio.startListening();
}
/* RECEIVER CODE
*
* Veronica Rosado
* Tutorial: Final Project
*
* In this tutorial we will learn how to use 1 arduino UNO’s, 1 arduino nano and 2 NRF24L01 transceivers
* to send a messages accross two locations without requiring internet or network connection.
* This tutorial helps to create a communication channel between two arduinos. In this case we used it
* to communicate a safe injection vending machine with the organization in charge of it.
*
* Physical Parts Needed:
- Arduino UNO starter kit
- Arduino UNO Nano micro controller or a second Arduino Board
- One push button (or two)
- Jumper wires
- NRF24L01+PA+LNA Wireless Transceiver RF Transceiver Module 2.4G 1100m (2 pcs)
- Antenna in Antistatic Foam Compatible Arduino (2 pcs)
Link: https://www.amazon.com/gp/product/B01IK78PQA/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1
- LED yellow or RED (1 pc)
* Arduino Wireless Communication Tutorial
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*
* Original code used for this tutorial can be found here:
* https://howtomechatronics.com/tutorials/arduino/arduino-wireless-communication-nrf24l01-tutorial/
* circuit_05 from Vilros USK Guide Code
*
*
*/
//first, we include the libraries needed for this sketch
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//arguments needed to create an RF24 object
RF24 radio(7, 8); // CE, CSN
//array which represents the addresses at both transmitters, this allows for the transceivers to send messages accross
const byte addresses[][6] = {"00001", "00002"};
//LED light at transmitter 2
const int ledPin2 = 4;
const int button1Pin = 2; //pushbutton 1 pin
boolean button1State = 0; //
void setup()
{
// Here we'll configure the parts and pins we're using for the receiver
Serial.begin(9600); //sets up the serial monitor
// Set up the pushbutton pins to be an input:
pinMode(button1Pin, INPUT);
radio.begin(); //initializes the radio object
//radio.openWritingPipe sets the address of the receiver to which we will send data
radio.openWritingPipe(addresses[0]); //00002
//radio.openReadingPipe sets the address of the transmitter from which we will receive data
radio.openReadingPipe(1, addresses[1]); //00001
//sets the Power Ampplifier level, use MIN when objects are close, MAX when further
radio.setPALevel(RF24_PA_MIN);
//sets the LED pin as an OUTPUT
pinMode(ledPin2, OUTPUT);
}
void loop()
{
//following are the functions to set up the our transmitter and receivers communication
delay(5);
radio.startListening(); //sets the module as receiver
if (radio.available()) //checks if there is data available
{
char text[32] = ""; //reads the data. [32] is the max num of characters transceivers are able to store
radio.read(&text, sizeof(text)); //stores the data
Serial.print(text); //prints text in the serial monitor
Serial.println(); //prints text in the serial monitor
//Serial.println("test print"); //prints text in the serial monitor, this is a test string to check the code is working
digitalWrite(ledPin2, HIGH); // turns yellow LED on to confirm message was received
delay(1000); // Wait for one second
digitalWrite(ledPin2, LOW);
delay (500);
digitalWrite(ledPin2, HIGH);
delay (100);
digitalWrite(ledPin2, LOW);
delay (100);
digitalWrite(ledPin2, HIGH);
delay (100);
digitalWrite(ledPin2, LOW);
delay (1000);
delay(5);
radio.stopListening();
button1State = digitalRead(button1Pin);
radio.write(&button1State, sizeof(button1State));
}
else
{
digitalWrite(ledPin2, LOW);
}
}
1. First, make sure you download the ZIP file for this library (Optimized fork of nRF24L01 for Arduino & Raspberry Pi/Linux Devices): TMRh20/RF24, https://github.com/tmrh20/RF24/
2. Open your Arduino software and add the library:

3. COPY the Transmitter code and PASTE it into a new empty sketch file.
4. COPY the Receiver code and PASTE it into your a new empty sketch file.
5. SAVE the Transmitter and Receiver sketches in TWO separate files
6. LOAD the Transmitter Code to the Arduino UNO/Transceiver 1. You must upload this code BEFORE uploading the receiver code. Make sure your arduino board is set to GENUINO/UNO and the proper port.

7. LOAD the Receiver Code to the Arduino NANO/Transceiver 2. Keep the receiver connected to your computer so that you are able to open the serial monitor. Make sure your arduino board is set to Arduino NANO and the processor to ATmega328p (Old Bootloader).


8. Use a USB wall charger adapter (similar to those use for phones, output of 5V) and plug in your Arduino UNO/Transceiver 1 to the wall.
9. While your serial monitor is open, push the button at the Arduino UNO/Transceiver 1. Notice how the LED’s at both Arduinos are turning ON and the serial monitor in the receiver is getting a message from the Arduino UNO/Transceiver 1.
You’re done!!
***Final Notes:
Several manipulations can be done to the LED’s blinking pattern and the amount of push button inputs accross transmitters. Feel free to leave any comments, suggestions or ask any questions. Thank You!!
References:
nRF24L01 – How It Works, Arduino Interface, Circuits, Codes
One reply on “creating wireless communication across separate arduinos using nRF24L01 transceivers”
I hv tried with same (single push button), and with two buttons, and two led outputs at receiver end. Working fine. But when I increase the no of buttons to 3, or 4, 5 in the same way. It is not working. Either flicker, or don’t respond, erratic .
Plz suggest can I not send 5 inputs to receiver with nrf24l01. Tr Nano, Rcv Uno.