Remote sensing with connection loss detection using nRF24L01+ modules
When using 2-way communication between 2 RF modules, it is very useful to be able to detect loss of communication between the modules. Especially with remote sensing applications, you don't want to lose data unnoticed or miss an alarm due to loss of connection.
The nRF24L01+ are interesting low cost RF modules that enable 2-way communication between 2 or more modules with the help of a microcontroller. The modules have an SPI bus (serial peripheral interface) that allows to configure and control the nRF24L01 module via a microcontroller. Many examples of projects using the Arduino in combination with this RF module can be found on the internet.
With the project described here, i want to add an extra feature that makes use of the 2-way communication to detect the loss of communication between the "transmitter" and the "receiver". It's a bit odd to talk about a transmitter and a receiver when using 2-way communication, since modules act as a transmitter AND as a receiver at the same time. For clarity we label one module as the transmitter because it's main task is to transmit the state of the PIR sensor to the receiver and the other module we label as receiver, because it's main task is to receive the state of the PIR sensor.
The ability to detect the loss of communication is very useful for remote sensors, because when there is no communication, an alarm is not being transmitted or data can get lost without noticing. It is also useful when installing the sensor to check if both nRF24L01 RF modules actually "see"each other and are not out-of-range.
A practical application for remote sensing is f.e. a PIR sensor or a long range beam break detector that is installed outdoors and you want to be notified indoors when the PIR sensor gets triggered. You also want to be notified when the communication is lost, so you don't miss an alarm.
In "arduino-nrf24l01-remote-sensing.png" you can see an overview of the project and how both nRF24L01 modules communicate with each other and how the detection of loss of communication is implemented..
The nRF24L01 needs to be powered with 3V3 but the I/O pins of the nRF24L01 are 5V tolerant. So connecting the nRF24L01 SPI bus directly to the 5V Arduino Pro Mini is no problem. The power supply bypass capacitors should be placed as close as possible to respectively the Arduino and the nRF24L01 module to suppress all the switching noise coming from these chips. This is often overlooked in Arduino projects and can cause all kind of unexpected problems. It is also good practise to use multiple bypass capacitors in parallel with different values. F.e. C1 = 100uF and C2 = 100nF. This is done because different capacitor values have different frequency behaviour. By putting them parallel a more effective filter is created over a wider frequency range.
In the schematic of the transmitter, a 5V PIR sensor is used. When the PIR sensor requires a different voltage than 5V, this can also be accommodated. Because the 5V PIR sensor has a 5V level output, Q1, R4 and R3 can be omitted and the PIR sensor output directly connected to pin 4 of the Arduino Pro Mini. When doing so, the Arduino sketch needs to be adapted, so the trigger input is high active instead of low active :
Q1 acts as a voltage level translator in case sensors are used that have f.e. a 3V3 or lower output voltage. This way you can connect other types of sensors without changing the hardware.
The red LED will flash when the connection between the transmitter and the receiver is lost. When the connection is restored, the red LED will stop flashing and everything will work as normal again.
The blue LED indicates that the PIR sensor detects motion. This trigger event will be send over to the receiver as a trigger code byte. When the PIR sensor does not detect motion, then a live beat code will be send to the receiver. This way the receiver knows if there is a motion trigger or not.
The receiver will send the same code that it received from the transmitter back to the transmitter as an acknowledge. Because of this continuous communication between the transmitter and receiver, both can easily determine when the connection is lost.
The receiver circuit is almost identical to the transmitter circuit.
In the receiver, the red LED will start flashing when the connection is lost and the Arduino will send a tone to the speaker using the tone (x, y) command, with x = frequency and y = duration. The speaker is an 8 Ohm version and is connected to the Arduino via an electrolytic capacitor. The higher the value of the capacitor, the higher the speaker volume will be.
I've chosen for a low frequency tone because that is less annoying/disrupting than higher tones.
The blue LED indicates when motion is detected. You can connect a relay to this output pin 3 via a transistor to power on/control any other device when motion is detected.
The project is just a basic example of how to detect loss of communication with 2-way communication modules..
Youtube video : https://youtu.be/lV0vnsQz0P0
With the project described here, i want to add an extra feature that makes use of the 2-way communication to detect the loss of communication between the "transmitter" and the "receiver". It's a bit odd to talk about a transmitter and a receiver when using 2-way communication, since modules act as a transmitter AND as a receiver at the same time. For clarity we label one module as the transmitter because it's main task is to transmit the state of the PIR sensor to the receiver and the other module we label as receiver, because it's main task is to receive the state of the PIR sensor.
The ability to detect the loss of communication is very useful for remote sensors, because when there is no communication, an alarm is not being transmitted or data can get lost without noticing. It is also useful when installing the sensor to check if both nRF24L01 RF modules actually "see"each other and are not out-of-range.
A practical application for remote sensing is f.e. a PIR sensor or a long range beam break detector that is installed outdoors and you want to be notified indoors when the PIR sensor gets triggered. You also want to be notified when the communication is lost, so you don't miss an alarm.
In "arduino-nrf24l01-remote-sensing.png" you can see an overview of the project and how both nRF24L01 modules communicate with each other and how the detection of loss of communication is implemented..
The nRF24L01 needs to be powered with 3V3 but the I/O pins of the nRF24L01 are 5V tolerant. So connecting the nRF24L01 SPI bus directly to the 5V Arduino Pro Mini is no problem. The power supply bypass capacitors should be placed as close as possible to respectively the Arduino and the nRF24L01 module to suppress all the switching noise coming from these chips. This is often overlooked in Arduino projects and can cause all kind of unexpected problems. It is also good practise to use multiple bypass capacitors in parallel with different values. F.e. C1 = 100uF and C2 = 100nF. This is done because different capacitor values have different frequency behaviour. By putting them parallel a more effective filter is created over a wider frequency range.
In the schematic of the transmitter, a 5V PIR sensor is used. When the PIR sensor requires a different voltage than 5V, this can also be accommodated. Because the 5V PIR sensor has a 5V level output, Q1, R4 and R3 can be omitted and the PIR sensor output directly connected to pin 4 of the Arduino Pro Mini. When doing so, the Arduino sketch needs to be adapted, so the trigger input is high active instead of low active :
#define TRIGGER_ACTIVE_LEVEL 0 // 0 = low active, 1 = high active
Q1 acts as a voltage level translator in case sensors are used that have f.e. a 3V3 or lower output voltage. This way you can connect other types of sensors without changing the hardware.
The red LED will flash when the connection between the transmitter and the receiver is lost. When the connection is restored, the red LED will stop flashing and everything will work as normal again.
The blue LED indicates that the PIR sensor detects motion. This trigger event will be send over to the receiver as a trigger code byte. When the PIR sensor does not detect motion, then a live beat code will be send to the receiver. This way the receiver knows if there is a motion trigger or not.
#define LIVE_BEAT_CODE 0x11 // code that is transmitted as a live beat signal from transmitter to receiver #define TRIGGER_CODE 0xAA // code that is transmitted when transmitter detects activity at the trigger input
The receiver will send the same code that it received from the transmitter back to the transmitter as an acknowledge. Because of this continuous communication between the transmitter and receiver, both can easily determine when the connection is lost.
The receiver circuit is almost identical to the transmitter circuit.
In the receiver, the red LED will start flashing when the connection is lost and the Arduino will send a tone to the speaker using the tone (x, y) command, with x = frequency and y = duration. The speaker is an 8 Ohm version and is connected to the Arduino via an electrolytic capacitor. The higher the value of the capacitor, the higher the speaker volume will be.
tone(SPEAKER_PIN, 50, 150); // output a tone of 50Hz for a duration of 150ms on the speaker output
I've chosen for a low frequency tone because that is less annoying/disrupting than higher tones.
The blue LED indicates when motion is detected. You can connect a relay to this output pin 3 via a transistor to power on/control any other device when motion is detected.
The project is just a basic example of how to detect loss of communication with 2-way communication modules..
Youtube video : https://youtu.be/lV0vnsQz0P0
Updates vom Autor