Sensor values to any website through the arduino and ESP8266-05 module

hi guys today I’d like to show you something fun were made with the app we know and it’s not going to be a federal walkthrough or tutorial it’s just going to be a brief overview of a small project that I’ve done over the Christmas and I’m going to hold it up now so you can see it right here I’ll show you a screenshot or picture of this up close in a minute but basically what it is is a Arduino mega some sensors and a my 5 mod module it’s the ESP module and this one is called – oh five and as soon as you power this it’s going to boot up it’s going to activate the sensors activate so the ESP module or Wi-Fi module and then it’s going to send data to a SQL Server online and actually feed back the data so you can see it on a web server and there already is services that provide this for you but I’d like to run my own service I want to run my own server and I don’t want to be dependent on some sort of free service so this is purely made to basically test if I could upload data directly from my arduino to a web server and then use it for something like a graph or whatever so what we have on this is a quick overview here we have a lm7805 voltage regulator because this is able to be powered from batteries we have a peer model a infrared sensor detecting motion I have a dht11 that’s a humidity and temperature sensor and of course I got the ESP module and over here hidden away between the wires we have a LDR sensor measuring light up here I have a voltage meter and a small screen so I can see what’s going on just going to hook it up to the computer so you can see what’s going on right now I’m measuring mulch it’s on we’re measuring on the lower rail and you can see it might be hard to see on the screen but the monitor just turned on on monitor to small old it and it’s displaying some stats yeah we’re not gonna worry about that right now so it’s running and I can actually watch it right here until okay it’s offline right now and when this is online it has connected to the Wi-Fi and has sent some better to the web server so there we go let’s take a look at the the screen shot I got a few I got one with let’s flash on the camera as you can see here we go and I got this one without the flash I think we’re going to use this one right now so basically you can see we have the Arduino right here and a hair pull mess of wires but basically this rail down here is anything from I believe it’s 6 to 36 volts I’m only using something between 6 or 12 volts input power runs into the lm7805 and up into this rail which is a 5 volt rail 5 volt rail then runs into the Arduino you can see right here there’s no wire right now but when I’m using external power source and no connection up here this orange wire right here is going to be moved from the 5 volts and put into this one which is Walter input and then we have this green one which powers the ESP module that’s 3.3 volts and that basically takes care of all the power secretary of course each module requires power the peer sensor down here requires five volts so that’s just hooked up to this rail this one requires five volts so you can see it’s right there hooked up to this rail as well and LDR

sensor is 5 volts as well also hooked up to the same Braille the LDR sensor also has a 10k resistor right there between the ground and the sensor you can see the since it runs over to a zero that’s the yellow one all yellow wires are just sensor wires all red or orange wires are power wires blue or black are ground it’s only exception is the green three point three right now so we got sensor to analog zero the peer sensor just runs over here it basically just takes motion or not so the input I get is 1 or 0 which is fine my ESP module is connected through transmit and receive one not zero you can use zero down there but one zero is actually being used when I develop and debug the software and the USB port is using the serial connection so that would just make things a bit strange if you start using the same however if you’re using this on a Arduino you you can use the zero but then you won’t have any serial feedback on your computer on the mega you have at least you can see you have several channels you can use for feedback or hook up several strands bit and sending modules the monitor oh sorry oh let is hooked up to five volt rail down here and it’s just using I squared C communications protocols the vault Mina is down here it’s this one you can see it’s a white wire right here and orange down here that’s just a measuring wire the two others the red and the black are hooked up to this rail up here for five volts and ground just to power it and then sometimes I take this one out and I miss you here and here just to see if I’m getting the correct mulch is just right now so as you can see right now I’m running three point eight on this rail down here but it doesn’t really matter because there is nothing connected to this except this lm7805 and it does not run at this low voltage anyway so there we go that’s the that’s the unit and it works without this USB connection you can just hook a battery into this rail down here the gray wire you can see right here is the antenna for my ESP module to have it down in that cutout you can see in the plastic but it keeps falling out and the antenna is very much needed if you don’t use that Jena it won’t be able to connect to your Wi-Fi here we have the same picture and we used the flash or I use the flash and funny thing is we can see this flash effect on the output in a minute but we can also see a bit more of the screen right there it’s not very easy to see but hey let’s take a look at the web server so here we have my web server I’m going to zoom in a bit so you can let us see it’s only showing the last 20 entries and since it’s offline right now it’s not sending anything I got a time I got it value from the LDR sensor I got a humidity value I got a temperature and I got movement or no movement but now I have several entries and you can see I’ve run it at several different times if you notice you can see it’s usually when it’s running it’s updating once per minute or once every one and a half minute it’s actually designed to send every 30 seconds but it fails very often so it actually succeeds every twice or third time so that’s fine enough for me for this purpose if I wanted a hundred percent success I’d probably work on a more stable connection all of this data can of course be turned into a graph making things a bit more easy to see and I found a graph solution online a free one I just used for this purpose and you can

