NRF24 Wireless LED Box

by Khang Nguyen in Circuits > Arduino

2751 Views, 12 Favorites, 0 Comments

NRF24 Wireless LED Box

Untitled.jpg

Over the years, I have built and use many communication methods for my robotic projects. No system is perfect, I have work with the EZ-link ( Bluetooth module), XBee, RobotShop PS2 controller, etc. However, my favorite so far is the nRF24 board with its breakout board, for voltage control 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 purposes device, where the nRF24 can turn an Arduino to be a transmitter and receiver. What this means is, an Arduino can receiving data and passing it on through a large network. This opens up the possibility of projects due to this is vast and incomprehensive capability is underrated.

Circuit Specialists located around my area, that provide cheap electronic components so I think I should take this opportunity to create a project that students can build and expand your future project to the wireless roam. I want 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 to 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.

Notes:

  • 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 work 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.

Supplies

  • Arduino Uno - link
  • 24 white LED - link
  • 6 Buzzer - link
  • nRF24 radio module - link
  • nRF24 breakout board - link
  • Project Box - link

Schematic and 3D File for Front and Side Panels

Schematic.jpg

Front Panel LED

IMG_6675.jpg
IMG_6680.jpg
IMG_6681.jpg
  1. Cut LEDs to the correct length
  2. Solder the LEDs in a row together. Please use the provided schematic for reference.
  3. Heat wrap the connection and fold the wires down to save space.

Front Panel Buzzers

IMG_6682.jpg
IMG_6683.jpg
IMG_6684.jpg
  1. Fold the buzzers' leg down to increase soldering surface area.
  2. Solder the buzzers together accordingly. Please use the provided schematic for reference.

NRF24 Radio Module

IMG_6686.jpg
IMG_6687.jpg
  1. The nRF24 breakout board and the nRF24 radio module.
  2. Solder communication wires and power to the board.
  3. Connect the nRF24 wires to the Arduino accordingly.
  4. Connect the LED panel wires to the Arduino accordingly. Please use the provided schematic for reference.

Prepare the Box

IMG_6688.jpg
IMG_6690.jpg
IMG_6694.jpg
IMG_6697.jpg

I will attach the STL files below for the side cover and the front panel. I attempted to use a rotary tool to cut out the hole for the Arduino, however, the final look was cutting it for me.

Cut out a large area to fit the 3D printed side panel. That will provide the box with a better fit and final look.

For the front cover, you can drill out holes for the LEDs however, I suggest that you should glue a thin sheet of material, like balsa wood, in the back of the cover before drilling the whole for a better final look.

Wiring

IMG_6692.jpg
IMG_6698.jpg

The wiring is fairly straight forward. Please follow the schematic for reference.

Code

Untitled2.jpg

Transmitter code

Set up radio module address and pins

RF24 radio(9, 10); // CE, CSN         
const byte address[6] = "00001";

Setup LEDs pins, switches and, potentiometer.

const int L_button = 7;<br>const int R_button = 6;</p><p>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 ;

Setup Timestamp and Data package

unsigned long lastReceiveTime = 0;
unsigned long currentTime = 0;


struct Data_Package
{
  byte L_Switch;
  byte R_Switch;
  byte Knob_Value;
};

Data_Package data;

Call Tranmitter_Setup() and resetDatat() in void setup()

Tranmitter_Setup();

  resetData();

Read the state of all buttons and knob

    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);

Convert the state of the button to either 0 or 1

data.Knob_Value = K_knob_value;

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;}

Send Data as a package

radio.write(&data, sizeof(Data_Package));

Tranmitter_Setup() function

  radio.begin();
  radio.openWritingPipe(address);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);

resetData() function

  data.L_Switch = 1;
  data.R_Switch = 1;
  data.Knob_Value = 0;

=============================================

Receiver Code

Set up radio module address and pins

RF24 radio(9, 10); // CE, CSN</p><p>const byte address[6] = "00001";

Setup LEDs pins and buzzers

int LED_RED = 8 ;
int LED_Array[4] = {5,4,3,2};</p><p>int buzzerPin_R = 7;
int buzzerPin_L = 6;

Setup Timestamp and Data package

  struct Data_Package
{
  byte L_Switch;
  byte R_Switch;
  byte Knob_Value;
};

Data_Package data; //Create a variable with the above structure

unsigned long lastReceiveTime = 0;
unsigned long currentTime = 0;

unsigned long previousMillis = 0;  
const long interval = 100;

Call Reciever_Setup() and resetDatat() in void setup()

Reciever_Setup();

  resetData();

Check if com is available, if so, read the package and save it.

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);
         
       }

If over a second without a data send, then reset data

if ( currentTime - lastReceiveTime > 1000 ) // If current time is more then 1 second since we have recived the last data,<br>  {                                           //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
  }

Turn the LED on or off accordingly to the data package

  if (data.R_Switch == 0){All_On();beep(880,data.Knob_Value);}
  if (data.R_Switch == 1){All_Off();noTone(buzzerPin_R);noTone(buzzerPin_L);}


  if (data.L_Switch == 0){Sqe_On(data.Knob_Value);beep(880,data.Knob_Value);}
  if (data.L_Switch == 1){All_Off();noTone(buzzerPin_R);noTone(buzzerPin_L);}

Different LED mode

void All_On()
{
  digitalWrite(LED_Array[0],HIGH);
  digitalWrite(LED_Array[1],HIGH);
  digitalWrite(LED_Array[2],HIGH);
  digitalWrite(LED_Array[3],HIGH);
}
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],HIGH);
  digitalWrite(LED_Array[1],HIGH);
  digitalWrite(LED_Array[2],HIGH);
  digitalWrite(LED_Array[3],HIGH);
  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[RandNum] , HIGH);
  delay(LED_Speed);
  digitalWrite(LED_Array[RandNum] , LOW);
  delay(LED_Speed);
}

Reciever_Setup() function

void Reciever_Setup()
{
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_LOW);
  radio.startListening(); //  Set the module as receiver
}

Finish. What Next?

NRF24-Wireless-LED box

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, sound like the next project to me :D.