Arduino Air Quality Sensor Tutorial With WiFi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video i'm going to show you how to make your own air quality sensor that sends data via wi-fi to the internet so you can check it from any device i'm going to go over both how you build the circuit using arduino as well as the code that you need if you don't have any experience with any of these things don't worry i'm going to give you step-by-step instructions that will explain everything at the end of the video i'll show you an example of what i'm using my air quality sensor for i'm actually using it to monitor the air quality around some plants if you're new here and you want to learn how to build similar projects and get other tips and product reviews and things like that to live a more sustainable life hit the subscribe button down below so the first thing you need to do if you haven't already is to order the parts you see here and if you don't have them and need to purchase them i have some links down in the description of the video for that so what you're going to need is the arduino here i'm using the arduino uno the upload cable for the arduino uh you'll need you'll need a breadboard to plug everything into the esp8266 wi-fi chip which looks like this you also might want to buy this adapter here for the wi-fi chip because of the way it plugs into the board and i'll show you that in a minute then we have the mq-135 gas sensor and here's what it looks like on the back and this sensor is capable of taking a bunch of different gases because we're trying to build a sensor for overall air quality you could buy sensors for individual gases but we're looking at overall air quality and then you're gonna need a bunch of cables to connect everything and just make sure that they are male to male meaning they have the plug on one end as well as over on the other end okay so the next thing to do if you haven't already is to download the arduino software and so i have a link down in the description that you can click and it'll take you over to the software page of the arduino website and on this page you'll see a bunch of different download options and you just need to find the option that works for you so i am on a mac so i'm going to click this option over here and the page that this takes you to is where you can end up downloading the software from if you'd like you could donate some money to support arduino it is it is free so you could just download if you want or you can contribute and download once you click either of these buttons it'll start to download so you can see that here and you can see arduino downloading so i've already downloaded it so i'm going to stop that okay once that's done the next step is to program the esp8266 wi-fi chip now this chip does have its own microcontroller that needs to be programmed so to program it we're actually going to have to remove this one here from the arduino and to do that it can be a bit tricky but if you have a swiss army knife and you and you use the knife end of it you could just pop it right out now you just want to be really careful here though you know it doesn't really look like i'm being careful but you don't want to bend the pins on the microcontroller because as much as they will bend back into place they could break and there goes your microcontroller so just keep little by little trying to pry it out until eventually you can just grab it with your hand and pull it out the rest of the way and just take a look at the pins afterwards and see if any of them look like they were bent i can see on mine there's one or two here that i'm going to need to fix just be really careful because you don't want them to break okay okay so with the microcontroller chip out we can start our build so i'm gonna use a breadboard like this one you don't need one so big but that's all i got so that's what i'm using so i'm going to just go ahead and put my arduino on top of the breadboard where we're going to start is with this adapter and you can see on the bottom the way these pins are set up is they're pretty far apart and that's good because it makes it really easy to jump and get over this gap in the middle and if you don't know about these breadboards already how they work is that anything that's in this row is connected together so if i plug in something to this pin here it can be connected to any of the other pins in this row but it's not connected to the other pins uh in the other rows unless of course you connect them with these sort of cables here so the advantage of using this adapter is that each one of those pins sits in its own row and then jumps this gap in the middle to get its own row on the other side as well and the esp8266 the pins on it actually aren't really capable of doing that there isn't a good way to plug this into the board because it won't reach over that gap so you can you can use some female to male wires where you put the female end here and connect it over but it's a little bit more complicated you need to start using tape and things like that so it's much easier to use this adapter because now instead of having to plug wires in and tape all i have to do is plug this right into here just like that okay so now we need to wire the chip okay so the first thing we're going to do is i'm going to use this yellow wire and connect to the 3.3 volt pin here and connect into the line here now if you don't know what we just did was we connected 3.3 volts into these long one of these long lines here okay and these lines here unlike these pins which are connected this way these one two three four lines are connected the long way so they're connected across the board and so that means anything that i plug in here or anywhere along that line is going to be connected and the same for any of these across this way across this way across this way so what this allows us to do is that we need more than one connection to 3.3 volts but we only have the one on the board and so by jumping from this 3.3 volt pin here into this rail i can connect other things to 3.3 volts and if i connect them in parallel which i'm about to do then the voltage won't drop across any of those pins okay so the other things that we need to connect to these lines are we first need to connect from that 3.3 volt line that we just made into the vcc or power supply of the chip and we also need to connect that same 3.3 volt line and it doesn't matter which of the pins you use as long as it's on that line and connect it to what is labeled here as chpd okay so what that does is when that when that pin is connected to the high voltage which in this case is our 3.3 volts it enables the chip so next i'm going to take this rx pin here and connect it to rx on the arduino and then i'm going to take another wire and connect to tx and go to tx on the arduino as well okay so we're just about done last couple things we need to do is i'm going to take another wire and on the arduino you have a bunch of different ground pins there's two here and there's one here so i'm going to plug into one of these ground pins it doesn't matter which one and go over now onto the blue rail and remember all of these are connected so anything that i connect to this blue rail is going to be grounded all right so let's take another wire and we're going to go from any one of these pins now and we're going to take that and go over to the ground pin of the chip and the last one that we need to do i'm going to have to use uh one of the colors that i've already used i am out of colors is we're gonna go from the ground pin and again it doesn't matter which one into the one gpo and what that does is when gpo is connected to voltage or not connected it's going to use the code that's already on it gpio is a flash pin so if gpo is connected to the ground or the low voltage it'll take new code so when we want to put our new code on it we have to connect that one to the ground and as you can see we still have two pins left open the reset pin and gp2 there are some circuits where you could connect the reset pin but i just prefer this one since it's a little bit faster i can actually see here that i missed two pins um i just have to move these over just a little hard to see but the camera here but okay we should be all good now so you should have your tx pin over here going to tx your rx pin to rx we should have 3.3 volts this yellow line here going into the positive rail from there from the positive rail we go to both through the green wire and the blue wire to vcc and chpd we go from the ground pin into the ground rail and from the ground rail we go into the ground of the chip and we also go into the ground of gpo now that that's done we can go and flash this chip or put our code on it so we're gonna have to go over to our code okay so now we can go ahead and create our code and use it to flash the chip with the esp8266 does get its own code and that's what we're looking at here later we'll go over to a much shorter code that we're going to use to flash the microcontroller chip with and i did have to put this together through a combination of different sources that i found online i really couldn't find one that worked or really that worked the way that i wanted it to so i put this together through a bunch of different sources and it works pretty nicely and if you want this you can find it down in the description as well so the first thing that we need to do if you are not familiar with coding is to make this code work there's a couple of different libraries that you're going to need to download and so to do that we're going to go over into tools and then manage libraries and when that window pops up we're going to type in thing speak because we're going to be using thinkspeak to send our data now i've already installed it here but you can just select your version and click install and it'll do whatever you need to okay and so once that's installed you'll also need to get the esp8266 libraries and so again over to tools manage libraries we're going to type in esp8266 over here okay and add this library here the same way you added the other one another thing that you'll need to do to make this work is to go over to the arduino preferences and again down in the description of the video you'll find this link just go ahead copy that and paste it right into here under this additional boards manager this is what is going to allow us to use the esp8266 so just go ahead and do that and then click ok so now what we need to do is go on over to thingspeak you can find the link to things speak down in the description of the video as well and go ahead and click that and once you're over on this page you can create a new account if you don't already have one i do already have one so i'm just going to go ahead and log into my account now that i'm logged in you can see the different channels that i've created uh these are the ones that i'm using for that plant video i mentioned earlier and so what you need to do is create a new channel come up with a name for it for example air quality or something like that and let's go ahead and type that in field one this could be anything since we're measuring air quality you might want to do something like aq or air quality or something like that and then you can save the channel now with this channel what you're going to do is you're going to go over to api keys and what you'll see is a write api key and a read api key and the right api key is what we need this is what's going to allow us to write data to thingspeak if we wanted to read from the thingspeak we would use this api key here but since we want to write data to thingspeak we're going to copy this api key right here and what you're going to do is you're going to copy this and paste it back on over in the code to arduino which i'll show you in a minute we're also going to need this channel id right here and we're going to copy and paste that over into arduino so let's go back over to arduino okay so right over here in arduino in the code is where you're going to paste in your channel id from thingspeak right over here is where you're going to paste your api write key from thingspeak and just make sure you get it between the two quotation marks there the next thing you need to do is right over here you need to type in your wi-fi network name and then below that you need to put in your wi-fi password and just make sure that both your network name and your password are between the quotation marks so sorry i have it blurred out here and before you go and upload your code what you need to do is go over into the tools boards and select a generic esp8266 module and from here if you'd like you could click the verify button here and you'll see down the bottom that's compiling the sketch and this is just making sure that everything in your code is good and that it'll be able to execute okay and when it's done it'll say done compiling so that means our code is all good okay so the other end of this cable is currently plugged into my laptop so what i'm going to do now is i'm going to plug this end into here and what you'll see is that this blue light will flash so let's go ahead and do that and there the light flashes okay so then we can go and upload our code as the code is uploading you see this pin flashing you might also see your tx pin flashing your rx pin is on the board is on all these things are letting you know that the code is currently being uploaded to the wi-fi chip and you'll also see at the bottom of your code these these lines and percentages that are coming up even though it's red that's actually a good thing once it's a hundred percent that means your chip is now programmed just want to take the minute now and say if you're finding this video helpful so far and you want to keep seeing other similar videos subscribe down below now that that's done we can unplug from our laptop some of this is actually going to remain the same but i just like to take the whole thing apart and get a fresh build so let's go ahead and remove everything except for the adapter and wi-fi chip and now what we need to do is plug our microcontroller back into the arduino uh so that we can program that so mine has this little notch on it right here and that was pointing to the right when i took it out so i'm going to go ahead and put it back in that exact way and they are definitely easier to put in than they are to take out but still a little bit difficult to put in okay and we're good and just check it make sure all your pins are in nicely okay okay so the first thing that we're going to do is we're going to take the mq135 gas sensor and plug that in and remember each of those has its own row each of these pins has its own row so plug that in like that so the first connection that i'm going to make is to the 5 volt pin right here the reason why i want to do this one first is because if you accidentally connect the wi-fi chip to 5 volts you can actually end up ruining it so we're going to connect to 5 volts and we're going to bring that over to vcc any one of the ones in the row with vcc and plug that in okay so that's our voltage supply we also need to ground this sensor so again plug into any one of these grounds here and over to the ground and last since this sensor outputs in analog we need to connect into the analog pin there and so to do that we're going to go from the one that says a0 on our arduino over to the analog pin of the sensor okay so that's the sensor okay so now we can do the wi-fi chip we're gonna do the same thing we did before with our 3.3 volt line we're gonna we're gonna plug into 3.3 volts and go into one of the rails here okay and then from that rail again we're going to go into the vcc of the adapter or of the wi-fi chip we're going to go from that positive rail into the chpd pin again okay so now we need to ground the chip so plug into the ground and this time we could just go directly into the ground of the chip we don't need the gpo anymore because we want to use the code that's already on there okay and now this time rx is gonna plug into pin six and you'll see that in the code in just a minute and t x let me use a different color so we can see it here i'll use this white one tx is going to go from the tx pin over into 5. on the arduino let's double check that circuit so we have 5 volts this red one going into the vcc of the gas sensor we have we have a0 going into the analog of the gas sensor and we have ground going to ground for the chip for the wi-fi chip we have our 3.3 volt line going over this green wire into this rail here we're going into vcc and into chpd we have tx going to pin five we have rx going to pin six and we have ground going to ground so now we should be able to upload code to the microcontroller back to arduino you can see this code that we're using here this is going to be for the microcontroller chip on the arduino and it is different than the one that we used for the esp8266 and it is pretty short but this is everything that we need to tell the gas sensor to do a reading and send it on over to the wi-fi chip if you want to change the amount of time between readings i have mine set here for 5 minutes but if you want to change that you would do that right here just take the number of minutes multiply that by 60 and then multiply that by a thousand and so i'm using five minutes so five times sixty times a thousand is three hundred thousand um if you wanna do it in seconds just take the number of seconds and multiply by a thousand and put that number here and that will be how frequently your microcontroller chip tells the gas sensor to do a reading okay and so if you want you can verify that make sure it's all good and that you've gone ahead and copied and pasted everything okay and then before we need to up before we upload that we have to change our board one more time so we're gonna go to board and we're gonna go over to arduino uno since that's what i'm using and just make sure you select your arduino board so that it knows to go to the arduino board this time and with all that we can plug the cable back into the arduino and click upload and now you can see that the lights on the gas sensor are also on which is a good thing okay so now back over in thinkspeak click on channels my channels and you can see all the different channels that you have set up these for me are just two test ones that i have but these two are ones that are actually up and running right now i have two sensors that are running the one i'm using this for is i'm using this first one here to measure the air quality in a sealed off box with a plant and i'm using this second air quality sensor to measure the air quality in a box that's also sealed off but that doesn't have a plant in it and my goal here is to see if plants can actually clean air and so if you want to check out that video check it out in the description below if you enjoyed this video and want to see similar ones like this video and subscribe to go green post so what are you going to use your sensor for let me know in the comments if there are similar projects that you'd like to learn how to build let me know in the comments as well thank you for watching i'll see you next time you
Info
Channel: Go Green Post
Views: 22,739
Rating: undefined out of 5
Keywords: Arduino Wifi Air Quality Gas Sensor Tutorial, Wifi Air Quality Gas Sensor Tutorial, Arduino Wifi Air Quality Gas Sensor, Gas Sensor Tutorial, Air Quality Sensor, Arduino air quality, gas sensor, air quality, air quality sensor arduino code, arduino air quality sensor, mq135 gas sensor esp8266, air quality monitor arduino, air quality monitoring device, mq135 gas sensor arduino code, mq135 gas sensor arduino, esp8266 projects, esp8266 arduino, esp8266, MQ135
Id: 1LJgZkrKMeo
Channel Id: undefined
Length: 26min 15sec (1575 seconds)
Published: Tue Jun 01 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.