see the values right here notice this high spike right here guess what that is you can see it was on the 27th of December 2015 at 1218 Zulu time take a guess yeah that’s the flash from the picture when I took this picture so luckily for me I was able to take the picture just as it was the reading reading that the answer so that’s actually quite funny so this picture was taken exactly right here hmm so the data what don’t bind these numbers time here that’s actually just the same as the tooltips you can see it has a number date and time but it’s very hard to fit date and time into the spaces down here but the red line is temperature the green is humidity blue line is movement engine no movement there that there and light so you can see there’s no light no movement high temperature and high humidity I’d say it’s dark nighttime and my cat was here yeah I’m sure he was laying on top of the entire thing or something like that and you can see the temperature was just around 24 degrees Celsius what’s going on here I’m not sure I’m not sure and the same with the mid humidity spike right here why is the air suddenly so moist after Sun well I can explain some of the spikes if you would take a look at the data you can see I have a huge step right here and when you take this huge step you’re missing a lot of theta you can see from 11 to 23 it was 52 then at 1903 it was 40 that’s a huge jump well it’s not really that huge but when you are doing it like a graph it shows like a huge jump and the same you can see this one right here I suspect at this point I might have been breathing on it to increase the temperature to test if it was working so I would very brief very heavily on the sensor right okay so that’s the website sorry let’s take a look at the code the Arduino code first of all I normally I use the Arduino edy of course as you can see but I have copied it all over into monodevelop because it has this nice zoom feature and I don’t need to hide my Wi-Fi password and cetera so let’s use the zoom feature there we go let’s run through the code it’s not that long only 200 lines or so got a few libraries the DHT you don’t need it but it’s very nice because it’s a using a pre pre calculated formulas to transform your measurement values from the sensor into something usable like temperature in Celsius and humidity in percent that’s why I have it gfx H is needed to run the SD card sorry not tasty got there the graphics on the small OLED display and this is the OLED display specific library the spring AP SSID is actually the Wi-Fi identifier and this is the Wi-Fi password server code is when I upload to my server to prevent people from uploading on their own I edit a off of the education code and the code needs to be included in the data although otherwise it won’t work so it’s just protection you don’t really need it so in fact while we are going through this I’m going to remove it so you can see how these things are connected so we’re removing the off code there then we have the site that’s the domain where you enter the domain I have my page this

is the link after the domain excluding the domain right back excluding the domain to where you actually spotted that on your server then we have things you want to add after your pair to stall we’ll get into that but that’s basically using a method called get when you’re sending that to a HTTP server or TCP server all right so I’m sending four values I’m sending LDR temp humidity and PE PIR motion detection the tape I’m still sending it but I’m not using it we’ll get into that later I just haven’t removed it yet then we start to hold it blah blah blah with the define our sensor pins placeholders global placeholders for values time intervals because I have different wait times I might change them accordingly initialize initialize the DHT and then we finally get to our setup we set up our LDR pin we set up a screen and if I’m running developer mode that’s abilene I got up here there we go developer mode it’s true if this is true then I am sending that or receiving data on the serial line to my PC so by setting this to false no data is being sent to the PC that’s good that’s why if you have it right here we don’t need to begin serial if we are running false right so l1 is to begin connection to the ESP module and serial.print that’s basically here we start to reset and initialize the ESP module so we start up by connecting it here and then we send a reset command instantly after excuse me this one called this advice it’s called V’s in Danish that’s a small thing I’m using to display things back on my PC you can see it says void this string what this is things for what if dev mode meaning if they’re mod is true then print what so you will see this throughout my coat it says this something inside meaning if the dev mode is true then this will be printed back to the terminal long delay with a defined delays in the top we begin map THD measuring and we initialize our main display don’t mind these these are something I edit we have our main loop so if dev mode is true then we would like to know what is the ESP communicating back to us it might say error it might say something else otherwise we ignore it delay we have a small delay we start with a delay that’s a bit weird but hey yeah okay that should be at the end of the loop but hey whatever the loop delay that’s fine we start by reading our sensor motion sensor we read our light sensor and I actually feedback on that as well if it’s true remember we read our humidity and temperature in Celsius and here we go start the actual functionality of the program if is on line equals to false meaning if the ESP module is not on line then we’re going to set display on the device to false which actually means it shows as offline then we’re going to display just the values then we’re going to try to connect we’ll get to that in a minute and after connecting we’re going to send the values otherwise just display online meaning if we already are online so this will only run once or twice if it’s possible yeah then this one will show true and it will be online on the small display and we get the values this one is again sending the values just like this one to a web server so let’s go

