Using Inexpensive 433 MHz RF Modules with Arduino

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today in the workshop will be working with some inexpensive RF modules I'll show you how you can use these to transmit data between two arduino z' you'll learn a bit about how amplitude shift keying works and we'll build a remote temperature and humidity sensor so stay tuned and welcome to the workshop [Music] hello and welcome to the workshop today we're going to be adding radio communications capabilities to our Arduino projects using some very inexpensive RF modules now there are a number of ways of adding radio communications capabilities to your projects Wi-Fi is an obvious choice and that would allow you to integrate your project with your existing Wi-Fi networking with all the devices that are already on it Bluetooth is another method of communicating between your project and things like your phone or your tablet or a nearby computer there's also the NRF 24 l01 modules these are very popular for adding two-way radio communications between two Arduinos and you can separate these by a fair distance with the correct antenna but we're not covering any of those today we will in future videos but today we are going to focus on some very inexpensive RF modules a receiver and a transmitter that work on the 433 megahertz band that you can buy for about $2 for the pair so for less than the price of a cup of coffee you can add radio communications capabilities to your Arduino projects so we're going to look at how these modules work some of the antenna considerations and how we can use these to make our Arduino talk to each other wirelessly now before we start working with radio devices we need to discuss a little bit about the regulations involved in doing that every country in the world has a regulatory body that is responsible for controlling how communications are used within the country in the United States the Federal Communications Commission or FCC takes care of this the Canadian radio and television Commission RC RTC is responsible for this in Canada and in the United Kingdom Ofcom or the Office of Communications are who regulate radio usage within the country now your country if I haven't mentioned it does have a Regulatory Commission I've got a link in the article to a good Wikipedia list that lists of them for all the countries in the world now the transmitters we are going to be using work on the 433 megahertz band this is a UHF band and this is sometimes referred to as Ltd 433 now globally these transmitters are generally allowed to be used as long as they are low-power and intermittent in some European countries you can actually run them at a bit higher power and at a more constant signal but if you wanted to do that within the United States for example you would actually need a valid amateur radio license now the experiments we're about to do make use of them in a very low-power mode and the range is restricted to a few meters now in no circumstances should you attempt to amplify the output to get a higher range you can work with the antennas but the range is limited and it is what it is do not try to make a more powerful device which could cause interference with some of your neighbors equipment and which can also get you in trouble with the authorities so having said that let's proceed and move on with our radio experiments now here are our two modules this module over here is a transmit module and this one is the receive module now there are very few connections on these modules which is what makes them so easy to use on the transmit module this outer pin over here is the data connection and amusingly they've got the word data written backwards on these modules so that's at odd but it's really data the middle pin is the VCC connection for the positive voltage and on the transmitter module you can use any voltage from 3 to 12 volts and the higher the voltage II use the more powerful the module will be and the third pin is the ground pin there's also a connection up at the top over here for an antenna and we'll talk about that in a moment now on the receive module it's also very simple to connect although there are four pins there are really only three connections the outer pin here is the VCC and unlike the trans intermodule this needs to be five bolts the pin on this end on the other end is a ground pin and the center two pins are actually internally tied together and this is the data out pins there is also an antenna connection on this as well it's down over here by this little coil now you probably noticed that both the receiver and transmitter have a place where you can solder an antenna and you're going to need to do this because without an antenna these two devices are limited to ranges within a couple of centimeters it's not very practical with an antenna you can extend it a lot further now the antenna isn't anything fancies is too piece of solid 22 or 24 gauge wire but the length of it can be important when you're building an antenna for a radio device you need to look at the frequency that you're using and then look at the wavelength of that frequency now 433 megahertz falls in the UHF or ultra-high frequency band and the wavelength of a 433 megahertz signal is sixty nine point two four centimeters now it's customary to cut it antenna to a half or a quarter wavelength the quarter wavelength is often used and a quarter wavelength of this signal would be 17.31 centimeters so that's the length you're going to want to cut your wire to for your antenna now you can reduce the length of the antenna if you wish by coiling it you can just use something like a pencil or a pen and coil the wire around that to make the antenna shorter and yet still as effect the visit would be if it was a long antenna so you're going to want to do that to both of your modules the RF modules we will be working with use a technique called amplitude shift keying or ASX like all forms of data transmission this is a method of modulating a carrier wave in our case the carrier wave is a 433 megahertz signal this is very similar to the analog technique of amplitude modulation which you might be familiar with if you're familiar with AM radio it's sometimes called binary amplitude shift keying because there are only two levels we are concerned with you can think of it as an on/off slip for the carrier and what a digital one turns the carrier on and a digital zero turns it off without modulation this is what our carrier wave would look like with amplitude shift keying the digital one turns the carrier on whereas a digital zero will turn it off the advantages of ASX is it is very simple to implement it is quite simple to design the decoder circuitry for an a SK system amplitude shift keying also needs less bandwidth than FSK or frequency shift keying which is another common modulation technique the disadvantage however is that amplitude shift keying can be corrupted by electrical noise and interference in order to experiment with these RF modules and Arduino we are actually going to need to use two arduino z' one for the transmitter and one for the receiver and i've got a setup like that right on my workbench right now with this being the transmitter and this being the receiver and in my first demonstration all I am doing is I'm sending a canned message from the transmitter over to the receiver you'll notice I'm running my transmitter on batteries the receiver is still connected up to my computer because I want to use the serial monitor to display the canned message and if you wish of course you could use two computers if you happen to have that one for the transmitter one for the receiver otherwise you'll just have to load the code into them one at the time and then run the transmitter on a battery or on a power supply now for our first demonstration we're going to make use of a library called Radiohead not to be confused with the musical group this is a library that has a number of functions that allow you to transmit and receive data on all kinds of radio links including these 433 megahertz modules this takes care of a lot of the problems you would have if you tried the transmit and receive manually manually meaning without a library the reason is that noise that you'll encounter on the receiver can be quite severe and so a number of keying techniques such as asynchronous shift keying and all have been employed in order to combat that noise if you try to do this manually you can do with code and there are a number of examples up on the web and on YouTube of folks who show you how to do this a lot of them use an analogue input port for the receiver and look at a threshold and if the level is above a certain level they considered to be a digital one if it's below a certain level they consider it to be a zero but by using a library like the Radiohead library we can eliminate all of that and just focus on actually building something that is reliable and that works however if you do feel like experimenting with doing this manually I'd encourage you to take a look at articles and videos that show you exactly how to do this so let's take a look at how I've hooked up everything for our first demo and then we'll look at the sketch that I'm using for it now here's the hook up for our transmitter it's actually very simple obviously you're going to need an Arduino Uno and you are going to need a transmitter module and those are the only two components you'll require now the VCC which is a center pin from the transmitter is hooked up to the 5 volt output of the Arduino the ground from the transmitter of course is hooked up to one of the Arduino ground connections and the data input to the transmitter is hooked up the pin 12 of the Arduino you will need to use pin 12 because the library actually expects to be transmitting data on pin 12 now let's take a look at the receiver now the receiver hook up is just about as simple again you'll need an Arduino Uno you will need one of the receiver modules now VCC which is the pin on the far left is again hooked up to the 5 volt output of the Arduino and the ground is hooked up to the Arduino ground now you can use either the 2 Center pins as an output as they're actually tied together anyway and this is connected to pin 11 again our Radiohead library expects the receiver input on pin 11 and now that this is all hooked up let's take a look at the sketch that will be to send data between the transmitter and the receiver before we work with our sketch we're going to need to obtain a copy of the Radiohead library unlike other libraries that we've used in previous videos this library is not available by searching in your library manager you'll actually have to go and download a copy from the website I have a link in the article associated with this video so that you can get this library here's the Radiohead page and you'll find the library right at the top over here the current version as of this recording is 1.83 and it's available in a zip file so download that zip file into a location that you're going to remember and then head into your arduino ide so here I am in my arduino ide looking at the transmitter sketch before i use it i'm going to have to install the library and is downloaded so if you go into sketch and go into include library you will see ads if library select that and navigate to the directory that you downloaded your library and look for the library and then click OK to install it I won't do that now because I've already installed the library into my IDE once you've done that you can proceed with the sketch now the radiohead library actually includes a number of smaller libraries and the one we are going to be using is one called amplitude shift keying so we are going to include the Radiohead amplitude shift keying library and we will also need to include the SPI the serial peripheral interface library that is included with your IDE the reason for the SPI library is that we're actually sending and receiving serial data so the Radiohead amplitude shift keying library makes use of some of the functions in that library so include the SPI library as well next we're going to create an object which I call RF driver after that in the setup we are going to initialize that object and then we go into the loop we're to create a character and we're going to call it message this is one long character of multiple characters and my message is welcome to the workshop now it is important to note that of course you can use any message you wish but you'll need to know how many characters are in the message and that includes the spaces and the exclamation mark in my message in my case there are 24 characters if you choose to change the message for your demo just count the number of characters because you're going to need that when we do the receive sketch then we're going to send that message aptly now this is the format that we're sending it in and we need to know how many characters were sending an Arduino string length command will give us the string length of a string so the string length of message in this particular case is 24 and then we're going to wait until the packet has been sent sometimes this can take a bit of time and then we're good to delay for a second and go back up and do the whole thing again so our transmitter is going to continually broadcast our message welcome to the workshop and so now that we've seen the transmitter sketch let's take a look at the receiver sketch now I've connected my computer up to the receive arduino the transmit arduino is currently being powered by a 9-volt battery so it could be transmitting our message right now of course you could use another power supply for that arduino or a second computer if you have one now the received sketch starts off identically to the transmit one will include the radio head amplitude shift keying library and will also include the dependent spi library and again we're going to create an object which we once again called RF driver now in the setup we'll initialize that object and we'll also set up our serial monitor because this is how we're going to display our received message in the loop we will set our buffer to the size of the expected message so as you recall when I talked about the transmitter you need to know the number of characters you're sending I'm sending 24 so I'm going to initialize my buffer with a size of 20 or characters and I'll also define buffer lengths as a size of that buffer now we're going to check to see if we've received the packet and if it's of the correct size so we do that with this statement here and if we have we'll display that on the serial monitor I'm going to display message received and then add a space and then I'm going to actually print the entire buffer and then I'll go through the loop and do it over and over again so now we'll upload that to our Arduino and see if we're going to get any messages received so we'll go and open our serial monitor and it's not uncommon to start off with a little bit of the buffer like we did but as you can see we are receiving a message and welcome to the workshop now just one final word on the demo that we've just done before we move on to the next one it may seem like this is just a simple demonstration and it doesn't have very many practical uses just sending the same message over and over again but one thing you can actually use this demonstration for is to check your antenna arrangement with the two devices with the receiver and the transmitter now my devices I've used a piece of wire as my antenna as about seventeen point three centimeters long because as I said earlier that's a quarter wavelength of the 433 megahertz signal and because my transmitter is being powered by a battery I can move it around the room I can move it into another room I can see how far I can actually transmit by using this demo and I could also experiment with doing things like coiling my wire I can maybe make it a different length or something maybe add another seventeen centimeter wire onto the ground that is another common way of creating an antenna with two wires one on the ground the one on the antenna side so you can do some experimenting to find out the maximum range and also find poss both sources of interference in your home for one thing I'm a source of interference I noticed that the closer I get into my experiment the more I seem to drop off packets you'll notice in the last demo that the welcome to the workshop wasn't coming up every time and I think a lot of that was because I was near it I noticed as soon as I backed the way it came in more consistently so again that demonstration while it seems simple can actually have a practical use so now that we've seen that let's move on to bigger and better things so for the final demonstration today I'm going to show you how you can send data from a sensor over the RF modules from one Arduino to another Arduino now for my sensor I've chosen a dht22 temperature and humidity sensor which I've got on my breadboard with the transmitter right now now I chose to dht22 for a reason first of all it is a practical thing to try to measure temperature and humidity remotely but secondly we are sending two pieces of data the temperature data and the humidity data so this sketch will illustrate how we can send two pieces of data over the wireless link and you can extend upon this concept to send as many pieces of data as you would like to so let's take a quick look at the sketch for the transmitter that I've used now the only changes we're going to need to make to the wiring or to the transmitter our receiver will be identical to the last experiment so on the transmitter we are going to add a dht22 temperature and humidity sensor we're going to connect the VCC from the dht22 to the five volts on the Arduino we'll connect the ground than the dht22 to the earthly nose ground we're going to send the output from the dht22 into pin seven of the Arduino digital i/o ports and that's it for the wiring as I said no changes to the receiver are required so now let's take a look at the sketches we'll use in order to send the data from the temperature sensor to the remote Arduino so here is a sketch that we're going to be using for transmitter now this sketch is going to require two additional libraries that you might have in your IDE if you've done some of the experiments in my previous videos we need the Adafruit AM to 31:5 library and the Adafruit unified sensor library now we'll use these libraries before in the video that we did with the HC SR 0 for ultrasonic sensor we use the dht22 in that video to measure temperature and humidity and factor it into the speed of sound so if you followed along those videos you probably already have these libraries if you don't i've got details in the article accompanying this video on installing them using the library manager you can also take a look at the older video to see how to do that once you have the libraries we can begin with the sketch the sketch starts as our previous sketches did by including the radiohead ASX library and the dependent spi library next we include the DHT library we define a couple of constants these are both for the dht22 DHT pin is the pin on the Arduino that we've connected our sensor to and I've defined it as 7 because I'm on pin 7 if you wish to use a different pin just change this number we also need to define the type of sensor because our library is capable of driving several temperature humidity sensors DHT type is defined as dht22 now a couple of variables these are both floats and they represent the humidity and the temperature the temperature will be in degrees Celsius by the way next we'll define a couple of output strings we need strings to formatter outputs and not floats so STR humid will represent the string value of the humidity STR temp for the temperature and STR out is our final formatted output as with the previous videos we'll create an object which I'm calling RF driver and now we need to initialize a DHT sensor and we do that with this command now in our setup we need to initialize the ASX object as we before and we also need to start our sensor anyway because a DHT begin command to do that and now we're into our loop we'll start the loop off with a two-second delay this is required so the dht22 can stabilize itself between readings next we'll assign those floats we defined earlier to both the temperature and humidity values are agreed from the sensor now we're going to convert these two strings so STR humid is going to be the string value of the humidity and STR temp will be the string value of the temperature we're now going to combine the two strings and we're going to put a comma in between the two of them this actually creates a comma delimited string that starts off with our humidity value and then with our temperature value now we're going to create a character as we did before we'll define the character message the star in front of this means it has multiple characters within it and we are going to use STR out which is the string we dis formatted and this formats the string has a character then it is the same as our previous transmit sketch will send out the data that we just formatted and we will wait until the packet has been sent and then we'll go back to the top of the loop and do it over over again so about every two seconds we will be sending out a string that has a temperature and the humidity value with a comma in between the two of them so now that we've seen the transmitted sketch let's take a look at the receive sketch now our receiver sketch starts off very similar to the last receiver sketch we looked at in fact you can use the last sketch to look at the raw data that we're sending out of the transmitter you'll see the comma delimited string you'll also see some junk right after the string and that's a null character that's sent after every line it won't be displayed in this sketch so we start to sketch off as we had before with the radiohead amplitude shift key and library and the dependent spi library we're going to define output string similar to what we did in our trans sket so we have a string for the humidity the temperature and for the final output will create an amplitude shift keying object and will initialize this object within the set up we're also going to set up the serial monitor because this is how we're going to display our temperature and humidity data and then into the loop now the loop starts off the same as the last received sketch the only difference is we set our buffer size to 11 because that's the total length of our comma delimited string each one of the temperature and humidity variables need five characters that's four digits plus the decimal point and there's also the comma that we have in between the two of them so the total is 11 over here once again we'll check to see if we've received a packet and if it's the correct buffer size and if it is we'll go down into this part of the code now we'll take our string out which is a string and we'll take it as the characters that are inside our buffer now these are characters so we need to convert them using a string command after that we are going to use this for loop to split them into two values using the comma that is part of our comma delimited string unlike other programming languages the Arduino does not have a command like a split command that can just simply do this so this for loop over here will accomplish splitting it into two values which we define as the humidity and a temperature now that we've got those two values we simply send them out to the serial monitor so I've already loaded this up to my Arduino so let's take a look at our serial monitor and see what we're picking up and there we go it's a pleasant 23 degrees Celsius and 47.4% humidity inside the workshop right now so that's about it for today as you see these little RF modules may be inexpensive but they're actually quite useful when you want to send data in one direction now obviously these are not as advanced as Wi-Fi or Bluetooth solutions or even solutions based around the NRF 24 l01 but for many applications it's all you'll need and for $2 you really can't go wrong now the last demonstration we did showed how you use the dht22 sensor and sent both temperature and humidity data by combining them onto a comma delimited string and you can extend this technique for other sensors you can send more than two pieces of data at a time and you could also use the analog inputs on your Arduino so let's say you wanted to get the input from a joystick you could use the X and y-axis on the joystick to drive 2 of the analog inputs and send that data over the arduino to a remote so this could make a very simple remote-controlled joystick arrangement if you wish there's a lot of possibilities over here anyway I hope you enjoyed this video and I hope it opened your eyes to some of the things you can do with these very inexpensive RF sensors now I'd really liked you to subscribe to the channel if you haven't done so I would really appreciate that and that way you'll also get a notification every time I put a new video out and I'm going to attempt to put more and more videos out because I know people have been asking for that and believe me I am trying so once again a thank you very much for joining me today and I hope to see you again soon in the workshop take care of yourself and good bye for now [Music]
Info
Channel: DroneBot Workshop
Views: 531,873
Rating: undefined out of 5
Keywords: Arduino (Computing Platform), Radio Control (Invention), 433 Mhz, Wireless, Arduino, Electronics, radio control, RC, transmitter, receiver, Microcontroller based Project, RF Link, RF Signal
Id: b5C9SPVlU4U
Channel Id: undefined
Length: 29min 50sec (1790 seconds)
Published: Sat Feb 17 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.