Water Safety Sensor Using NRF24L01

Let everyone know about your works in progress

Water Safety Sensor Using NRF24L01

Postby Roys29 » Sat May 21, 2016 8:45 pm

Many thanks to Brennen for providing his NRF24L01 code. :D Using MikroElektronika's Easy Pic 6 development board and MikroBASIC Pro for PIC, NRF24L01 modules I purchased on ebay, and Brennen's tutorials I built a water safety sensor for my house. :idea: Back in February the water line to my refrigerator ice maker broke and damaged my kitchen and dining room. After the repairs I didn't want that to happen again so I built a water sensor/transmitter to put behind my refrigerator, and a receiver/valve driver to shut off the water. If the sensor/transmitter detects water it sounds an alarm and sends a signal using the NRF24L01 to the receiver/valve driver consisting of the sensor number. (I plan to install 3 sensor/transmitters.) When the receiver/valve driver receives a signal it shuts off the main water line into the house using an electric ball valve. An LED blinks the number of the transmitter that sent the signal. After I built the units they worked first time thanks again to Brennan's tutorials.

I did find one confusing point in his tutorial 0. To read the TX_ADDR he states, "First, you would bring CSN low and then send the command byte ‘00010000’ to the 24L01. This instructs the 24L01 that you want to read register 0x10, which is the TX_ADDR register. Then you would send five dummy data bytes (it makes absolutely no difference what the data bytes contain), and the 24L01 will send back to you the contents of the TX_ADDR register. Finally, you would bring the CSN pin back high.” Ok, is that send 5 dummy bytes with 5 write commands, then read 5 data bytes with 5 read commands, or do I write one byte then read one byte five times? I searched Brennen’s libraries for hours looking for the answer, and it turns out that the correct answer is neither!

Since the SPI interface is a synchronous serial interface every write via the SDO line is also a data read on the SDI line. So to read a byte from the NRF24L01 you perform a write of dummy data. As the dummy data is being sent on the SDO line one bit at a time, the correct read data is also on the SDI line one bit at a time. As the 8 bits of dummy data are sent, the 8 bits of read data are being received at the same time so when the operation is complete the read data is in the SPI buffer.

Something else not clear in his tutorial 0 was that each NRF24L01 command requires that the CSN line be set low, then set high after the command is sent and any data is sent/received. I tried to keep the CSN line low while sending multiple commands and data and this resulted in weird results. :roll:

I am currently testing my units for stability, and if they pass, I will post an article. Thanks again Brennen for your excellent tutorials.
Roys29
 
Posts: 2
Joined: Sat May 21, 2016 8:19 pm

Re: Water Safety Sensor Using NRF24L01

Postby brennen » Mon May 23, 2016 2:08 pm

You're very welcome! I'm glad you got some use out of the tutorials. :)
brennen
Site Admin
 
Posts: 394
Joined: Sun Aug 17, 2008 2:15 pm


Return to User Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron