
nRF24 versatile Arduino RF Communication Devices
We're sorry, this item is discontinued.
For help finding an alternative product, please call 1-800-528-1417 or email sales@circuitspecialists.com and we'll be happy to assist.
NRF24 Network Device
Over the years, I have built and used many communication methods for my robotic projects. No system is perfect, I worked with the EZ-link ( Bluetooth module), XBee, RobotShop PS2 controller, etc. However, my favorite so far is the nRF24 transceiver board due to its low cost and all the benefits that come with the board.
One of the biggest benefits of the nRF24 is that the board can act as a dual-purpose device, where the nRF24 can turn an Arduino to be a transmitter and receiver. What this means is, an Arduino can receive data and pass it on through a large network. This opens up the possibility of projects due to the flexibility of the board. Circuit Specialists wants to change the norm of expensive communication hardware, that is what this project is all about, low cost and easy access.
This project is built around a low-cost nRF24 board, a very popular communication board in the Maker Communities which comes with a well written Arduino library. We will build a wireless LED box which could provide extra security and light around your property. The LED box can be power by a 9V battery or plug into an outlet for long period usage. The LED box can also be a long-distance car locator or a light beacon for your camping trip.
If you did not already build the Circuit Specialists Control Box then I have bad news for you, you are going to need it for this project. You can click here for the link on how to build a Circuit Specialists Control Box.
If you never worked with the nRF24 before, don’t worry, you can click here for the article about the nRF24 on how to wire it to an Arduino and test code.
1.Parts list:
- Arduino Uno
- 24 white LED
- 6 Buzzer
- nRF24 radio module
- nRF24 breakout board
- Project box
2.Build Process:
A. Upgrade Circuit Specialists Control Box with nRF24 module
- For more information on how to build a control box, you can click here for the tutorial on how to build a Control Box using an Arduino Uno.
- For more information about the nRF24 module, you can click here for the tutorial on how to wire an nRF24 module to an Arduino Uno.
B. Thief Deter Device
C. Prepare the LED and buzzers panel
Cut LEDs to the correct length |
Solder the LEDs in a row together. Please use the provided schematic for reference. |
Heat wrap the connection and fold the wires down
Fold the buzzers leg down to increase soldering surface area |
Solder the buzzers together accordingly. Please use the provided schematic for reference. |
D. NRF24 radio module
The nRF24 breakout board and the nRF24 radio module Solder communication wires and power to the board
Connect the nRF24 wires to the Arduino accordingly: Connect the LED panel wires to the Arduino accordingly:
GND - GND; CE - pin 9; CSN - pin10;
SDK - pin 13; MOSI - pin 11; MISO - pin 12
3.Coding
A.The Transmitter code:
/*
-----------------Note----------------------
Date: 02-04-2020
Project Name: Expert Control Box
Goal: Testing data Package Radio Module
Author: Khang Nguyen
*/
#include
#include
#include
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
const int L_button = 7;
const int R_button = 6;
const int Knob = A0 ;
const int LED2 = 3 ;
const int LED1 = 5 ;
int L_button_state = 0;
int R_button_state = 0;
int forward = 0 ;
int backward = 0;
int K_knob_value = 0 ;
long P_Knob_Value = 0 ;
unsigned long lastReceiveTime = 0;
unsigned long currentTime = 0;
struct Data_Package
{
byte L_Switch;
byte R_Switch;
byte Knob_Value;
};
Data_Package data;
void setup()
{
Serial.begin(9600);
pinMode(L_button, INPUT);
pinMode(R_button, INPUT);
pinMode(LED1 , OUTPUT);
pinMode(LED2 , OUTPUT);
Tranmitter_Setup();
resetData();
}
void loop()
{
L_button_state = digitalRead(L_button);
R_button_state = digitalRead(R_button);
K_knob_value = analogRead(Knob);
P_Knob_Value = map(K_knob_value,1023,0,9,255);
data.Knob_Value = K_knob_value;
Serial.print("Knob Value: ");Serial.println(P_Knob_Value);
//Knob_Function();
if(R_button_state == HIGH)
{
digitalWrite(LED1,HIGH);
data.R_Switch=0;
}
else
{
digitalWrite(LED1,LOW);
data.R_Switch=1;
}
if(L_button_state == HIGH)
{
digitalWrite(LED2,HIGH);
data.L_Switch=0;
}
else
{
digitalWrite(LED2,LOW);
data.L_Switch=1;
}
radio.write(&data, sizeof(Data_Package));
}
//----------Radio---------//
int Tranmitter_Setup()
{
radio.begin();
radio.openWritingPipe(address);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
}
//===========Knob_Function============//
void Knob_Function()
{
if ( P_Knob_Value > 10)
{
//====================Left_Button====================//
if (L_button_state == LOW)
{
analogWrite(LED1,P_Knob_Value );
Serial.println("Left button press!");
}
if (L_button_state == HIGH)
{
analogWrite(LED1,0);
Serial.println("Left button release!");
}
//====================Right_Button====================//
if (R_button_state == LOW)
{
analogWrite(LED2,P_Knob_Value );
Serial.println("Right button press!");
}
if (R_button_state == HIGH)
{
analogWrite(LED2,0);
Serial.println("Right button release!");
}
}
}
//====================Data_Package====================//
void resetData()
{
data.L_Switch = 1;
data.R_Switch = 1;
data.Knob_Value = 0;
}
B. The receiver code:
/*
-----------------Note---------
Date: 02/04/2020
Project Name: Thief_Detering_Device
Objective: testing communication
Author: Khang Nguyen
*/
#include
#include
#include
int ledState = LOW;
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
unsigned long lastReceiveTime = 0;
unsigned long currentTime = 0;
unsigned long previousMillis = 0;
const long interval = 100;
struct Data_Package
{
byte L_Switch;
byte R_Switch;
byte Knob_Value;
};
Data_Package data; //Create a variable with the above structure
int LED_RED = 8 ;
int LED_Array[4] = {5,4,3,2};
int buzzerPin_R = 7;
int buzzerPin_L = 6;
void setup()
{
Serial.begin(9600);
for (int pin = 0; pin <=4 ; pin += 1)
{
pinMode((LED_Array[pin]),
}
Reciever_Setup();
resetData();
Sqe_On(150);
contact ();
}
void loop()
{
// Check whether there is data to be received
if (radio.available())
{
radio.read(&data, sizeof(Data_Package)); // Read the whole data and store it into the 'data' structure
lastReceiveTime = millis(); // At this moment we have received the data
Blink_LED(250,50);
}
// Check whether we keep receving data, or we have a connection between the two modules
currentTime = millis();
if ( currentTime - lastReceiveTime > 1000 ) // If current time is more then 1 second since we have recived the last data,
{ //that means we have lost connection
resetData(); // If connection is lost, reset the data. It prevents unwanted behavior, for example if a drone has a throttle up and we lose connection, it can keep flying unless we reset the values
}
if (data.R_Switch == 0){All_On();beep(880,data.
if (data.R_Switch == 1){All_Off();noTone(buzzerPin_
if (data.L_Switch == 0){Sqe_On(data.Knob_Value);
if (data.L_Switch == 1){All_Off();noTone(buzzerPin_
// Print the data in the Serial Monitor
Serial.print("L_Switch: ");Serial.println(data.L_
Serial.print("R_Switch: ");Serial.println(data.R_
Serial.print("Knob Value: ");Serial.println(data.Knob_
Blink_LED(250,550);
}
//===========LED_Mode=========
void Blink_LED(int Brightness, int BSpeed)
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= BSpeed)
{
previousMillis = currentMillis;
if (ledState == 0) {ledState = Brightness;}
else {ledState = 0;}
analogWrite(LED_RED , ledState);
}
}
void All_On()
{
digitalWrite(LED_Array[0],
digitalWrite(LED_Array[1],
digitalWrite(LED_Array[2],
digitalWrite(LED_Array[3],
}
void All_Off()
{
digitalWrite(LED_Array[0],LOW)
digitalWrite(LED_Array[1],LOW)
digitalWrite(LED_Array[2],LOW)
digitalWrite(LED_Array[3],LOW)
}
void All_Blink(int LED_Speed)
{
digitalWrite(LED_Array[0],
digitalWrite(LED_Array[1],
digitalWrite(LED_Array[2],
digitalWrite(LED_Array[3],
delay(LED_Speed);
digitalWrite(LED_Array[0],LOW)
digitalWrite(LED_Array[1],LOW)
digitalWrite(LED_Array[2],LOW)
digitalWrite(LED_Array[3],LOW)
delay(LED_Speed);
}
void Sqe_On(int LED_Speed)
{
for (int i = 0 ; i <= 3 ; i+=1)
{
digitalWrite(LED_Array[i], HIGH);
delay(LED_Speed);
}
for (int i = 3 ; i >= 0 ; i-=1)
{
digitalWrite(LED_Array[i], LOW);
delay(LED_Speed);
}
}
void Rand_On( int LED_Speed)
{
int RandNum = random(0,4);
digitalWrite(LED_Array[
delay(LED_Speed);
digitalWrite(LED_Array[
delay(LED_Speed);
}
//==============Radio_Setup===
void Reciever_Setup()
{
radio.begin();
radio.openReadingPipe(0, address);
radio.setAutoAck(false);
radio.setDataRate(RF24_
radio.setPALevel(RF24_PA_LOW);
radio.startListening(); // Set the module as receiver
}
//==============Data_Package==
void resetData()
{
data.L_Switch = 1;
data.R_Switch = 1;
data.Knob_Value = 0;
}
//==============Buzzer_
void beep( int note, int duration)
{
tone(buzzerPin_R, note, (duration)); //Play tone on buzzerPin
tone(buzzerPin_L, note, (duration));
delay(duration);
noTone(buzzerPin_L);
noTone(buzzerPin_R);//Stop tone on buzzerPin
delay(50);
}
void contact ()
{
for(int i=0;i<20;i++)
{
int BSpeed=random(0,200);
beep(880,BSpeed);
}
}
void firstSection()
{
const int c = 261;const int d = 294;const int e = 329;const int f = 349;
const int g = 391;const int gS = 415;const int a = 440;const int aS = 455;
const int b = 466;const int cH = 523;const int cSH = 554;const int dH = 587;
const int dSH = 622;const int eH = 659;const int fH = 698;
const int fSH = 740;const int gH = 784;const int gSH = 830;const int aH = 880;
beep(a, 500);beep(a, 500); beep(a, 500);
beep(f, 350);beep(cH, 150); beep(a, 500);
beep(f, 350); beep(cH, 150);beep(a, 650);
delay(500);
beep(eH, 500);beep(eH, 500);beep(eH, 500);
beep(fH, 350);beep(cH, 150);beep(gS, 500);
beep(f, 350);beep(cH, 150);beep(a, 650);
delay(500);
}
4.What next?
The LED box is a simple project to get to know the nRF24 how it works and how to send data from a transmitter to a receiver, we didn’t use one of the nRF24 advances as a dual device. However, this project can be upgraded to a dual device as simple as installing a motion sensor for feedback. This means the LED box can send data back to the control unit if the motion sensor was triggered. With a network of these units set up around a large property can provide the controller with additional information like the location of the threat and direction of the threat heading.
This LED box can also program to be an emergency beacon, provide the survivor with additional light and sound for evacuation location and motion sensor for rescuer information about the location of the survivors. This unit can have a carbon dioxide sensor install for auto-trigger when the level of carbon dioxide in the air is critical to the inhabitant.
However, improve the LED box is not enough due to the information flow back need to present to the operator somehow. This means the control box needs to be improved to interact with the operator.