down to main display first main display is just really what’s going on on the main screen and you can see I’m taking four variables I’m taking the bullying I’m taking three integers the bullying is down here it’s basically just to display online or offline 12 values sorry the integers are basically just showing the LDR LDR value humidity humidity value temperature and the way we have temperature value it’s just giving you a live feedback then we have this one ESP con show for connection and that’s right here we have ESP con and again I’m going to connect we are already connected we did that in the setup with the reset as well remember then we’re going to send the mode choose TV mode 1 excuse me yeah it’s really bad for my trope we have this this value sorry library right here at github and you can see we have this CV and you can just find the commands right here and you can see see we moved one main station mode so we are actually setting this to station mode 1 it’s usually already at that I’m just doing it again just in case in fact you should actually run a plus no something like this right after to reset it but we are not going to then I’m going to run the connection string for bin it’s means connecting Danish and I’m running a t + C V join access point then we’re going to use the excess part ID we got from the top right here and the password as well right there and then we’re going to wait connecting previously I had a you can see I have it right here while serial it will just stay and loop over these until it would give me a feedback from the ESP module but I learned that sometimes it won’t even give the feedback maybe it’s because of bad voltages I don’t know but I had a very large error margin making it not so successful so I decided to drop that loop and just ignore the ESP modules feedback and simply try to wait eight seconds and then just send anyway sometimes it would just right okay you can see if so you’ll find okay then it sends if serial fan fail it stops and returns otherwise it just goes back to the main loop and nothing has happened so when it finds the okay value from the serial that’s the feedback from the ESP module it’s going to set the boolean to true which is on line and when it’s on line remember up here it’s just going to send the values to the server so let’s see how we’re going to send two values that’s called is here we have the string get and we’re building the link the link of the entire server so when when when do we are entering data into SQL so you need to know some PHP first if you’re using PHP so let’s let’s hide our Arduino code just a minute I’m going to pull it over here and I’m going to grab some PHP code and you basically need two files to store data of course first of all you need to setup a SQL Server and I’m going to show you something you should never do after 2015 I’m using my SQL and that’s something that’s being outfaced from PHP 5.5 so now you’re going to use something called a PD Oh like this video or my SQL I that’s the new standards but my server is running PHP 5.4 I believe so I’m

perfectly happy using old-school PHP SQL commands basically I first define just like we did in the Arduino I define my username my password my web address and my database name these four values and then I have a function that’s called connect and that’s it this connect function has two commands the first one is connect to deathbed address database username database password or Die which means if it does fail just stop and then we have this one called select database meaning once the connection has been made we’re going to open the database or make it available but it’s not going to run these things because they are inside a function and it’s a c-sharp or C plus developer you should think of this as a void a separate void and it’s not being called yet it’s just there it’s just standing there not doing anything okay now we don’t want to save let’s close this one then we have this one called get des a PHP and yeah I’m just writing something hang on just a minute there we go this one is actually the only thing you need and still remember this is old SQL after 2015 we are changing this to SQL i or PDO okay enough I’m just typing just testing meaning if you enter this website website it will just show this and nothing else then it’s going to ask for the previous file the one we just saw connection and then it’s going to call this command what happen is really it’s going to take the entire file with all the connections and put it in in front of here we have just reduced this to one line then we’re calling the function right away and then we are getting these things from the menu meaning let’s get a browser when I enter my domain calm I enter you can see this one is called get dater kids it’s a PHP question mark and then we have something called el dia da equals some value and we have a temp TMP which is stupid short for temperature yeah another temperature and we have something called Hume Hume equals to another value and sine pi/2 some value this right here is actually what this is looking for so you can see we have these four values Anderson and sine and in front of it all there’s a question mark so basically we have to build this drink in our Arduino and put it onto this page so that’s what we’re using the ESP module for then we have this and you can see the PHP page is just taking this one and renaming it to this one and down here we are building acquire e which is something you do with your SQL databases which is taking the data from the website and putting it into a database so take this data and put it into this table at this position just one data entry is right here we have these columns table name these columns put in these values so this value tato gets in there this value from here gets in there this value is here it gets in there that’s basically what’s going to happen and this one is actually execute of run the entire function this one up here is just like in that we know we are building the line first and this one is running the line that’s all you need to know about PHP back to Arduino code so we have our we’re trying to build this line unity my domain get dad’s a PHP etc so oops I’m building it as a string so we start out by calling it a B

