I have tried out many different devices with the Arduino and generally I can get a simple test working pretty quick on even the most complex. That sure hasn’t been the case with the NRF24L01+ RF transceiver. It seems this device is pretty finicky.
It has taken me three tries to get this device to run consistently. Partially due to my own mistakes. No, I take it back, largely due to my own mistakes – mainly not taking others’ advice.
The base transceiver is the NRF24L01+. It has a range of about 200m (67′). It is small and self-contained. Not much bigger than a large stamp. I got 4 of these on eBay for maybe $4. They are *really* cheap.
These are the first units I tested. They worked OK in the same room and reasonably well with one wall between them (next room). They dropped too many packets at 50′ and a couple of walls in between to be useful at that range.
The NRF24L01+PA+LNA has a power amplifier and Low Noise Amplifier to increase its range to a reported 2000m (666′). Some how I ended up with just one of these so I tried it with the NRF24L01+ and the range wasn’t any better. So I waited for another shipment from China so I had two NRF24L01+PA+LNA. These worked better only after tweaks explained further down.
These are *way* more expensive. I think I paid $6 each.
Connecting the NRF2401L to an Arduino
I used a Nano on this project, but the Uno will use the same pins. You *really* want to be using an external 3.3v power supply to power this device. See my Gotcha’s below. Check the sketch as to if you need pin 8. For my test, I did not.
I used the RF24 library available here. Download it, unzip it into a directory named RF24, then move that directory to the arduino libraries folder (where all of your other libraries reside).
The sketch I used is found at Examples | RF24 | GettingStarted. This sketch should require no modification to get two of these devices communicating. Compile and download to your two Arduino’s with the NRF2401’s connected.
The arduino IDE doesn’t seem to like being open two times and pointing to 2 different COM ports. I didn’t try to deal with this, as I almost always use a different terminal emulator to begin with. I just ran 2 copies of it, each pointed to the proper serial port.
Note that the default sketch uses 57,600 baud. Make sure you set your terminal emulator properly or you will just see garbage.
When you first connect to the NRF24L01+, it will be in receive mode and you will see a information dump about like this:
You should not be seeing a bunch of 0’s and CRC Length and PA power should be as you see above. If they are not, you probably are not connecting to the NRF24L01 properly.
Once you have both Arduino’s at this point, type “T” on one of them. This will toggle that NRF24L01 from receive mode to transmit mode (you can return to receive mode by typing “F”).
This is one point where I was having some problems. Some times just typing T on one arduino wasn’t enough. I’d have to toggle back and forth on both arduino’s until they just started working. That problem seems to have went away once I resolved all of the gotcha’s; however, if you press T and you don’t start seeing transmission, you might try toggling both arduinos a few times.
If you are lucky you will see this (this is the transmitter side):
As I said, I had a lot of trouble actually getting this to work well.
First, you should solder at least a 0.1uF capacitor between pins 1 & 2 (GND and Vcc) ON THE NRF24L01+ especially if you have it connected via jumpers like I do:
Next, you need to provide external 3.3v power to the NRF24L01+. This YwRobot power supply I’m using can provide 5V on one side of the breadboard and 3.3V on the other.
There are multiple resources that document needing the capacitor and a better power supply. You might want to heed them so you don’t get as frustrated as I did.
Even after I made those changes, I was still having issues with packet loss. I decided to power the Nano from the external 5V power supply and it began working much more reliably.
I only made these tweaks once I started testing the NRF24L01+PA+LNA. Once it was running well, it would go diagonally thru my house from the basement in one end of the house to the 2 floor at the other end. That is roughly 75′ thru 2 floors and multiple walls.
I have not tested the NRF24L01+ with the tweaks. They may well work a little better too, but they aren’t rated for much distance to begin with.
Scanning the 2.4GHz Spectrum
For my my last test, I compiled and downloaded code that allows the NRF24L01+ to scan each channel and give an indication of what part of the spectrum is in use.
I used this blog post as my reference which includes the source code to the scanner. I downloaded and compiled the software w/o changes (note the serial port is 57.6KB).
Here are my results:
Each column has a ‘grayscale’ character indicating power: ” .:-=+*aRW”. A space is lowest and W is highest.
I puzzled over these readings. I checked my WIFI access point in that room, and it is on channel 11 and I know that channel is in moderate use because an IP camera is on it. I could not explain all of the traffic on channel 5.
Then it occurred to me I have an analog wireless surveillance camera that uses the 2.4GHz range. I turned that off:
suddenly I can see a lot more traffic and the overall power level is way down.
Not sure how to interpret these results yet, but interesting.
As I think about it, I think this is the first wireless device I’ve used on an Arduino. Not exactly surprising as I’m not a big WIFI fan. The only wireless device I use regularly is my phone.
I’m not sure how much use I could get out of these NRF24L01+ units. The small ones could be handy, but their range is to limited for me. The NRF24L01+PA+LNA seem to do well within the confines of my house, but with the whip antenna are not exactly small. We’ll see if I come up with something for these down the road.
It’s on my list to test a cellular GSM shield and the new ESP8266 WIFI module. Both seem to be more suited to my interests.