Arduino Wireless Communication - NRF24L01 Tutorial
HTML-код
- Опубликовано: 27 авг 2024
- howtomechatron... ► Find more details, circuit schematics and source codes on my official website.
In this Arduino tutorial we will learn how to make a wireless communication between two Arduino boards using the NRF24L01 transceiver module.
Visit HowToMechatronics.com for more Tutorials, Tips, Projects and How It Works videos:
► howtomechatron...
Like my page on Facebook:
► / howtomechatronics
Add me on Google+:
►plus.google.co...
Music: Aduro by Jens Kiilstofte (machinimasound.com/music)
I literally got my 3 NRF24L01 modules today and was trying to find a good tutorial, and now you uploaded this, thanks!!
i was lost between using wifi or xbee or RF and what do you know our friend decided to upload a video !
Go for the NRF, I also got my wifi-module today and it's terrible. If you're going for the wifi module buy one which is build in into an arduino, like the Wemos!
I love being 4 years later
clear and helpful tutorial, I like that you go in depth on what you are doing unlike many other tutorials, thanks
Noticed one small error in the drawing that I'm sure has already been mentioned but not recently maybe. On the Nano in the picture the green wires are running to 10, 11 and 12 rather than 11, 12 and 13. 13 is on the other side of the board. Only I would follow the picture and miss that the numbers everywhere have it correctly. Don't want to say how many hours I messed that up and I've used SPI before and actually was bummed because it uses my little flashing LED pin 13. Not at my best today.
Really great video and your link to your page really helped. Super. I don't know I could have linked them without it. Many thanks.
Yeah, thanks for the remark.
yeah I struggled with them hours too small mistakes
What do you think, Can I use this module with just AtMega328 (without Arduino)?
@@plebaniaurydzyka8356 Yes you can. I have used the Atmega 328 on its own for use in model aircraft. Works great.
@@HowToMechatronics Man, just mark it in your video and on your website... you cost many people plenty of time...
Thanks, this was a huge relief, because I've watched several other tutorials, and it didn't work then. I really appreciate you
Great video thank you so much! I just wanted to bring to your attention that the 2 of the 3 green wires at 2:32 for the arduino nano are incorrect. MOSI is correct. But you have SCK running to 12 when it should be 13. And MISO is running to 10 when it should run to 12
And in the code you need to swap ce and csn pins around ( 8csn , 7 ce )
yoo
i need your help
Thank you for posting this tutorial! I was at a wireless data communication bottle neck on a robotic arm project and you just saved the day! Great job my friend! So happy!
I believe I just discovered a small mistake in the video (with the Nano/Uno at least, I am using 2 Uno's) that was causing me some headache in figuring out what I was doing wrong. If you're having trouble like I was maybe this will help you (for me, the receiving end was getting a flood of blank input and eventually getting some weird characters before outright stopping (viewing with the serial monitor).
At 2:30, you list the CSN as being connected to Pin 8 and CE to 7, for the Nano/Uno. However, if you look at the code at 2:40, you have the line:
RF24 radio(7, 8); // CNS, CE
Which I assume implies that you have the CSN connected to 7 and CE to 8, in their respective order. This is reversed from the list 10 seconds earlier. All I had to do was swap which wire was going to which pin and suddenly everything is working fine. Just swapping the lines in the code should have worked too.
I ran into the same problem as well. I think the comment should have stated RF24 radio(7,8) //CE,CNS...... that's the set up that worked for me. Eventually switching them around just like you did. Instead of switching the wires, i just switched the number on Arduino
Just finished testing your code, it works! thanks.
I add "radio.setChannel(0)" after "radio.begin" at both transmiter and receiver sketch. It is to make sure both receiver and transmeter in the same channel. Since it is 125 channels altogether then i use 0 at both. Thanks again.
Nice introduction to the NRF24L01. The diagram of the Arduino Uno/Nano at 2:30 seems wrong but the arduino mega seems correct. Would of been nice to see the demonstration at the beginning with a clear view of the wiring. Thanks for the tutorial.
Finally it works. Don't use breadboards to make the connections because the breadboard turn into a small capacitor.
Huh, here's my story. I was fixing it and fixing it, and Was unable to get it to work, not even the basic transmission, and kept trying everything, everyone's code, everyone's library, all lead to failure. I was stubborn and didn't want to give up on them. And then I finally decided to try and replace one of the modules with the 3RD one I had lying around, and wola! it worked.
-I was struggling so hard, and didn't want to test the other module because I was kinda lazy and kept thinking that there is some interference in the wires, or that my Arduino 3.3V was insufficient so I ordered 3.3V linear stabilizers and the outcome was the same, then I tried wrapping the ground wire around the Miso, still nothing, not working.. and then for the last resort I swapped one of the modules, and luckily enough I swapped the broken one on the first try and the Transmission began, So let everyone know, if you're unable to get it to work, not even any transmission,and you checked everything, then perhaps you really have a faulty module, and it isn't the bypass capacitor nor the insufficient arduino 3.3 power supply.
I bought 3 Pa LNA modules and only 2 works, but even to get those two to work I had to attach 3.3 ams1117 regulators and 1000uf capacitors. But now they work perfectly with that addition.
I think I will have to refer the datasheet to actually check , but I've noticed some modules don't have all 4 resistors connected while others have ( they are the 4 resistors along with one capacitor all parallel in the middle of the board,) on some modules all the resistors are there but in some others they are not there. Either ways all those modules work.
Really easy to understand and helpful!!Thank you! It's the first video of coding in arduino that I understand
Glad it helped!
Finally I got it working after two days of attempts trying to find out what was wrong, I replaced the Nano board with Uno board.. Thank you very much.
Did you have problems with both demos, or just the second one? I'm using two Nanos. I got the first demo to work, but not the second.
Awesome work. You have saved me a LOT of time.
Glad I could help and thanks for the support!
Nice tutorial but there are a couple of things that I needed to correct in order to get both examples to work.
First, the wiring diagram for the Nano is incorrect. Use the written pin assignments at 2:33 in the video.
Second, in order to get the second example to work, I had to change this line in the transmitter code - while (!radio.available()); to if (!radio.available());
Thank you for all the help in getting this project working. Now to add more servos!
@Mateo M wrong, you can use same pins as on Nano board, 11, 12, 13 and 7,8 or whatever pins you decide to use as CE and CSN pins. Nano, Uno and Pro Mini board have the same pins for SPI.
@@daliborbaricevic685 he was right. the wiring diagram is incorrect.
Excellent! Thanks. And also, thanks for not drowning your videos with 5h1t 'music'! Your voice is important and it comes across well! 👍
Glad you like it!
Hi people, i think i may have found the problem some of you are facing...on 2:26, the connections of MOSI, MISO and SCK are in the pins 10, 11 and 12....buuuuut, the pins for the SPI connection are 11, 12 and 13...and actually on the description below the Nano pin numbers are right, its the image that fools us...
Can confirm, I found out the hard way. The picture is wrong, but the description is correct. (at least on the Nano)
how much is the range of them?
@@felixbaum2180 About 85 meters in open space, there are some other models with antenas that can go up to 900m...
@@davidporras761 Thanks for the quick response. 85m are perfect. I just need to transmit over about 30m, but within my house, so through a few walls of concrete
@@felixbaum2180 Mmmm concrete walls could make the signal loose too many packages, 15-20m should be fine if there are no more than 3 walls, but with 30m im not sure...
In that case you could use a module with antena (anthena?) as transmitter and a normal one as receiver, thats what i always do actually, just to be sure haha...
Am sorry but there is a mistake in the way the Arduino nano is hoocked up for SPI (the 3 green wires are wrong and the pin 13 is used). Great otherwise :)
Excellent point. Hardware SPI is really important for this module due to the high bandwidth if you want low latency
@@WungoBungo Quick question. Do you know roughly what the latency is?
@Allan Thiago I hacked her account also and she wants to meet up with me again.
Thank you for the video! simple and easy:) GUYS ALL OF YOU WHO CANT GET IT TO WORK! I spent days and night to bring it to life, I tried all projects and all examples but haven't succed. The problem was i had to add a capacitor between the gnd and 3.3v pins on rf24, it solved the problem:) and try to set pa level on max. U need to add 1-100 microF capacitor.
i cant get it working, what is the reason to add the capacitor?
@harithalau1970 reduce voltage spikes wich could interfere with the radio signals and making it unreliable
Thanks, with your very informative videos I am learning a lot of things. And everything I build with arduino following your tutorials works well. Thanks
Thanks, I'm glad to hear it!
Great Video, the only one I've seen so far that has Send and Receive functions on both ends.
Glad you found it useful. Cheers!
@@HowToMechatronics On another video of yours, you used a breadboard to assist soldering headers to Arduino's...Great Idea, did it earlier today.
OUTSTANDING VIDEO! Thank you very much. Not only did this completely explain the subject matter, I enjoyed the precise articulation which compresses a rather large amount of information into an efficient time line.
I did have one question. Instead of only 6 receivers, I need to expand this. So, would you have ideas to share for, say, adding a second group of 4 receivers? One group of 6 and another set of 4? If you have a blog, I'd be happy to continue this conversation in that manner. Thanks.
Best intro to wireless communication! Thanks!
Hi. I am using web editor and I have tried desperately again and again to get the NRF24L01 to work. I keep getting either no messages or weird encrypted text on the serial monitor. I need help.
i have the same problem, did you fix that?
@@barakyona Yes! i fixed it a long time ago
@@barakyona Do you need me to help you?
Blink yes bro do you have a discord? Or Facebook? So we can talk
@@barakyona I do! Add me @ Andrew Bejger on facebook
Great experience, I used 2 NANOs. Comments about pin 13 helpful ... worked first time. Thank you !
Sir please make lecture on weight sensor in detail . Your video lecture is really nice and informative .
Hello, Youve connected CSN to 8 and CE to 7 but in code you mentioned otherwise? why?
when i try to recreate the first example. the code sends a message but in the serial port on the reciever nothing is recived
any idea to why
Thanks for a great tutorial. You cleared up a lot of stuff I was confused about.
Good video! Very thorough and helpful.
If anyone gets blank output in serial monitor......then You must check the connection..... actually pin 11,12,13 in the diagram is incorrect.......13 is the opposite side...... Better see the pins and connect it yourself.......
Anyway great video...
To make it easy for Newbies Note in i.e Getting Started Program find code RF24 radio(7,8); alter to reflex say RF24 radio(9,10); //CE, CSN Please note CSN on Mega should be on 53 if not then add pinMode(53,OUTPUT); First line in void setup()........ Due does not mind as it expects pin 4,10,53 to be CSN. Uno only pin 10 for CSN This then conforms to ARDUINO SPI Library
MY Colour Coding and pin out for nRF24L01
Pin 1 Brown 0v Ground Pin 2 Red +V 3.3v
Pin 3 White CE Pin 4 Black CSN
Pin 5 Purple SCK Pin 6 Grey MOSI
Pin 7 Blue MISC Pin 8 Orange IRQ
Uno Colour Mega Due Due Header SPI
9 Any pin White 9 Any pin 9 Any pin CE
10 Black 53 4,10,53 CSN/SS
11 Grey 51 51 ISP-4 MOSC
12 Blue 50 50 ISP-1 MISO
13 Purple 52 52 ISP-3 SCK
Hey dude codes for printing hello world for both transmitter and receiver are compiling without error but not working
See my comments above. (Sort by date.)
dadigitechman Pin 8 is the only optional pin.
@@dadigitechman You don't have to use pins 7 and 8. I used pins 9 and 10 and it worked fine but you have to define the pins you are using in the code. The code here defines pins 7 and 8 for CE and CSN so you need to modify the code. This does work.
@@dadigitechman It's reasonably straight forward. The only line of code you have to change is this one "RF24 radio(7, 8); // CE, CSN" just type in (9,10) if you plan on using those pins on the arduino. I agree that using pins 9 and 10 for CE and CSN makes the overall wiring much neater. Follow the link in the video description to the tutorial for the full code as it is good and all of that code works. You may need to modify the code for your own application depending on what your project is and what you are trying to achieve but that is up to you to do some research and play around to figure out what part of the code you need to modify. It is very possible that your wireless modules are faulty and I have seen faulty ones from China in the past. If you follow the tutorial in this video exactly right and it doesn't work then it may be your modules.
@@dadigitechman Yeah do a video and I will watch it and see if I can help.
Brilliant video. Best explanation yet on how to code for nrf24L01. Many, many thanks for posting this tutorial.
I thank you for this video and the tutorial link, I learned a lot from you.
I share your creations and put thumbs to the sky. ;)
Continue like this, I become a big fan ^^.
Thank you!
WoW HOW EASILY U EXPLAINED THE NRF24l01 THANKS A LOT
just something I noticed, in the video your comment when you created the radio object you have it read as CSN, CE but on your website its the other way around CE, CSN
Congratulations! excellent project. It would be great if you make a wireless project using Xbee modules. I know these devices are expensive, however, you can consider this project for the future.
Nice work! I am sitting here trying to think how I can implement this in some of my projects.
I'm confused, on the picture of Nano you have connected ports 10, 11, 12 to nrf2401, but you have written in the script ports 11,12, 13. I don't know what to use, and my experiment doesn't work! What could I do next?
Thank you for your tutirial it was very good as I am setting up an RC module now, but having trouble with noise as I can't read what is xmitted? baud rates are set to 9600 and I still have not found the problem?
Rick
IDK if this is just for me but contrary to the code in the video @2:55, the CE pin should go on 7 and the CSN pin should go on 8.
thank you have helped me with the nrf24L01 it was causing me a headache.
Thank you my NRF modules are working perfectly with 2 arduino nanos also you missed pin 13
Thank you! The bilateral communication thing is very useful!
Excellent! Clear and concise example, many thanks.
lol, i am using arduino and RF transceivers for the first time, and was thinking i would have to do some crazy 8 bit encoding and decoding between the different duinos, this is so much simpler xD
i`v been waiting for a new video , and surprised you made the video im looking for
it doesn't work. first example well compiled and uploaded but nothing received at receiver side. WHY?
I think if you use signal modulation rather than simply the channels to pair transmissions with receivers you can probably have many more than 125 devices within range of each other
One tip which may help someone: if you use NRF24L01 + adapter, connect the adapter to the 5V pin, cause in my case it doesn't work with 3.3V
There is more versions of NRF24L01 there is 3.3V and 5V version
I LOVE YOU, this fixed everything! lol
Thanks for a very useful video. That has got me started with these great transceivers
Thank you so much, you are the one who's sketch and connection works. But I still have a question. Why nothing works when I change power supply. It works only from 3.3 v Arduino output. Other power supplies (batteries, MB-102...) Don't provide possibility to work properly for nrf24l01
Thanks. Clear and helpful tutorial.
Nice short and to the point.
Can I send and receive 2 push buttons?
This is a great video, it helped me out a lot.
However: your wiring diagrams on the Arduino Nano are wrong!
The SPI wires should be connected to pins 13, 11, and 12 but according to the picture both in this video and on your website they are connected to pins 12, 11 and 10.
The text underneath shows the correct pin numbers, but the picture is clearly wrong since pin 13 is on the other side of the board.
Took me nearly an hour to figure out why my sketches did not work, until i found a different wiring diagram on another website.
Kind of my mistake, since i went purely by the picture instead of checking the pin numbers. But still...
Anyway, thanks for the otherwise awesome tuturial.
Hannes Größlinger : Right the same! Until I saw the pin 13 for SPI and everything hoocked up in the same side of the nano :3
Hi, Hannes, I followed your instructions to re-connect my circuit, but only question marks show up
Why doesn’t my sketch upload to my arduino uno it says “can not compile the sketch to arduino uno” and every project that includes nrf radio module does the same error while compile the sketch
very clear and simple explanation, thank you.
HaiTHaM KoBeIssI go to serial monitor
I've got in the serial port monitor message like this but upturned question mark -->>> "????????????????????" What is the problem? I've done everything like in this video :O
Same problem bro
Same here
Any solution
Sprawdziłeś czy ten cały numerek który jest w Serial.begin zgadza się z tym na dole monitora szeregowego który otworzyłeś?
@@woogieboogie9803 English
Hello. Thanks for the excellent video but I am puzzled by your Tx code in the bi-directional example. It seems that the loop will freeze if the receiver does not send any message. What's the reason for the line of code, "while (!radio.available());" ??????
hello, thank you very much for this tutorial, I connected everything as in the diagram, it works, there is communication, unfortunately the SG90 servo dances, vibrates constantly, there is no stable operation, there are interferences, I added 10uF capacitors, where do these interferences come from, why is this happening?
You are gift of God sir 🙏
In this project, only one input is allow at once, so if I want to make it read and write at the same time, I need to use to pair of NRF24L01, right?
My nrf modules don't want to communicate with each other, I tried your test code as well as bidirectional communication code, they upload successfully to board but nothing happens. I tried changing nrf modules and my Arduino but still no any output in serial monitor as well as servo outputs
You need to get an nrf24l01 breakout board and wire the arduino 5v vcc output to the breakout board input vcc
@@arhamthowheed9471 thank you very much for your reply but I have soldered them directly on board and I am using a Arduino mega board which at 50ma output current at 3.3v and I am also using a 220uf capicitor directly on nrf board. After fraustations I quit with loss of time and money. Any help will be appreciated.
@@AmateurInventor Ok all you need is 2 arduino boars, 2 nrf24l01 modules without a capacitor soldered on them and 2 breakout boards, assuming you already have 2 arduinos, 2 nrf24l01 modules and breakout boards should cost you about £5, when wiring them wire teh 5v pin on the arduino the the nrf24l01 breakout board input vcc. if you need more help add me on discord___> snakeviper123#2297
@@arhamthowheed9471 But unfortunately the place where I live, I can't import these from any international sellers like Amazon or eBay. Please suggest me another way.
Serial monitor show random output at reciver end.....what should I do....plzz help me out
Hello, thx for this tutorial. I have a problem, I uploaded the exact same code on my Arduino Mega and my Uno, but it's not working. I use my mega as a recepter and It justs write some squares and '?'. Have you got any idea ?
same i got last night . any solution ?
You should check a baud rate in serial monitor which you have coded, may be that can help.
@@rvlad13 That is exactly the problem. The baud rate is not matched to the clock speed. because UART has no clock (its asynchronous).
me too i changed the baud rate and stil the same problem
I'm 4 years late on this but I was getting something very similar. Try swapping the 7/8 pins for the CSN/CE wires going to the nRF24L01. If you look, at 2:30 and 2:40 he has the pins reversed between the explanation/code.
Dejan Nedelkovski your sketch for the nano says SCK is connected to D10 while the list says D13. Just in case you diddent notice ;)
great video. I am just begginer and I did not manage to make this project. can anyone tell me what pins i should replace when using arduino uno in the place of leonardo. thanks.
Can i use ' switch case ' which is controlled by push button.. To change the joystick mode for controlling dc motor and servo motor?
Thanks. Exactly what I was looking for.
i have 2 x rfx2402e module from wltoys v666-ufo, but i try with nrf library not working, is there any other library?
can you help me for my case?
I tried the tutorial to display 'hello world' on the receiver module but nothing happens, can you suggest a fix? There was no error and the library was correctly downloaded, but nothing is happening.
Try swapping your wires for the 7/8 pins (CSN and CE), or swap the numbers in the code when you create the radio. If you notice, at 2:30 and 2:40 he has the pins reversed between the explanation and the code. Just a small mistake in the video I believe, I was getting the same thing until I figured it out.
@@EnvoyOfFabulousness Thanks! I'll try it out.
Man you are great ! All is so clear clarify. Thanks
I'm using the same code as yours and same connections, but still not working, nothing appears on the serial monitor of the receiver, what could be the problem? I'm using UNO as transmitter and NANO as receiver.
I feel like the code"!radio.available()" might be the problem. Make it "radio.available()"
If this code could work without "
nRF24L01.h" why would you include it?
i did everything you said and showed in the video but i can't manage to do it i only receive weird stuf I also changed the connections to what you put under the drawing instead of copying the drawing.
Having an issue using 2 arduino nanos where no data is being received, with a very occasional ? symbol at the start of run code on the receiver
Very good!!! Congratulations by explanation!!!
i have a couple of Qs
1) can it reach 1km?
2) is both connected with any laptop?
3)is it wireless?
please answer these Q sir
great video, comprehensible tutorial, NRF24L01
Absolutely great stuff, thank you very much!
Thank you, glad you enjoyed it!
Awesome tutorial! Can you make another one using two esp-01's?
Interesting videos, thank you. The first sketch worked for me. I used the Nano IPSP rather than the numbered SPI pins. For the second sketch, I also used IPSP with identical hookup of the wires for the receiver/transmitter. Also, I used a potentiometer instead of a joystick. I ran the servo side off battery and the led side off computer. I verified multiple times that wiring was correct and that send and receive channels were appropriately reversed on the 2 Nanos. Nothing I could do succeeded in making the second sketch run. Presumably the error is mine and not in the sketch, but I cannot find it. It is tedious to do the wiring and then have the project fail, but maybe I've overlooked something obvious and will eventually find it.
hey you might not remember but how did you get this working? it keeps returning false for radio.available so nothing in the if statement runs.
Fixed it my connections were wrong hehehe
for some reason the first code isn't working for me is there any other setup I need to do?
I'm using an uno and an uno Rev 2 and I'm just getting an overflow of symbols until it stops cold.
any ideas?
Did you solve it?
as always from the first minute i feel like i know this module already you explained it so well that i will change my project from wifi (hard for me) to RF ..... excellent video love it...i have a question for you can the modules be configured to be like 6 emitters a single receiver ?? i have a project and i need 50 separate transmitter boards to send data to the same receiver so my solution is i will have every board pass data to the next board that way i can get data from all of them !!! can i do that ????
this is awesome dude thank you to help me
Thanks. It's easy to understand example
Great tutorial. The simple sketch in the beginning help me a lot.
One question though. The line const byte address[6], is the 6 referring to the pipe being used. Nobody seems to explain what the number in brackets is referring to.
Thanks again for the great tutorial. Jeff
Thanks for the fast response. That makes sense.
How many receivers can receive the same signal through a single common transmitter pipe address..?
Pls clarify the doubt...
Thank you dear for making this tutorial.
best tutorial for nrf .thankx
can i use esp8266-01 instead of NRF24LO1
There seems to be no connection when i switch the modules from integrated antenna to external antenna. When i use the module with the integrated antenna, it works. However when i switch to the external antenna, i get nothing. I was wondering if the code works for the external antenna module.
Super Helpful Tutorial!! Thank you!! 👍👍👍
Nice Man!
Good tutorial... Excellent learning for us all !!!
Can you add link to download code for quick implementation....Appreciate your extra efforts
Hi Dejan,
You are doing a great work!!
Can you tell me which software you are using to edit the videos? They look perfect
I use 2 arduino uno and its not working? Its displaying question marks. Can you tell me sir what is the problem
i get the same problem
Sure
Hi may I ask you,the transmitter can get signal under deep water?