Arduino Mega 2560 with ESP8266 (ESP-01) Wifi, AT Commands and Blynk

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi there I've been working on this project for a few days now and I finally got it working and I thought I'd put it on YouTube in case someone else wants to do something similar I've got an Arduino mega talking to an esp8266 Wi-Fi module that's transmitting through my home Wi-Fi to the cloud and then I'm using the blink app on my iPhone in order to control this LED and to monitor the temperature from this sensor so I can turn that LED on and off from my phone and this is the temperature that I'm getting from the sensor if I grab the sensor it's going to heat up a little bit it's also my app is also tracking Millis or the time that the Arduino board has been powered up so this is pretty simple circuit it's actually part of a bigger project that I'm working on which utilizes a lot more of the mega capabilities but the big hurdle was getting the Wi-Fi working and I got that all in place now with this circuit so I thought I'd show how I did this I will show how to program the esp8266 I'll show how to program the mega the Arduino mega and I'll show how to set up the blank app in order to receive and send data all right I'm gonna go over the hardware that I used for this project starting with this is a 9 volt power supply this is certainly optional you don't really need it however at the beginning of this video you saw I was running the Arduino mega from the 9 volt supply it's handy to have in certain circumstances and they're easy to buy off of ebay or amazon this is a 3.3 volt power supply that's necessary in some cases because the esp8266 module runs on 3.3 volts and so you need a 3.3 volt supply in order to run that in certain circuits this is a USB to TTL converter I also got this on Amazon and it's needed in order to program the esp8266 t6 this is a breakout board because the ESP module doesn't have pins that are convenient for a breadboard so I you can buy one of these breakout boards that makes it easier to plug into a into a breadboard other people use wires like like this to connect the ESP module to the breadboard but this is pretty convenient and if you're ordering some of this other stuff you might as well get one of these too this is a an adapter for the ESP you'll see me using it later in the video basically it converts 5 volts to 3.3 volts for the ESP and it makes connection to the Arduino a little bit easier this is optional you can probably live without it but again it's a pretty cheap piece of hardware if you're ordering something else might as well get one of those as well you need an LED this is a 330 ohm resistor for the light this is the temperature sensor that I'm using it's a DES 18 B 20 sensor which is a digital output sensor and I bought this from the web from Sun founder and convenient little temperature sensor again that's just an optional thing I only used it just to demonstrate the fact that I'm able to read something from the Arduino board and send it to my iPhone you might want to use some other kind of sensor or just don't even bother with this answer this is the Arduino mega that I'm using it's actually not the Arduino brand it's another product from Sun founder so but any Arduino mega copy board would be probably fine got breadboard and some wires and two different types of USB cables one has to go onto this device and one of them has to go into the mega so that's the hardware that I used just a little bit of information about this guy for awhile I was having trouble programming my ESP module and on Amazon there were some mute comments from people saying that the chip on this was a knockoff chip and therefore it wasn't working so for a long time I was worried that the problems that I was having was because this wasn't you know a this wasn't a valid board to use to program the ESP module I later found there are other problems that I had in my system and really this thing worked as far as I can tell the the counterfeit or the knockoff brands work fine for this converter also just I'm using the ESP this 82 66 module it's you know kind of what's known as a ESP - 0 1 that's because I use this because it's the cheapest one and I really didn't need it to have a whole lot of inputs and outputs I just need it to run my Wi-Fi there are a lot of other esp8266 modules out there like this one and these would probably work but it was really more than I needed and also there's a lot more documentation out there and YouTube videos that show the ESP - of one style so that's why I'm using the ESP - oh one instead of one of the more complex versions of it but you can probably use use one on one of these modules for this project but it was it wasn't what I needed and I'm only going to show how to use this type of module in the video now we're gonna be using this TTL or USB to TTL converter to program the esp8266 one thing that you need to be careful of is the output voltage there's a jumper here which allows you to select whether you want 5 volts or 3.3 volts and since our 8286 uses 3.3 volts put the jumper on the call that the right-hand side I suppose depends on which way you're looking at it but anyway that's a 3.3 volt setting for the adaptor okay when you receive an esp8266 module it will have some 80 command firmware installed on it the problem is you don't know which version of the firmware is installed and the version is important to the project that we're working on here so I'm going to show how to check the version and install new firmware onto the 80 to 66 module so the first thing you need to do is go on the web and blink is the company that makes the little app that's on the phone that controls the Arduino and they have some pretty good advice on running an Arduino with an esp8266 Wi-Fi with AD commands the funny thing is one of the first things I say is this is not recommended for beginners and I can attest to the fact that this took a while for me to figure out but since I'm guiding you through it have no fear we should get through this okay so I click on this help topic so they talked a little bit about connecting an Arduino board to an 80 to 66 module this is obviously not the mega we'll get back to this later this is more this isn't used to program the the 80 to 66 we'll get to we'll work on that in a little bit one thing that's helpful here in this page is that they explained the blink was tested with the following a teef firmware versions so bla bla bla bla bla bla bla bla bla here's the latest one and that's the one that we're going to install today so we're gonna get this eighty version firmware installed on this little module here okay so where do you get the where do you get this firmware from well I went to this website here so now they say it's a little bit confusing because they say that the version is one point five four but actually when you download it you'll see that there's two numbers one is this number and the other number is this number a little bit confusing but bear with me here so click on the link you know you'll save it in your wherever whatever folder you're interested in I already saved it so I'm not going to click on that right now but here's the folder after you download it this is what you get now this was really confusing to me for a little while because they give two versions of the firmware one is this 32 M 32 M the other ones 8 m8 M blah blah blah and for a while I was trying to figure out which one I should flash to my 82 66 I never found a good explanation of what the two different versions are if someone knows the difference please post a remark in the comment section of this video anyway what I ended up doing is I just kind of took a long shot and said well maybe this is the one that I want and so eventually I use this one and it worked so feel free to use that that use that firmware now now that we have the firmware loaded on our machine we need a program to flash to our 80 266 the flasher that I used I got from this website don't worry it gives you this whoops message just download it anyway and save as in a place that is convenient for you I've already downloaded it so I'm not gonna click Save here but we'll see what it looks like in a second so here's the file the zip file and here's the flasher firmware or software that we use to flash to the esp8266 now just to let you know in this zip folder there's another version of the 80 commands this is not the one that you want but what we want here is the flasher so extract this from the zip folder I've already done that it's in my temp folder and we'll see where's my flasher okay so here's the firmware that we're using - art sorry I keep saying firmware here's the little app that we use to flash to the 82 66b where there's other flasher apps like this one that they do very similar things ideally they would do exactly the same thing however I will tell you when I use this app to flash my 80 to 66 it did not my 80 to 66 looked like it was working but when I tried to running the blink program for some reason it didn't work when I use this app to flash my 80 to 66 everything worked fine so there might if you have any problems with your or 80 to 66 not working I suggest that you use this this app because it worked for me there are probably half a dozen or maybe maybe more apps out there that trying to make it easy for you to program the 80 to 66 but this is the one that that worked for me so this is the one that I'm recommending and that's the one that I just showed how to download so that's the so I showed you how to download her I showed you where to get the firmware this is the flasher that's what's gonna flash to the 80 266 and finally what we're going to need is the Arduino software itself the Arduino software lets you communicate with the 80 to 66 and that's what we're going to use it for here here's the our Camino program we're actually only going to use the serial monitor at this point just to talk to the 80 to 66 so those are the three things you need in order to get yourself up and running need the the flasher you need the firmware and you need arduino software alright this is the circuit that we're going to use to flash the firmware to the esp8266 so here's the esp8266 this is a breadboard adapter and this is the USB to TTL converter that we're going to use so on the 80 to 66 we go from RX 2 TX on the converter and vice versa we go from TX on the 80 to 66 to rx on the converter and gets connected to ground ground gets connected to ground this is a 3.3 volt supply that I will use in the circuit we could use a 3.3 volts from the adapter however some people have said that that might not be sufficient to drive the 82 66 so just to be sure I use the my own 3.3 volt supply anyway 3.3 volts goes to VCC on the 82 66 and we connect 3.3 volts to the CH PD pin GP 2 is left open rst is left open when we're flashing to the 82 66 GPA GPIO zero gets connected to ground if we're running the 82 66 in its normal operating mode GPIO is left open alright let's connect the circuit and voila we are ready to flash our firmware so what we have here is we've got Arduino IDE running we've got our flash downloader up and running let's check and see what firmware I have on this device right now so to do that I'll go to tools serial monitor we need to make sure that I'm on the right Tom six now I I just happen to know that com6 is where my USB cable is connected so this USB is connected to comm six you can see that in my device manager coms X so if we unplug so now I just connected GPI o0 so when I ups the most eighty command firmwares run at eleven fifty two hundred so then I cycle the power again technology Wi-Fi connected eighty oops capital K T GM r G R so you can see on this on this 82 66 we're already running the current version that's not surprising because I flashed this a couple days ago but it doesn't hurt to it doesn't hurt anything to flash it again and so I'll show you how to do that so GPI 0 connect it to zero or to ground and then cycle the power now we go to flash downloader all right we're gonna be flashing on comm six don't bother changing anything that this is the bin ein file I showed you where to download the current version of the eighty commands so I open that and then click download so this takes a little while it takes about a minute or so to transfer all the firmware over to the esp8266 okay it's done it always ends with this failed to leave flash mode don't worry about it that's not a problem all right now just double check to make sure everything worked okay we will check our firmware version so I'll disconnect GPI zero and I will cycle the power go back to my serial monitor and cycle the power again eighty if just like 80 it should say okay I got the okay and and if we type 80 plus GM r we'll see that we have the correct firmware version okay we're actually done with this part of the circuit now so I'll unplug from here so now our Wi-Fi module we've confirmed that it has the correct firmware installed and now we'll start setting up the Arduino and the other components to make this circuit work alright this is the circuit that we're going to set up with the Arduino mega and the Wi-Fi module this is the adapter that I mentioned earlier so this Wi-Fi module is going to plug into this adapter and that is it it's a convenient way to connect the module to them to the Arduino mega so here's the white ring on our adapter we want to connect VCC to sorry this is ground obviously it goes to ground and VCC gets connected to 5 volts we're not connecting to the 3.3 volts because this board converts 5 volts to 3.3 which is necessary for the Wi-Fi module this is our X and that gets connected to pin 18 on the mega which is the transmitted line of the serial one port this is a hardware serial line that's on the Arduino TX from the adapter goes to our x1 which is pin number 19 on the Arduino we're gonna have this LED that turns on and off so just kind of picked a digital line and you read any digital line will be fine I picked 40 so that line 40 goes to the anode call it a positive side of the LED and then we go through a resistor to ground Arduino mega these two pin sockets are ground and these two pin sockets are 5 volts just they're exactly the same as these so we also connect this es 18 B 20 temperature sensor it's pretty simple it has a DC c 5 volts and ground and a data line which will connect to pin number 38 on the arduino and that's pretty much all we have to do to set up this circuit okay next we're going to work on blink if you don't have blink on your phone already it's pretty easy to find you go to the App Store blink and you'll see ya pop up they have iOS versions and Android versions I already have mine installed so I'm going to bring it up now so when you first start up blank you're going to be asked to start a new project so we'll start a new project we'll give it a name like LED underscore temp 3 so the device that we're going to be working with is a Arduino Omega there we go what we're not you had an option of using 82 66 as the device but that's we're actually sending commands to our mega we're not trying to send commands to the 82 66 we are using the 82 66 as our communication device but where our commands are going to be going to the and they're gonna be coming from the Arduino mega so that's the device that you choose for this particular project connection type is Wi-Fi you have some other options there but Wi-Fi is good for what we're doing so then we're going to create project now when you first create a project blink is going to send an authentication token to your email address that's my email address there and that token is what's used to allow communication between your device and your phone via the cloud so let's start a few put in a few widgets we're gonna have a button this is gonna be the button that controls the LED so let's call this button call it LED and we'll give it a red color cuz my LED is red and the pin is going to be a virtual pin it may not be obvious what virtual pin means yet or sorry no we're doing the LED so we're going to use digital pin and on my Arduino mega the LED is connected to and 40 as you may recall from the circuit diagram that I set up say okay and these buttons seem to work a little better if you have them on the switch so that's our LED button say okay now we're going to set up a a value display and this value display is going to display the Millis output from the from the arduino Millis is like a little counter that just runs and whenever the arduino is part part up and we're gonna just send that information to the phone not that it's useful but it just shows how the communication works so return and this is where we put in a virtual so they call it a virtual pin I think it would be better to call it a variable but you can think of it either as a virtual pin or a variable that is going to get updated by the Arduino mega okay so I set that to virtual pin 5 and you'll see how that gets coded into the Arduino mega and a little bit say ok and I'm gonna add one more display for our temperature we're gonna make that a virtual pin and we'll set that to virtual pin 6 just because it sounds like a good number I'm gonna call this temp and updated every second okay all right so now we've got an LED button we've got a value button or field that's going to attract the Millis and we've got a value field that's gonna track the temperature and in a second you will see that blink has sent an email to my inbox and that email will contain the this authentication token and you'll see how that gets used in a minute so anyway blank is pretty much ready to receive data now all I have to do is set up my Arduino and power it up and have it communicate with this so hold on okay next we're going to start working on getting the firmware installed in the mega we'll start from the blank website go to getting started we've already downloaded the blank app for our phone we've already gotten the authentication token it's already been sent to us Alex you know I'll show that in in a second install the blink library so this is the library that's needed for the Arduino IDE and there's some very simple instructions on how to get the the libraries installed I'm not going to show that in detail here's the link for the blink libraries so click on that download it follow these instructions and you'll be ready to go with your Arduino code one thing I will mention is that the installation of the libraries was a little bit different than what I was used to normally when you open up Arduino normally I would go to include a library and add a zip library but in this case it didn't work using ads if library follow these instructions in order to get the libraries and tools installed properly okay so i've got arduino up and running and i'll assume that you have the libraries and tools installed the next thing we're gonna do is create first example of sketch so blink has this very handy tool that writes most of the code for the arduino all you have to do is tell it which boards are using again we aren't using the 82 66 to drive this code we're using a mega mega 2560 and then our connection is an Arduino it's an 82 66 Wi-Fi shield we are not using the Arduino Wi-Fi shield we're using 82 66 Wi-Fi shield okay here's where it asks for the authentication token so here is my email this is the email that I was created when I first started that project on my phone a few minutes ago and this is the authentication code that was sent to me and it allows for communication between my Arduino code and the blink app on my phone so I copied that into memory and I place it here and the example code that we're gonna use is push data and you can see here that the code has already been updated with the token that you're going to use and pretty much this code is almost ready to go we'll just copy and paste it copy we're gonna create this sketch and one last thing we need to do in our code is we need to update our we need to update the name of our network for me that's my the name of my network and password of my network that's the password of my network so now the the code is ready to go so I'll come over here and plug in my article and well compile hopefully it compiles without any errors and update that to our Arduino you can see it's blinking there alright now we'll open up our serial monitor and see what we got okay let's connect it to Wi-Fi you need one more thing ping that's what we're looking for you need to get that pain and that means that it has pinged the cloud I assume that's what it means and it's gotten a feedback okay I get our phone go to blink our blink app this is the display that we're created press play there's a little play button up there and you can see Millis is updating and we should be able to make our LED turn on and off look at that temperature is not updating yet that's because I haven't written the code to push the temperature data to the phone so we'll do that next so next we're going to update the Arduino code in order to run the temperature sensor so I'll go to the Sun founder website son founder is where I bought the sensor from and son founder provides an example sketch of how to run the temperature sensor so I'm gonna update our dueƱo code using a bunch of the lines from this example sketch I'm gonna do it pretty quick because it'd be pretty boring to watch so so this is one wire is a library that's used to communicate with the temperature sensor Dallas temperature is a library that converts the digital information to Celsius and there might be some other information coming from the sensor wire I'm not sure what that does but I think it's necessary we need to change this value to 38 you might remember on my my sketch of the wiring diagram we plugged in the digital wire coming from the sensor to pin number 38 on the Arduino board going to add a little routine here to get the temperature from the sensor nothing mysterious here v6 is you might remember on the blink project we set the temperature display pin to virtual pin six so that's why we have virtual pin six here so this is a routine that causes the Arduino to get temperature from the temperature sensor and then this command pushes the information to the blink project that we created a little while ago I also have the temperature printing out on the serial monitor in the setup we need to make sure that the sensor starts running and we need to create a timer to get the temperature this this is going to happen every six seconds you can do it faster but six seconds was sufficient for what I was trying to do and now we are ready to write this code to the Arduino let's make sure it compiles and compiles ok let's write this to the Arduino we gain good all right now we'll go to our blink app and hit play it's offline nope there it is hey there's our temperature let's see if the temperature changes yeah temperature changes so we are rocking and rolling all done we have Wi-Fi communication between the Arduino mega and my phone using an esp8266 Wi-Fi module and we can turn light on and off too all right well that's it I hope you're able to succeed and get this circuit to work and good luck
Info
Channel: Nathan Church
Views: 311,560
Rating: undefined out of 5
Keywords: Arduino, ESP8266, ESP-01, Blynk, AT Commands, wifi
Id: YLKEZtLhfZo
Channel Id: undefined
Length: 44min 24sec (2664 seconds)
Published: Wed Dec 06 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.