Microcontroller boards like those made by Arduino are practical and incredibly versatile on their own. But as your abilities as a builder grow and progress, you may long for the capabilities of a wireless interface.
Infrared interfaces may be useful in many situations, as are Bluetooth or Wi-Fi, but another alternative comes in the form of the NRF24L01+ module. This module transmits and receives information on the same unlicensed 2.4 GHz band as Wi-Fi. If configured correctly, two of these modules will send RF information back and forth without any connection hassles on the user’s end.
RF Module Using Arduino
The hassle with these inexpensive devices comes with initially wiring them up and programming everything. The setup process involves properly connecting seven or eight wires instead of, for example, the four you’d use with a Bluetooth module. Further complicating things from a practical standpoint is that typical module pinouts don’t fit on a breadboard correctly, so you’ll need to jumper each of them in place or find an appropriate adapter. Once you’ve decided to take the plunge into this potentially messy wiring setup, connect the jumpers to an Arduino Uno or Nano board (Arduino pin listed first, followed by the RF module’s connection):
- 3.3V==>VCC
- GND==>GND
- 8==>CSN
- 7==>CE
- 13==>SCK
- 11==>MOSI
- 12==>MISO
There is also an optional interrupt (IRQ) pin on the NRF24L01+ board, but we won’t cover that here. Connecting with outer boards, such as the Arduino Mega 2650, is possible, but you may require a different pinout. For this test, we’ll also attach an LED with the appropriate resistor to output D2 on the receiving board, which will function as a visual transmission indicator.
With everything connected securely—on two Arduino boards as you’ll need something to talk to— install the RF42 library from GitHub. With that complete, download the example code for the transmitter and receiver and install the code on each board.
NRF24L01 Audio Communication
For testing, it’s useful to have two separate instances of the Arduino IDE open, as we demonstrated using Bluetooth communication. This setup allows you to view and modify both pieces of code at once. You can also access the Arduino software from a desktop shortcut or file folder, instead of through the open Arduino IDE’s File-New dialog.
Caption: “LLL” signal is not recognized by receiving Arduino, while “L” gives serial feedback and turns on the LED.
With everything connected and properly installed, the “receiving” Arduino will receive a serial text from the normally transmitting unit once every second, while the transmitter will blink in response when it receives an “L.” Open to the serial monitor on the receiver Arduino at 9600 baud, and you’ll see a line that says “L” followed by a line that states, “is L-Light On” repeating every second.
From here, you can observe the response. Building on this arrangement, you could implement different control scenarios, such as:
- “F” and “R” that trigger a forward and reverse response in a remote-controlled vehicle
- A numerical signal for a simulated analog output
- Two-way communication
Adding a Capacitor to NRF24
The NRF24 radio units, while a very efficient use of power, are also sensitive to noisy or insufficient power. To keep things working smoothly, you can attach a capacitor in the 4.7-47 µF range between the ground and 3.3 V input to the unit. Some recommend using a separate power supply from the Arduino board; that theory remains untested and using a capacitor appears to be sufficient.
Since the NRF24L01+ uses power in the 15 mA range and the Uno listed a 3.3 V supply capability of 50 mA, a separate supply seems unnecessary. However, a capacitor can help even out power spikes or deficits from the Arduino.Caption: Amplifier and antenna result in a longer range, but also a much larger size.
A few factors may affect these receivers’ performance. Most obviously, the receivers come in a format with a small onboard antenna, along with a version with improved range and a power amplifier that requires an external attachment. The external antenna model can reportedly transmit in the 1000-meter range, but these models are much larger and more expensive (though still available for a couple of dollars).
How to Boost RF Signal Using Arduino Software
You can try a few software tricks to improve range as well, referenced in the setup function of both Arduino code examples. Power levels are defined by the radio.setPALevel(), and vary between RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, and RF24_PA_max.
1. Set the data rates with the radio.setDataRate() function. RF24_250KBPS signifies 250 kbps, which is the slowest speed available and it offers the longest range of data transmission. RF24_1MBPS signifies 1Mbps and RF24_2MBPS signifies 2 Mbps, giving a higher transfer speed, but less range.
2. You can also set the channel of your radio between 2.400 and 2.524 GHz using the radio.setChannel(). At that reading, values of 0-124 correspond to 2.4 GHz plus the channel number in units of MHz. So radio.setChannel(21). Your radio will therefore communicate at 2.421 GHz. While this is a bit more nebulous speed-wise, different channels will certainly give better performance depending on your surrounding environment. Note that 2.483.5 GHz is normally the top legal limit for this type of transmission, so be sure to keep that in mind.
If you’re having trouble getting your boards to communicate, be sure that you’ve connected each wire in the proper order, and secured everything breadboard or solder-wise. Loose or incorrect connections can cause problems in any project, but when we’re dealing with two separate systems, troubleshooting can get even trickier.