HOW TO: Use a NRF24L01 + Arduino to remotely control a motor

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Let us know when the garage opener project video is out!

๐Ÿ‘๏ธŽ︎ 3 ๐Ÿ‘ค๏ธŽ︎ u/swingking8 ๐Ÿ“…๏ธŽ︎ Jan 11 2016 ๐Ÿ—ซ︎ replies

Really good and helpful video!
Keep it up, you earned yourself a new subscriber! :)

๐Ÿ‘๏ธŽ︎ 2 ๐Ÿ‘ค๏ธŽ︎ u/KaptainKugelkopf ๐Ÿ“…๏ธŽ︎ Jan 15 2016 ๐Ÿ—ซ︎ replies

Very helpful, thanks!

๐Ÿ‘๏ธŽ︎ 1 ๐Ÿ‘ค๏ธŽ︎ u/EmperorOfCanada ๐Ÿ“…๏ธŽ︎ Jan 10 2016 ๐Ÿ—ซ︎ replies
Captions
if you need to communicate from one Arduino to another it's pretty hard to beat the NRF 24 ello what these things are cheap they're very reliable easy to use are readily available and all they're great little things they've got a lot of advantages if you're using them for say a remote control type device I'm going to be putting one into a replacement garage door opener for instance I'm probably put up a video of that entire project cuz it's kind of simple and cool but anyway these things have a variety of advantages they don't use a lot of power they do use some though and the startup time is very quick from a cold start you can have one of these guys talking to another one in about a tenth of a second and the codes fairly straightforward not as easy as some but it's fairly straightforward the little chips on here take care of a lot of error correcting and dealing with frequencies and whatnot and so they do a lot of work for you now there's a lot of other options we've got for instance Bluetooth we could use that uses fewer pins this particular one has a great pin out these guys here a terrible pin out very breadboard friendly CF don't put female wires onto the moon make it easier to talk to them or build some kind of adapter but the Bluetooth uses fewer wires but it's got a longer startup time it's more expensive two or three times as much and but you can talk bluetooth to bluetooth it's not a problem and these have the advantage that they can talk to laptops desktops whatnot other options would be the 80 to 66 series of chips and modules which this one's really breadboard friendly it's got a nice pin out on it but these guys from a cold start they have to establish a connection with a router of some sort or with each other and that can take 5-10 seconds they're powered our needs are finicky so they require more circuitry to support them and they're great for many usages but they are use cases but for just straight Arduino to Arduino they're great now on the 4 or 15 megahertz range we've got these little guys and I wouldn't wish them on my worst me the range is about that for our part I'm barely exaggerating I mean even with a good antenna there they're not reliable easily interfered with and you have to write a lot of code to make them reliable they're cheap is about their only benefit but don't buy them don't use them they're terrible but what you'd find in a cheap remote-control car from 1970 anyway back to these there the codes fairly simple they take a 3.3 volts in all the rest of the pins are 5 volt tolerant and they're pretty nice now I've got a transmitter and receiver I've got a transmitter here when I say a transmitter they're both transceivers but this is the controlled controlling circuit and this is the circuit that's to be controlled they do chat back and forth we've gotten our doing out you know it's connected to one of the transceivers and the wiring of this and this are identical and the code is nearly identical but the uno has an interesting capability that it puts out just that little bit of extra current that it can run this thing by itself so when you are developing on this if you don't put enough current into it it just doesn't work you don't really know why it's not working it doesn't give you some kind of low power error code or anything it just doesn't work so if you use the you know straightforward I'm using a tiny little servo so I can run that off the 5 volt rail of you know usually you run motors through some other kind of motor controller but for a little server like this and no load you know is fine so this is getting from three point three this is getting 5 volts which no other wiring no resistors or anything like that and up here we have a transmitter or the controlling thing is I say these are going to actually talk back and forth so they're both transmitters and receivers and this is a nano it's 3.3 volt rail does not have enough power to power this so I've added this external power source it has 3.3 volts coming up here and so I have the one wire running into the transceiver unit and Thresh the wires there's five of them go down to the you know this one also has two buttons so we have a we have a start button which is the white one and we have a stop which is the right one so if we send thing up the servo we hit start and it begins sweeping back and forth between ten and a hundred and seventy degrees very simple bit of code trying to do anything amazing then we hit a stop code and it stops so we can start we can stop and now we'll go up to the Fritzing diagram because this is a wiring mess so we have a Fritzing diagram here which is a much simpler thing you can see all the wires going to the Nano in this case and they are the control wires there's five of them then we're getting our three volts in from this external power source common ground two buttons with their pulldown resistors and a quick explanation of a pulldown resistor is basically if you don't connect this this wire here when the button is not pushed is just acting like an antenna if you leave it there you're going to get weird spurious signals going into your digital pins which means effectively the as far as you're concerned if you remove this resistor these buttons will just get pushed randomly without anyone actually pushing them this basically draws a tiny tiny bit out it's a 10k resistor so when you send power into the button it's not really a short very little of the power will go this way because this is 10k this wire it best is maybe 2 k to our 2 ohm resistor and so the power flows through you get a nice positive voltage high and when this is here though it's just enough to eat the spurious signals coming in and you get a nice voltage low so on and off is basically so you need this pulldown resistor now there's ways to force the Arduino to be its own pulldown resistor but we're not doing that for this I'll show you there's a side benefit if you didn't know what a pulldown resistor was about that's what it is and they just go into two digital pins it's all pretty straightforward so now we go to the we go to the receiver or the controlled unit and it's a much simpler circuit saying five wires go into the same five pins nine to 13 so 9 through 13 and then one control wire for the servo the yellow one so the servo gets its 5 volt power the transmitter transceiver gets its 3 volt power 3.3 and all is good so now outside here we have a virtual access to my laptop which is what is connected to the transmitter and then we have my receiver which is connected to my desktop so as you can see we were pushing the buttons and will bring up a serial views of this serial and code as I say are the receiver and this is the transmitter even though they both actually transmit receive so we'll hit start as you can see the over here says the motor started we hit stop and the motor will stop but it'll start it will stop and then I created amusing third option which is if you hit both buttons the motor will explode which obviously we can't really do and we go into the code we have a beginning serial interface that's part of a requirement for this library the RF 24 library which you can include through managing your libraries and then you just search for and install that library if you don't already have it and so then we establish a radio object or instantiate the radio class f24 class credo up shake name radio and then here are the codes now these are numbers I just made up as long as they're unique you can uniquely identify each transceiver because you not only will have two transceivers but you could also have a network of many transceivers I believe the RF 24 library can handle five but you could also have many others and within the same say house talking in different ways so that as long as each one is uniquely identified to this Xcode it's good so we have a send and receive and then on the other code over here that will be reversed so then here the two pins for the two buttons we establish serial connection set up the pins that this sets up the radio and what this does is I've set the power to low we could set the power to high we'll draw more power and give you more range but you also have to have that power available so in the case of this transmitter we have the external power supply so this could easily be high gives lots of range now this setting retries it increases the number of retries and increases the delay between the retries of this bit of static interference this will buy you more reliability you could put that way high might increase the reliability more but then we set which pipes are going to be for reading and writing and that's where these codes come in and then we give the module a kick and that's where we say start listening even though actually in this particular case we're going to start writing first so we've got four different codes the do-nothing code the motor start code the motor stop code and the explode code and this is where we set what code is going to be going out set it to a default of none then we look the two pins if the pin white pin is going of the red pin is going and if both pins are pushed we sent the message code to be motor explode and start for white stop for red and if no button pins are pushed then set it to code none and if it's not set to code none we immediately are asking that we then so it could be any one of these other codes we then stop the listening because we're going to be writing we then write out a message code which is an unsigned long which means we have the option of 32 bits worth yet unsigned long on the ID we know is 32 bits so that's 4 billion different code options so we control a lot of devices with that and then if that returns a false then we will say failed now you could put more air handling where you could try that over over again or whatever your project calls for and then we begin immediately listening now there is a little bit of a delay between here and here so we needed to lie on the other side but we'll worry about that a second so then we said what time this started in micro microseconds and then we said that there has not been a timeout so now we wait for while the radio has no data coming in so this will now loop over and over the one we sent out a package now we're waiting for something to come back but we're only going to wait for 200,000 microseconds which is one fifth of a second so these little things are pretty quick and what we're doing is we're saying if the present time - what time - started at is greater than 200,000 and set the time out and break out of this while loop and down here if the time what is true print timeout obviously you some kind of error handling it would be a bit more robust you might say try the sending that last message again or something or produce some kind of flashing light saying that there's a problem then here we have we have if the data comes back which is what we're expecting we read it in and then we just print it out now all the code over here is going to do is take whatever codes come in activate/deactivate the motor or whatnot but it also then just send the code right back so we could say we could put some if statements here saying motor start and stop acknowledged or whatever and verify that that's actually the code we sent but here I'm just printing out of that code so I mean data is one too and here's where we made the motor explode explode so three so then back here it's the same thing almost all the same setup except that we include the servo library because we're controlling a servo we set up the thing these numbers here have to be the same as here so we set that up same codes except we set servo pin to being six and then this is about the motor basically this code here we won't go into but it allows the motor to sweep back and forth and so it's the same thing here we set up all the same power law retries whatnot except this and this are reversed because really this is this is the other end this is this device and this is this is this device and this is the other end so then we get down to here we attach the servo so that just make the motor sweep and then we say okay present motor code is now none and we wait for the radio to have data and so it's looping round and round and if the motor if there's no data coming in then we don't do anything we just skip right down here to seeing if the motor global motor running variable is true and if it is and it keeps sweeping the motor and if it's not it doesn't do anything and then we if the message comes in while there's data and it should be pretty quick because that's just one packet that we're getting in which is one unsigned long the motor code we put what data came in into the motor code we read it in we stop listening then we write back out that dumb motor code which is where that then receives it back here then we act on the motor code so start we start the motor or we set the global motor is running to true if it stopped we set to false put up these messages as well and then we just put up this funny message if both buttons were pushed which is the third motor code and of course if the motors exploded presumably it's not running anymore then down here as I say we act on how this flag was set so it's pretty straightforward as I say this this here could be this is unsigned long so we could have four billion if statements of the Arduino could handle that much code so now back down to here we will look at this for a moment and I'm getting the power right now from the usb but since we're doing an external power source I can go like this I can plug into the five volt rail I can plug this into the in and I've got this hooked up to a little external battery pack that puts out a USB and we now have motor control without having to be plugged into any device I'm going to start I can stop can start stop start stop it so anyway it's all a beautiful thing with the these modules there they say they're cheap they're easy to use the code as you can see is not that complicated and I really like them as I think I will do that video on a new garage remote and make this a much more interactive remote rather than just the classic push the button and toggle the direction of the door but you don't really know which way it's going and whatnot plus the door has no sensor on it for for knowing if something's interrupting it so maybe I'll put a bunch of these so the door will have a sensor and it'll have a control because the control is missing anyway thank you very much this is I think pretty straightforward I'll post all these Fritzing diagrams and all the code they'll comment it a little bit better to explain what's going on and if you have any questions about this or even other things but if you have any questions about this then go right ahead put them in the comments and I usually actually respond to them also all the usuals subscribe like that kind of stuff it actually helps the more people subscribe and like a video the higher and the rankings it goes
Info
Channel: LessonStudio
Views: 124,923
Rating: 4.8940639 out of 5
Keywords: Arduino, robot, robotics, electronics, NFR24L01, wireless, Mac, DIY, learn electronics, motor, servo
Id: 4c0t8PBArvk
Channel Id: undefined
Length: 18min 1sec (1081 seconds)
Published: Sat Jan 09 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.