5p.io

In this next part of the communication-series, we will be covering standard RF communication over the 2.4GHz spectrum.

Introduction

The 2.4GHz Spectrum is called the ISM(Industrial, Scientific and Medical) band.It is the most widely used band for wireless communication and is used in Wi-Fi, Bluetooth and most other commercial wireless solutions.

In this tutorial, we will be using the nRF24L01 module by Nordic Semiconductor. This is a very low cost (<$5) ultra low power RF transceiver capable of data rates up to 2Mbps. The module I will use is an SPI module making it compatible with any MCU with SPI. In this example I will wirelessly communicate between 2 Arduinos to turn an LED on or off.

Things Needed

2 Arduinos

An LED or any device that can show output from an Arduino

Wiring it Up

To get setup, we will wire up 2 Arduino's Identically.

We shall connect the SPI pins(MOSI, MISO and SCK/SCLK) from the module to the SPI pins on the Arduino, and connect 2 additional pins for CE(Chip Enable) and CSN(Slave Select). We should also wire up the GND to GND and VCC to 3.3V on the Arduino. The pin connections should be:

nRF24L01

Arduino

Description

1

GND

GND

2

3v3

VCC

3

9

CE

4

10

CSN

5

13

SCK

6

11

MOSI

7

12

MISO

8

NC

IRQ

The Schematic is:

My Setup looks like:

For the 2nd Arduino, we must also connect an LED to Pin 2.

The Schematic becomes:

My Setup looks like:

Code

The code involves initializing the Radio using the RF24 library. We also initialize the Serial Port so that we can use the Serial monitor or a Serial terminal software like CoolTerm. We must also define a Pipe, this is the channel to communicate on, all radio's listening on this pipe will receive all transmissions sent on it.

Sender

The sender will take an input from the serial console and send it out through the radio to the receiver. The code is:

Usage

Once you upload these sketches to your Arduinos, you can use a serial terminal to send a requisite command from the Sender to the Receiver, and viola you will see the LED turn on and off based on your commands.

Conclusion

This is a very convenient and cost effective way to wirelessly transfer data between devices, I have used these radios to control everything from light switches to robotic arms, and they have worked like a charm. One point to note is that these radios do not come built in with any security, so if someone with RF knowledge were to sniff out our data packets, they could easily hijack your pipe and compromise anything that you control! If you you want to use this for security sensitive applications, I would highly recommend increasing security by using some sort of encryption.