2.4GHz RF communication between Robot and Base station

In my previous tutorials, I showed how to control DC motors with Arduino,  how to measure distance with HC-SR04 ultrasonic distance sensor and how to measure acceleration with MPU6050 gyroscope + accelerometer. These are all part of the Hackabot Uno Robot Kit.

Today, we are going to talk about how to communicate between the robot and base station (another Arduino Uno) through RF module (Nordic Semiconductor nRF24L01+).

arduino_rf_module_nrf24l01
Nordic Semiconductor nRF24L01+ RF module for Arduino

 

 Connections (for both Arduino robot and base station)

 

Arduino pin RF module pin
3.3V VCC
GND GND
9 CE
10 CSN
11 MOSI
12 MISO
13 SCK

 Programming

Base station

The Arduino Uno base station connects to a laptop through USB. The following program creates a radio object in read mode. It simply keeps printing the data received.

// This program is based on the tutorial on http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define pinCE  9
#define pinCSN 10

RF24 radio(pinCE, pinCSN); 
     
void setup()  
{
  Serial.begin(9600);
  Serial.println("Basestation RF Starting");
  radio.begin();
  radio.openReadingPipe(1,0xE8E8F0F0E1LL);
  radio.startListening();;
}


void loop()   
{
  long data;
  bool done;
  if ( radio.available() )
  {
    // loop until finish reading the data
    do  
    {
      done = radio.read( &data, sizeof(data));
      Serial.print("Data = ");
      Serial.println(data);
    } while (!done);
  }
}

Program for the robot

The following program is uploaded to the robot. All it does is to keep increasing a number and sending it to the base station.

// This program is based on the tutorial on http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define pinCE  9
#define pinCSN 10

RF24 radio(pinCE, pinCSN); 
long data=0;
void setup()   
{
  Serial.begin(9600);
  Serial.println("Robot RF starting");
  radio.begin();
  radio.openWritingPipe(0xE8E8F0F0E1LL);

}

void loop()  
{
  data++;
  radio.write(&data,sizeof(data));
  Serial.print("Data sent = ");
  Serial.println(data);
  delay(100);
}

Summary

This tutorial demonstrates the basic one-way RF communication between robot and base station using 2.4GHz nRF24L01+ RF module from Nordic Semiconductor.  It is very easy to extend this to send the sensor readings from the robot to the base station. On the other hand, it is possible to send commands to the robot from the base station.