skill which is Danish for message equals get we want to type get first space then we want that domain we enter the top we want our page get data we want our tenth occasion we’ve removed that earlier and date don’t forget this date thing then we want our actual date value that’s this one right here then we’re going to add sense of one up here arstan so one is called an LDR so we are adding and LDR it’s this part right here equals this part and a value and then we continue to build until the end then we end the message with HTTP forward slash 1.0 back slash are in iron basically it means it’s sending a HTTP link signal yeah it’s hard to explain and the ions are just enter values for different systems meaning it’s actually doing this so okay after we got this entire string it should look something like this part right here then we need to send the string to the a ESP module but the ESP module needs to know how long is the string well we’re going to count the letters by just using this function called length so the skill message dot length and then we’re sending a link message this is another so quite I wrote is peeling takes the link which is a number and message itself that’s the link that’s right here so it gets the number and the message then we’re going to connect to the website using a command called a t chip start so we can pull this one back and we can see down here we have chip start starts a connection as a client yep that’s what we want and then we’re going to say TCP and we’re going to commit to our domain not the entire link just the domain at port 80 okay these are just relaying the commands once again and we are waiting for something to heaven if we find an error we just break and stop otherwise we continue if there is a delay on there we will never catch there and it will try to send even though we have the error and this is why it’s not succeeding every time but it will try to send anyway so that I’m happy with that oops there we go then we’re going to send the link by first we’re going to use something called see IP sent so we going to go back to this page and we’re going to use this see IP sent and you can see the first thing it wants is the length of the data that’s that we’re going to send so we got that from before that’s the count of the letters from the domain and the data and we’re sending and we’re just letting the ESP know we’re sending maybe ninety letters now or soon and then we’re simply sending the link right after that’s it because once you use this command it will return something like this and just stand there idling everything you enter this it’s going to try to relate to the site we just connected to by using CP start right here and that’s it CP closed we’re going to enter connection and the loop is going to run from the beginning again yeah let’s quit that that’s all that is happening it seems like a lot for this it’s not so bad let’s try something I’m going to open my Arduino interface power up using my mega the one with the modules on I’m going to open a sketch called a T relay and I’m just going to

make sure it’s on the right port yeah and I’m just going to upload it overriding anything on there right now so basically now I have my my command module and it’s sending commands directly back and forth between my Arduino and the ESP module and this is how you test if it works so to test if there is a connection just type 80 and it answers okay if it says arrow then you might be using the wrong baud rate or you might be using the wrong line endings and then you can basically just start hate trying these commands new z80 cv lists essex points and if this works you can see oh I got two access points right here I got one called ROFL mouth three got one called HP print that’s the printer right and you can test the commands using inside your using inside we know like the reset you can see it says okay but please wait and you get these airlines don’t worry about them that’s just connection arrows it’s fine it’s still working you saying it’s a system ready make sure you get version of the current firmware it’s a 1.8 902 nice and all of these commands if you get something like this error wrong syntax you say what’s what’s wrong oh you need equal time yeah will wake up after so it’s a sleep mode and you can use all these functions but some of them requires previous functions to be run so something like 80 see you blowed you know this is fun I don’t know why it’s saying that it’s a question mark it answers well I’m in Multan right now ok that’s nice a tcv mold equals two then it changed the moat and a C dot C dot B mold question mark I wrote move instead of mold there we go you see it says era okay that means we have to reset it reset and wait and basically that’s how you are going to send a learn how to use the ESP module so you just sit here and experiment with how you’re building these lines and texts I know I might have made it a bit more complicated than it actually needs to be but that’s because I want this data on a website and once I have it on a website I actually have it inside ie database I can then also put it in to pull the data out and you can see I can set up different values I can see this is my UNIX timestamps my LDR sensor values my temperatures my humidity and my motion detection and you can see I’ve just put them into Excel I’ve extracted them from the website and you can do all sorts of crazy things with this data this one you can go into this link and this one is the one I’m actually using with the module your you saw earlier in the video hope you enjoyed watching this and if you have any questions of course try to write them in the comment section below otherwise on Facebook and I’ll try to help but a lot of the questions I’m receiving often something like I have connected something to my Arduino and it’s not working why well to be honest I can’t tell you why because to debug or find the solution of something you really need to measure the wire see what’s broken was not broken I using the correct libraries are using the correct code it’s extraordinary a huge process to debug and find a error on function or something wrong and one of the videos I get a lot of response on are the oscilloscope I still have it right here and I do occasionally use it

but people are using different monitors they’re using different versions of the arduino ide which also has changed a lot since then and a lot of libraries included in the code have changed meaning they have changed the commands of course usually you would think they make them better not always but sometimes they do but that also means that sometimes commands get deleted or removed because they are obsolete and in order for me to update all my projects means I have to run all my projects and I don’t have room or data storage to be able to do that so usually once my project is done i disassemble them or give them away or something and I don’t have access to them anymore and I don’t stalk the code so if there’s any code involved and I put the code in usually I put the code in a sip folder and I link it through Dropbox in the comment section below the YouTube video and you can get the code there I don’t have it physically on my computer anymore but that’s basically it so if you need help please be very specific code library Hardware connections as an absolute minimum for anyone to be able to debug any errors at all anyway guys thanks for watching comment rate subscribe and I’ll see you next time bye