This is the cheapest way to do it. I mean cheaper than Bluetooth. Those ZigBee modules. Wi Fi, forget about all that. If you need to send a bite from one microcontroller to another, this is the way you do it and we’re talking about using those cheap, RF links, and in case you haven’t, noticed we’re up in my bedroom here and I’ve got a standalone Arduino down here with Two sensors, these sensors, are they measure humidity and temperature, so I have two of them: one outside wired up outside the window and the second inside the bedroom here, so I can see you know what the temperature difference is from outside versus inside it’s kind of an Unrelated project we’re not going to really talk about the specifics there. But what I want to talk about in this video is that I’m sending data from all the way up here in the bedroom to here where the receiver is connected to an Arduino board, where we’re taking that data and sending it out through the serial port, where We can open up a serial monitor window on the computer and view the data, so you can see here that we’ve got the outside temperature humidity with the inside temperature and humidity and just ignore the C. There that’s a typo. It should be f4 degrees Fahrenheit, but anyway you can see. We have the data here, and the thing to note here, that’s important, is that when you’re sending the data, your sin you’re sending bytes okay, so those are numbers between 0 and 255, so you can’t really send decimal.
That decimal pointed values like what I’m, showing you here, 38.3 87. You can’t send that as one byte you have to break it up. So what I did was I broke it up into each number. So I sent a three eight point. I didn’t send the point. Actually, I sent a three eight six one, five okay, so that was five separate values to send over. I happen to know on the receiving side what I’m getting so I just printed in here a decimal point, so so that you know it displays correctly so but I’m sending a lot of data here so there’s five, five, five, five! So there’s twenty bites that all get sent over every time. This updates okay, so so it’s really it’s, really good. These transmitters and receivers are really reliable and they’ve got pretty decent range, but there’s a few drawbacks and we’ll talk about that more here in a second. So let’s let’s drag out the white board and take a peek at how these things work. So I just want to say a few things before we get started. If you bought these modules, you just want to get started. You just want to plug them in and go then I recommend you actually go ahead and download and install a library that was designed to work with these modules and there are plenty out there and they’re really good. Usually you’ll get really fast data rates, they’ve implemented. Some kind of encoding schemes, so the data is fast, it’s, reliable, all that good stuff in this video I’m, not really going to talk about libraries.
In fact, the code that I made for these arduino z’ is terrible, it’s, really bad code, in fact, it’s just awful there’s no comments and it’s using delays, there’s a lot of things you can do to improve it, but uh that’s, not the purpose of this video. I just kind of want to dig in a little deeper see how these things, work and I’ll show you some things that maybe, if you want to make your own library or make your own code to work with these things, you can okay. So I just want to get that out of the way so that when you’re watching when you’re looking at my code – and you know it’s just bad okay so anyway, okay, so wiring of the modules is insanely easy, okay, there’s really hardly anything to it. Each module has has pins for power and ground; these are five old modules and they also have a pin for data. So, on the transmit side, your data pin goes to an output of your Arduino and on the receiver side, the data pin goes to the input on an are on the Arduino, okay and then you’ll notice here that I also have an antennas soldered on to it. These are just standard like 22 gauge wire and the the length here is about seven inches. I think it’s, like six point: eight inches and that’s the quarter wavelength of 434 megahertz. Okay. So if you’re going to use these on a breadboard there’s, an extra pin for antenna make sure that that pin isn’t inserted into the breadboard, because the inter pin capacitance between two rows on a breadboard is just awful and it will really throw off your range.
So if you’re not going to install the antenna, but you still want the pin just bend it up so it’s, not in the breadboard okay, so that’s that’s pretty much it for wiring. Okay! Now I just want to talk a little bit about. You know the signals, you know what it looks like on those data pins. You know it’s it’s kind of deceiving because you have a data pin on the receiver side and you sort of think that these things are going to behave like transparent devices. So you could, just simply, you know, do like a serial dot print to your transmitter and then you get that data on your receiver. I wish that was the case, but it’s not if you look at your receiver pin like if I looked at it right now. It kind of looks something like this: it’s got: noise garbage all kinds of stuff; okay, which is why you need to sort of implement a little bit of software filtering and some timing and a little bit of a protocol. Okay, because think about, if you were to send a byte you’re, going to send a bite to the let’s, just send this okay, two three and then a one okay you’re going to send over a one to the to the receiver. You want to send over just one so while you’re sending this over right now the pin would be low or all those zeros in a standard way of sending it over.
What do you think the receiver pin is going to be doing while these are all 0 it’s going to be like all, ah crap I’m going to leave? You know I’m going to leave that in the videos a little blooper, so the pin is going to be like getting all kinds of garbage and crap. So there’s not going to be a good way for you to to actually register these as zeros. So that’s kind of where you got to implement something that’s, you know it’s got a lot of names, but it’s kind of like a variant of Manchester encoding that’s what it’s called so. What we’ll do is for 0 we’re going to send over nothing and then we’re going to rise. The pin up, okay it’ll, bring it back down and it will rise it up so that a 0 will first send over a 0 nothing and then will rise. It up and it will come back down and will rise it up on the receiver, and we will see this because the pin is constantly moving, which is good. It keeps everybody active it. It doesn’t allow the pin to get into that idle state where you’re going to get all defensive, noise and garbage. But the trick is: is that on the receiver end we’re going to only check it here and here and you know if we’re just going along and along and along and then once we get that’s a good square wave and then once we get to the 1 Once we get over to the 1 what’s going to happen is that this will just stay high and then it’ll go low.
Ok, so we check check don’t check there, check, check, check and then check. Ok, so we’re checking it at. You know that if the entire cycle is here but we’re checking it every other, so we’re shifted over a little bit. Ok, that’s the trick and that’s all I did here. It’S really there’s, nothing special to it. In fact, I’ll show you the timing, diagram so here’s. The receiver pin I’m going to call this Rx and it’s going along and it’s getting blips of noise. Lip lip lip here’s the TX line and I’m ready to send some data. So all of a sudden what I’m going to do is I’m going to rise. It high I’m going to raise it high low I’ll, oh I’m, going to do this like 20 times really fast, okay, but these times in here, like 500 microseconds we’re, going to do it really fast we’re just going to make the pin go high low high low High low, all of a sudden, when that happens, this thing the RX, is going to wake up and it’s going to see those flips, but we don’t know where the start of our bite is so what we do is after like doing that, 20 times, we’re going To keep the pin high for like three milliseconds, okay and then all of a sudden on the receiver and we’re going to see it high higher than any of these guys and what we’re doing is we’re waiting for that pin to be high.
So now that we’re, high or synchronized, and then this pin on the transmit side, will go low for 500 microseconds and then right after 500 microseconds, we start sending data okay, so we were going to send a 0 over. My guy on the receiver end know is that right when this drops we’re going to chill for 500 microseconds and then wait, I don’t know another 250 microseconds and then check it check the pin. So if we’re sending a zero here, we’re going to send a zero but that’s going to be 500 microseconds and then remember we’re going to invert the bit and we make it high for 500 microseconds and then we make it low. But he checks it right here about 250 microseconds right here: okay, that’s, where that pin is and then it’ll go high, just like we got here, I should be going all the way out, but whatever and then that’s how we register it and then on the receiver End he knows, then, to wait. 1000 microseconds for the next check. So if I was sending another zero, it would send that and you would check it right here – okay, so that’s how it works. Now, let me just just for the heck. I just want to show you what everyone looks like, so that would be a zero right there and he registers that is zero, but a one, a bit of one would be like this, oh well, you have to send something in its order to receive it, but On the transmit side, after this time out here, he’ll stay high for 500 microseconds and then go low because he inverts the bit and since down here, we’ll see that is high and then low, so that was 500.
This in here was 500 this between here’s, 500 and 500. He checked it right there at about 250 after the first drop or he’ll, wait the 500 then 250 and then it’ll check it right here, which is a thousand after that. I know this is probably so confusing. Once you see the code, it will all make sense. I promise okay we’ll jump over there, but the point is: is that he checks it one time during this whole transition. But the point is we really want to keep that? Pin moving okay, it doesn’t allow the receiver to ever go into an idle mode and then pick up some garbage or whatever okay, so he checks it when it’s high right there and he gets his one for his bit and that’s pretty much it. Okay and I send over a bite right there when I send over another bite, he does the same thing not on here. When I send another bite, he does. The same thing makes this pin go crazy, waits three milliseconds and then start sending the boy over okay. This is a whole synchronization process, yeah it’s not really efficient, it’s, not optimized. You can make this a lot better. A lot better trust me, but this gives you the general idea of what’s happening. I deal with these these modules, so let’s jump over into the code and take a peek what’s going on there. All right, so we’ve got the transmitted code here on the left, the receive code on the right – and this is different code than what I demonstrated earlier.
This is just bare bones: just sending a byte over to the receiver and displaying it okay, so let’s open up the receiver window and you’ll see what I’m sending okay let’s see if it works. Kevin is awesome. Make new line give me a new line baby there. It is okay, so you’ll notice that I have a long delay in between the data transmission, and this is important because, when it’s, when it’s idling, like that, when it’s not doing your sending anything, the receiver and pin is just going crazy. So this really tests out how strong your communication link is in the integrity of your data. Okay, so this is pretty good. I don’t see any garbage characters in there or anything, so I think everything’s working pretty good and let’s jump right into the code. We’Ll start with the transmit side, so you could tell it’s it’s very simple. First thing we do in the setup is set up. The output pin, pin that’s going to go right to the transmitter, and then we jump into the void loop and we type Kevin is awesome to the transmitter and you’ll see here. We call a subroutine for this RF send and then, at the end of sending that we do a little delay and you’ll see, I have a little a little character there. That signifies the end of the transmission over here. I’Ll show you what that does here. In a second but anyway, when it calls that subroutine, we jump down here, it’s expecting and a byte as its input, and the variable is called input.
Okay, so integer. I we set up and then we do a little for loop, 20 loop. We do this 20 times make the pin go high low high low high low, just like we talked about before in the waveforms, goes high low, high low high low, and then it makes it high for three milliseconds okay. This is what I was talking about earlier. After the three milliseconds, it then goes low for 500 microseconds and then it kicks off the day to transmission. So now it’s going to send the byte over and it’s all done within a four loop from I equals zero to I less than eight okay. So does this eight times and it works its way right through the bits of that byte, so let’s check it out if bit read of input that’s what you just put it into this routine of I, which so it’s bit position. Zero is equal to one make. The pin go high, otherwise make the pain go low. So if it was a one, we would make it high if it was a zero we’d make it go low, wait five hundred microseconds and then do this. If bit read of that thing, it’s the same thing, but instead of making it go high, we make it go low. So we invert everything so right here we wrote it high five hundred microseconds and then we make it go low. So this is what I was talking about about keeping the pin active.
So when we write a 1 to it, it goes high low. When we write a zero to it, it goes low, high, okay, so it’s always moving at the when it’s all done with that. Just make sure the pin is low and you’re done, that’s it that’s all it takes to send a byte over ok, it works it its way through a byte sending over ones and zeros, with the inverted bits so you’re actually sending over technically like 16 bits altogether. But you’re only really looking at 8 on the receiver side and I’ll show you what what I’m talking about here. So on the receive side, oh we’ve got a bunch of crap. We don’t use check this out editing on the fly here. Ok, so we’ve got a couple: we’ll set up I’m, not even sure, if we use all that we jump into the void setup for this I’m, going to use an interrupt. Okay, interrupt, pin 1, which is digital, pin 2 on the Arduino. Ok, the interrupts start at whatever. Where do they start at? I think one in two so to interrupt one or interrupts is digital. Pin 1 interrupt one is on digital pin 2. Hopefully I said that right, okay, so we attach it to one and we call this subroutine when that pin goes high, so the rising edge, pinmode 3 input pin mode 13 output. 13, just simply is, is a light. A little LED on the board that we want to make it go high, so we know that you know something’s happening it’s just an indicator and then we do the serial that begin at 15.
1. 15. Hey look nothing in the loop that’s, because when data is received, it calls this loop. The interrupt is called ok and the first thing we do right here and I’m telling you this code is terrible. Ok, there’s! Nothing! There no comments, nothing! I know it’s just terrible, but what we’re doing here is ok. The pin just went high, ok, so jump into this loop delay 20 microseconds, or make this variable good equal to 1. If the pin goes low, make good equals 0 and make I to 50, actually that could be anything that could be a hundred. What we’re doing here is that we’re doing a software filter, and this is the worst kind of filter you could do, but it works. So, who cares, but what we’re doing here is we’re, making sure that the pin is high for two thousand microseconds? Basically, okay we’re going to run through this. If at any time the pin goes low jump out. So when I make I equal to 100, this is no longer true and it jumps out and good is equal to zero. Okay, so let’s just let’s just go through that good is equal to zero jumps out. It doesn’t do any of this stuff and then it reattaches the interrupts not that it detached it anywhere, but anyway it goes through it. So that would be like a sudden blip in the thing – or maybe this this part over here when we’re, when we’re making the pin go crazy right here.
That’S calling this but nothing’s happening because he can’t get through this because it’s not on long enough it’s not on for 2000 microseconds, okay, so that’s what we’re doing so, we’re checking it a hundred times we’re checking the pin a hundred times. Ok! So anyway, if we get through this, if it turns out that this never goes true, then good we’ll be equal to one okay and then we’ll jump into good. This is somewhere we’re somewhere in here right now: okay, at the delay of the three thousand microseconds, so we’re in that delay of the pin being high for three milliseconds. Okay, so it’ll jump right into this it’ll get rid of the interrupts. You know detach it, get it out of get it out of here, because we don’t want to be yanking out of this now. We’Re solid, okay, so get rid of that and we jump right into a while loop okay. So this is stuck in this while loop, and then it can’t get into this until that pin goes low, so it’ll go into this while loop and keep going through it and and nothing’s happening, but as soon as this happens right here that three milliseconds is done As soon as that drops for 500 microseconds jump in to this okay, it’ll detect it and then it’s going to delay it for eight eight hundred and twenty five microseconds okay. So I told you that it sort of offsets itself so it’s waiting out this five hundred.
But then it’s tacking on about 325 onto it so that it catches it somewhere in between of this part here this first right, it would either be here or here so it’s kind of catching it somewhere, so it’s offsetting itself. 325 microseconds don’t worry too much about this. You can play with this number. You can tell 825 there’s no science to that number. It was through trial and error to get it just in that sweet spot. Okay, in fact it could be. It could be which a number I had a lot of good luck with with 750. In fact, I’ll just write that too right now I can do that. I have the board hooked up. Let’S check that out so 750 would be the full 500 wait here. Oops, it would be the full 500 wait and then it or not there darn it right here, so it would be the full 500 wait and then half of the first bit okay let’s see how that works, see if there’s any integrity yeah. So I mean it still works it’s there’s, a lot of there’s, a lot of leeway in that that you can play with okay and by the way I have the transmitter board not close to the receiver here, because when the transmitter board is is close to it. Like on the same desk, you’re gon na have all kinds of problems, because that thing just radiates, you know all kinds of noise and it’s just screaming.
So I found that out the hard way, but anyways okay, let’s get out of that and I’m going to leave. That at 750 it seems pretty good okay. So what we do is we wait? Okay, let’s figure out where we were so we waited 500 microseconds and then now we’re 250 into this. So this is pin has already gone high or low, but we’re in in the middle of the bit. So what we do is we jump into this now, a for. I is equal to 0, I less than 8. So what we’re going to do here is: do this 8 times? Okay, if it’s high bit write data in of I the position of the bit a 1 okay and yeah, we could probably do bit set bit clearer, but whatever, if it’s low, which is an else of the check of it being high, make it a zero okay. So that’s pretty simple and then just wait. A thousand microseconds because it has to it has to wait not only for this 500, but also this 500. So a thousand microseconds but it’s offset remember because we got the 250 on top of that. So the next check, ittle dew, will also be 250 in between this guy, hopefully that’s making some sense here but that’s it. You go through that eight times since done, and then what it’s doing is it’s checking the bits or the early, the byte that came in, because the whole byte is stored in data in if it’s equal to this hash tag.
Here then make it make give me a print line so print me, a new line so that’s, why you know at the end here we send that over and it prints us a new line else, just print the whole character. Okay! Well, in that this, this is important too. You have to print the character version of data and because it’s coming over is you know, they’re coming over it’s just numbers right, so this will do the ASCII translation for you and print it out to your screen in Nice letters. Okay! Do that then break okay? That was one bite. The break is needed to break you out of this, while loop, okay, that you’re stuck in so it goes through that break. Break me out of this, while loop I’m done, the good check is done and then reattach the interrupts and you’re done that’s the whole code, okay, very, very simple, very easy code and yeah. It can be a lot better than this trust me there’s. A lot of room to grow here, but I just wanted to – I just quickly – threw this together. All this code will be up on my site. I just wanted to kind of kind of make this up see if I could get it to work now. I understand how it works now. I can go back in and make it better.
arduino 433mhz Video
arduino 433mhz news
Posted on Thursday April 18, 2019Teardown: The Guts Of A Digital Sentry Hackaday … Continue Reading »
Posted on Wednesday August 29, 2018Raspberry Pi As 433 MHz To MQTT Gateway Hackaday … Continue Reading »
Posted on Saturday September 29, 2018Putting M5Stack On LoRa And The Things Network Hackaday … Continue Reading »
arduino 433mhz Social
🔬 Now that you’ve gotten your feet wet, dive into the kit and enjoy all nine experiments. Order yours today: http://bit.ly/2MnQ7fr
Originally posted 2017-02-11 23:57:59.