In my last tutorial I created a NodeMCU based Duino Coin Miner. It is an awesome little miner that sits on my desk and mines few cents a day. However, adding these miners to my home network choked my WiFi router. Home Appliances and Smart Devices connected to the router constantly started dropping off. To my understanding, most of the wireless routers and access points can support upto 250 devices connected at once. So, what's happening here? To clarify my doubts I called my ISP. The answer they gave was absolutely shocking. "ONLY 30 devices can successfully connect and exchange data via their router at any given time". Bloody hell!! So, to overcome this limitation I added another router to the network to scale up the load.
But, I was not happy with this solution. So, I did a bit of research and found this "NRF24L01 RF Transceiver Module" which I can use to create a mesh of wirelessly connected microcontrollers. In this tutorial, I am going to show you guys how to use this transceiver module to add wireless communication between two or more Arduino boards. I will be using this module for many of my upcoming home automation projects. Bang Problem solved..
In my last tutorial, I created a NodeMCU based Duino coin miner. It is an awesome little miner
that sits on my desk and mines few cents a day. However, adding these miners to my home network
choked my Wi-Fi router. Home appliances and smart devices connected to the router
constantly started dropping off. To my understanding, most of the wireless routers
and access points can support up to 250 devices connected at once. So, what's happening here?
To clarify my doubts, I called my ISP. The answer they gave me was absolutely shocking.
Only 30 devices can successfully connect and exchange data via their router at any given time.
Bloody hell. So, to overcome this limitation, I added another router to the network to scale
up the load. But I was not happy with this solution. So, I did a bit of research and
found this NRF24L01 RF transreceiver module which I can use to create a mesh of wirelessly connected
microcontrollers. In this tutorial, I am going to show you guys how to use this transreceiver
module to add wireless communication between two or more Arduino boards. I will be using
this module for many of my upcoming home automation projects. Bang! Problem solved.
This video is sponsored by PCBWay. PCBWay specializes in manufacturing of very high
quality, low volume, colored PCBs at a very budgetary price. In addition to standard PCBs,
you can order advanced PCBs, aluminum PCBs, rigid flex PCBs. They also provide PCB assembly
and other related services which can meet your need at the greatest extent.
So far, I have always used Wi-Fi for wireless communications between microcontrollers. While
this is easy enough to do, it is not exactly suitable for battery-operated nodes. Wi-Fi
modules consume a lot of current while transmitting data, plus they also have a slight delay when
initiating the transmissions as the module has to first connect to the Wi-Fi network.
After getting crippled by the abilities of my wireless router, I found this cheap,
very popular and widely used RF transreceiver module which you can hook up to any microcontroller.
This module is called RF transreceiver because a single module can work both as a transmitter
and a receiver. The module operates at a frequency of 2.4 GHz which is one of the ISM band which
it is open to use in most of the countries of the world. Data transfer rate is between 250 kbps to
2 mbps baud. The module is designed for ultra-low power wireless applications. It has two power
saving modes operating at 22 microamp and 900 nanoamps. Operating voltage is between 1.9V
to 3.6V. All other pins on this board are 5V tolerant making it easy to connect to any Arduino
without using a logic level converter. The module has 125 independent RF channels giving the
possibility to have a network of 125 independently working modems in one place. The module is
configured and operated through a serial-peripheral interface. It uses enhanced shock burst for
automatic packet assembly and timing, automatic acknowledgement and retransmission of packets.
The module used in this video has an inbuilt PCB antenna making it compact. However,
you can also buy a variant that supports an external antenna allowing much higher range of
about 1000 meter in line of sight. Now let's have a look at the pinouts and specifications of this
module. GND is the ground pin. It is generally placed inside a square for easy identification.
VCC supplies power to the module. Voltage can range from 1.9V to 3.9V so you can connect it
directly to the 3.3V pin of your Arduino. Remember connecting it to the 5V pin will likely destroy
the module. CE or the chip enable is an active high pin. When selected, the module will either
transmit or receive depending upon which mode it is currently in. CSN or chip select not is an
active low pin and is normally kept high. When this pin goes low, the module begins listening
on its SPI port for data and processes it accordingly. SCK or the serial clock. It
accepts clock pulses provided by the SPI bus master. MOSI or the master out slave in. It is
SPI input to the module. It is used to receive data from the microcontroller. MISO or the master
in slave out. It is the SPI output from the module. It is used to send data to the microcontroller.
IRQ it is the interrupt pin that alerts the master when new data is available for processing.
In order to get this working we need two such modules and two Arduino boards. For this tutorial
I am going to use two Arduino Nanos. Just remember we cannot use a breadboard with these modules
because the pin spacing on these modules are not enough to place it in the middle and if you
place it anywhere else then you will end up shorting all the pins. This means that you will
either have to solder the wires directly to the module or use some sort of jumper cable. The
connection is exactly the same on both the transmitter and the receiver end. Connect the
ground pin to negative and VCC pin to the 3.3 pin of Arduino. The signals generated by these modules
are very sensitive to power supply noises. Adding a decoupling capacitor anything from 10 to 100
microfarad across the power supply line is always a very good idea. Then connect the CSN pin to D8,
CE to D9, MOSI to D11, MISO to D12 and SCK to D13 pin of Arduino. Since the module requires a lot
of data to transfer it gives the best performance when connected to the hardware SPI pin of the
microcontroller. Note that each Arduino board has different SPI pins that must be connected
accordingly. Have a look at the table on screen for quick reference. For this tutorial I'm going
to use the TM-RH20 slash RF24 OSI layer 2 driver for NRF24L01 on Arduino and Raspberry Pi. You can
download the library from the link provided in the description below. In my first example I'm
going to send a character array from one module to the other. Using a split screen I'm going to
demonstrate this example. On my left is the transmitter code and on my right is the receiver
code. Let's start by including the SPI library followed by the RF modules library just downloaded
from the github in the code. Then we are creating an RF24 object by passing the CSN and the CE as
the two arguments to the radio function. Next we are creating an array of the addresses that
the modules will use to communicate amongst themselves. The address can literally be
however it has to be the same on both the transmitter and the receiver module.
This is how the RF module know who they are communicating with. In the setup section we
first initialize the radio object. Then using the radio dot open writing pipe function we set the
address of the transmitter which we will use to send the data to the receiver module. On the
receiving end we use the radio dot open reading pipe function with the same address to read the
data from the data pipe. Next we set the power amplifier level. Since the module in this demo
are sitting just next to each other I'm using the minimum level. Next in the transmitter code we
need to tell the module to stop listening using the radio dot stop listening function. This sets
the module as a transmitter. On the receiver module we need to start listening using the
radio dot start listening function. This sets the module as a receiver. After that in the loop
section of the transmitter we send an array of character using the radio dot write function
and on the receiver end we read the array using the radio dot read function and display it on the
serial monitor every second. In the second example I'm going to light up two LEDs on the receiver
end based on whichever button is pressed on the transmitter end. To achieve this I have added two
LEDs on the receiver end and two push button switches on the transmitter end. When button B1
is pressed the transmitter sends B1 using the radio dot write function and when button B2 is
pressed the transmitter sends B2 using the radio dot write function to the receiver module. The
switch statement in the receiver code then lights up the corresponding LED based on whichever button
is pressed on the transmitter end. In my third example I'll show you guys how a single node can
act as both transmitter and a receiver. Just remember you cannot send and receive data at the
same time. Using the stop listening and the start listening function will toggle between sending and
What's different here from the previous code is that we are creating two pipes or addresses for
the bidirectional communication. In the setup section we need to define both pipes in a way
that the sending address of the first module is the receiving address of the second module
and vice versa the receiving address of the first module need to be the sending address
of the second module. Now in the loop section of the first Arduino we use the radio dot stop
listening function to turn the node into a transmitter and send the data using the radio
dot write function. On the receiver end we use the radio dot start listening function to read the
incoming data. While there is incoming data we read it using the radio dot read function then we
add a bit of delay to the code. After that we set the first Arduino to receiver mode using the radio
dot start listening function and the second Arduino to transmitter mode using the radio dot stop
listening function. The data is then displayed on screen using the serial monitor. The NRF24L01
plus has a feature called multisever. It is an abbreviation for multiple transmitter single
receiver. In my fourth example I'm going to show you guys how to connect multiple transmitters to
a single receiver. In a multisever network each RF channel is logically divided into six parallel
data channels or data pipes. Each data pipe has its own unique data pipe address. Only one data
pipe can receive a packet at any time. So basically the primary receiver in the middle is collecting
data from six different transmitting nodes simultaneously. The primary receiver can stop
listening at any time and start acting like a transmitter. This way you can create a mesh of
network where each node can act as a repeater. There is a different library called RF24Mesh
you need to use to create this mesh network. Since I don't have that many modules handy at the moment
I am unable to show you guys the working bit of it. However I will create a second tutorial
dedicated just to this mesh network. So stay tuned. There is a way to conserve battery by
sending this module to sleep mode. Please read through the pingpair underscore sleepy example
for more details. I have provided the link in the description below. These modules work very
well when the transmitter and receiver are close to each other. If the distance is too big you may
lose communication. The signals generated by these modules are very sensitive to power supply
noises. Depending upon the amount of noise the communication rate may vary. Setting the maximum
output power can also improve the communication range. If there is an obstacle in the line of
sight you may see multiple dropouts. Reducing the data rate can also significantly improve the
performance. A speed of 250 kbps is more than enough for most of our projects. Using an external
antenna can also significantly improve the transmission rate. Another potential source
of noise for RF circuit is Wi-Fi. Especially when someone's network is set to the same channel. Since
Wi-Fi mostly use the lower frequency channels it is recommended to use the highest 25 channel for
your module. Thanks again for watching this video. I hope it helps you. If you want to support me you
can subscribe to my channel and watch my other videos. Thanks. See you again in my next video. Bye now.