This post aims to be a complete guide for nRF24L01 – 2.4GHz RF Transceiver module. I’ll explain what it does, show its specs and share an Arduino project example that you can take and apply to your own projects.
I have more complete guides for other popular sensors, check them below:
These RF modules are very popular among the Arduino tinkerers. The nRF24L01 is used on a wide variety of applications that require wireless control. They are transceivers which this means that each module can transmit and receive data.
These modules are very cheap and you can use them with any microcontroller (MCU).
Specifications nRF24L01 – 2.4GHz RF Transceiver
You can purchase these modules for just a few dollars. Click here to compare the nRF24L01 module on several stores and find the best price. They come in two versions with external antenna (more range) or built-in antenna (less range).
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
You need the following components to make this example:
Here’s the library you need for this project:
The RadioHead library is great and it works with almost all RF modules in the market. You can read more about this project here.
Important: Input voltage is of 1.9V~3.6V, do not exceed this voltage, otherwise it will fry your module.
Follow the circuit above for your client. Then upload the code below which can be found in your Arduino IDE (after installing the RadioHead library).
Go to File > Examples > RadioHead > nrf24 > nrf24_client.
// nrf24_client #include #include // Singleton instance of the radio driver RH_NRF24 nrf24; // RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf // RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin // RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini void setup() < Serial.begin(9600); while (!Serial) ; // wait for serial port to connect. Needed for Leonardo only if (!nrf24.init()) Serial.println("init failed"); // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm if (!nrf24.setChannel(1)) Serial.println("setChannel failed"); if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm)) Serial.println("setRF failed"); >void loop() < Serial.println("Sending to nrf24_server"); // Send a message to nrf24_server uint8_t data[] = "Hello World!"; nrf24.send(data, sizeof(data)); nrf24.waitPacketSent(); // Now wait for a reply uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN]; uint8_t len = sizeof(buf); if (nrf24.waitAvailableTimeout(500)) < // Should be a reply message for us now if (nrf24.recv(buf, &len)) < Serial.print("got reply: "); Serial.println((char*)buf); >else < Serial.println("recv failed"); >> else < Serial.println("No reply, is nrf24_server running?"); >delay(400); >
Important: Input voltage is of 1.9V~3.6V, do not exceed this voltage, otherwise it will fry your module.
Follow the circuit above for your server. Then upload the code below which can be found in your Arduino IDE (after installing the RadioHead library).
Go to File > Examples > RadioHead > nrf24 > nrf24_server.
// nrf24_server #include #include // Singleton instance of the radio driver RH_NRF24 nrf24; // RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf // RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin // RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini void setup() < Serial.begin(9600); while (!Serial) ; // wait for serial port to connect. Needed for Leonardo only if (!nrf24.init()) Serial.println("init failed"); // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm if (!nrf24.setChannel(1)) Serial.println("setChannel failed"); if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm)) Serial.println("setRF failed"); >void loop() < if (nrf24.available()) < // Should be a message for us now uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN]; uint8_t len = sizeof(buf); if (nrf24.recv(buf, &len)) < // NRF24::printBuffer("request: ", buf, len); Serial.print("got request: "); Serial.println((char*)buf); // Send a reply uint8_t data[] = "And hello back to you"; nrf24.send(data, sizeof(data)); nrf24.waitPacketSent(); Serial.println("Sent a reply"); >else < Serial.println("recv failed"); >> >
In this project the client is sending a message “Hello World!” to the server via RF and the server is sending back the following message “And hello back to you”. Those messages are being displayed in the serial monitor. Here’s what you should see in your serial terminal windows (see Figure below).
Note: On the left window, I’m establishing a serial communication with PuTTY.org. On the right window, I’m using the Arduino IDE Serial Monitor.
You need to have some realistic expectations when using this module. They work very well when the receiver and transmitter are quite close to each other. If you separate them too far you’ll loose the communication.
The communication range will vary. It depends on how much noise in your environment, if there’s any obstacles and if you’re using an external antenna.
I hope you found this guide useful.
Share this post with a friend that also likes electronics!
You can contact me by leaving a comment. If you like this post probably you might like my next ones, so please support me by subscribing my blog and my Facebook Page.