ESP8266 Project: How to control 4 AC bulb or load using 4 Relay with NodeMCU and D1 Mini over WiFi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hi! Welcome to in Internet of Things (IoT)  tutorial from Robojax. in this tutorial we   are going to learn how we can control for easy  bulb or for loads using four channels really   and new them see you to turn on enough easy loot  dissolute fan where web interface when I click   it turns on turns off AC load DC load number two  number three can be turned ON and off now let's   turn on the right turn ON the light. Turn ON the relay using do  D1 Mini to turn on and off or relays.   you can get the code for this by clicking at the  link below the video in the description which   will take you to robojax.com/learn/arduino let's get started with this My name is Ahmad Shamshiri. I am presenting tutorial from Canada. working with AC is very dangerous make sure  that once this is connected, do not touch here and   also make sure that this is not on a surface  that is metallic because short-circuit would   cause fire and it is very dangerous and if you're  unsure how to proceed with AC seek help from   some professional or person who can handle  it safely otherwise I would suggest using a   DC load and 12 volts DC or maybe 5V, 6V just connected here so you can turn it on and   off and learn and later on if you're using it  practically in some application then seek help   from someone who can handle this safely. I've  received a lot of requests to control loads or   AC load, AC bulbs, fan or whatever you have for  DC over the Wi-Fi with node MCU d1 mini esp8266.   so I've created one channel relay using your  mobile device or desktop computer and then for   to channel this is the four channel I'm going  to create also an 8 channel video as well. so   we are going to control it using this NodeMCU from your computer or your mobile device. Wiring Explained if you need a wire like the wiring diagram for  this it will be available as part of my Arduino   course at Udemy where you can learn or do we know  from ground up in the structure course a step by   step with all the code library and wiring diagram  in one place the length of my courses below the   video in the description for this demonstration  I'm going to use this AC bulb this is a plug that   will be connected to wall outlet and the light  will be turned on the middle at this point I have   disconnected the wire one of the wild the live  wire here and has twisted them and prepare them   these two will be connected to the relay job of  really is to turn it on by connecting these two   wires turning on the light and disconnecting it  turning it off so this can be a bulb or a fan or   any other load the same way that really will  connect it and disconnect it these two wires   from your load in this case an AC bulb if it  is a fan or motor the two wire from that will   be inserted to one of these for release that we  have so if I if you want to connect it to really   one out of these three it will be connected to  these two pins in here if you want it for relate   to it will be connected here the test pan is  not connected the same way for the third and   fourth and here I've connected it to really run  to these two pens I have external power supply   these two are my power supply five volts for the  relay the span on this side is connected to five   volts this side is connected to the ground using  these two wire that goes to my external power   and then here we have input one two three and four  therefore for relays accordingly this the last one   is connected to d1 it has been connected to d1 d2  d3 d4 accordingly and then from one of the ground   doesn't matter which one from this G or ground  I've taken and I've connected it to my external   and to my fellow power supply unheard-of the  wiring for d1 mini channel one is black one two   three and four have been connected using these  wires hair from one two three and four on the   side we have D 1 D 2 D 3 R 4 and the last one is  ground is connected to my external 5 volts ground Preparing Arduino to work with ESP8266 the first thing that you need to prepare is your  Arduino for esp8266 a separate video explaining   that but here I can tell you quickly I  will provide you the link click on file   preferences and then additional board managers  URL click here and then paste like the link that   I provided I will provide you this one so you  copy and paste it here once you paste it you   click OK and then click OK now this this link  will make Arduino to know where to look for the   ball then click on tools' board and then board  manager once you are able to type esp8266 then   you will see this esp8266 by esp8266 community  and if you have not installed it in my case it   is installed and there is a remove button in  your case if you have not installed it you   will see here install button click on it and  wait and tell the bar graph finishes and then   close and you have to flick your board before  using it click on tools' boards and here there   are tons of other boards but the one that we are  using will be generic esp8266 module select this   and the rest of the settings should be automatic  and then you have to select of course the right   port if you don't know what is the pour that  you are using on the Start menu right click   go to device manager or any other way that you  have go to Device Manager and under the port   collapse it and you will see serial USB serial  maybe you will see some different numbers but   this is a chip for USB ch3 40 that's comm 11 and  that's why I have selected here and a comm 11 you Code Explained took fill in the code first we often dress  under stage this interface is an HTML page   which is generated by the new dempsey you or d1  mini FB T 266 is generating this if I press ctrl   you will see that HTML text that is generated by  the motor controller and here it starts from this   tag which is HTML and HTML ends or closest with  forward slash here and then in between this as a   title where you can see it in here and each  push button is divided into division or dev   and here is a flight one on and these are the  values and these are the style for the color of   the background so each is represented like that  so this is generated with the esp8266 which I'm   going to explain next now let me explain the  code this code is taken from an example or   if you click or if you select your esp8266 board  and then go to file examples and another example   for generator gives with you 266 module scroll  down and tell you see esp8266 web server and   then advanced web server if you open it you will  see this page but I have heavily modified it so   it can be used for controlling the relay first  I've added this mapping for the pen for East 52   66 either do you want many or no them see you so  these are random numbers first for the pens but   we can enter these values that are printed on the  most of the modules they have printed the 2 which   means 4 so you don't need it so you type whatever  is the printed value and upon the board first we   define how many relays we have in this case we  have 4 and then relay pen is an array of length   and really count which is 4 and then we put the  pens which we have defined here I've put them in   order so you are wiring will be easy side-by-side  so you don't make mistakes and then relay state is   the state of really either initial state or later  on will be used by the code and this is referring   to really one really - really four and also this  also depends that really one really two three and   four is connected and these values 1 means off  and 0 means on so if you want to keep the relay   off put 1 1 1 and this will cause the release to  be off initially otherwise make it 0 to be turned   on and then button title 1 and button title to  title 1 is the title that when you click so this   is title 1 and when you click it goes the title 2  you see this on changes to off and also background   color and the other stuff will be changed so light  one on like - and as you can see I've named them   and if you have fan you can call it fan 1 fan  to fan 3 or if you have motor or whatever so   these are on the set of values and then these  are the argument ID we call it our one or two   or three really one really to divvy three even  if you use something else please do not change   it will create some issue if you do not properly  taking care of other settings so it's just really   one really two three and four these are port parts  of the code which I have not changed I've put here   my SSID for Wi-Fi router and this R is capital u  pay attention to uppercase and lowercase otherwise   it will not work and then put your phone password  I used this router specifically for recording so   I'm not worried about the password I will turn  it off we're finished this line is initializing   the webserver at the port 80 and hundred root is  a function that was there but I've changed the   totally and side that I've created and a string  variable called HTML and this is the beginning   with double quote and that is the end in between I  have the page title and all these things that you   just saw here all of those is printed from here  but we are also concatenating or adding this value   to HTML later on and then based on for each Lily  we are creating these buttons using a for loop   that goes I equals 0 1 2 3 and here it s the early  stages 1 then we print one type of button with one   type of text else we create other button with red  color and different text and this at this line we   are just adding everything so HTML has been in  completed and then it's printed and thus lines   are percent of the type text and HTML with a code  200 so this is just sending the page to the screen   not found is a function that takes care of request  that is unknown for example right now if you pay   attention and look at the top or if I bring my  mouse look at the bottom here the status bar you   will see that it says forward slash after the IP  it says full refresh relay question mark or 1 it   says on and then off so a forward slash relay is  defined in the code if somebody types for a slash   book you will get this errors not found and that  is taken care of by this section file not found   which has not changed it at all and here inside  the setup again I use a for loop to assign these   four pins for the as an output defined for  pencils and outputs at initial state of each   really whatever is a state either high or low so  instead of creating eight lines I just used this   for loop hair I'm defining the serial monitor and  I should I think it what 115200 board and this is   the text being printed this value must match  if I click here and open it on the right side   lower corner this is the number that must match  otherwise you will not be able to see that text   the first part of the code I did not change it  for a Wi-Fi initialization if it is connected   this is also printing the text I have just added  this HTTP before printing the IP address so if I   press the reset button on my device so if you used  to parent earth but I've just added this HTTP so   you can just copy and paste it or you can use  the multicast DNS esp8266 let me copy and paste   it so you will see that Latin also works on my  computer but as I said in some devices you might   face challenge with this and this is multicast DNS  we define Robo jack CA speech - easy 266 to access   it and using this line I'm just printing it and  the route is taking care of the route which means   if you don't type anything just IP address that's  called route or for Worster - delayed this is a   line that I have added we as we are creating for  us or Ashley if that type of request get comes it   will go to this function which I've defined it  below this at the end of the code which I would   explain it and these were part of the original  could have not changed it inside the loop we   initialize a handle client which takes care of  all the requests and then this is a multicast   DNS it was already there here I don't know I have  created a for loop that starts from I equals 0 and   it goes to I equal when I as long as I is equal  smaller than really count which is 4 that goes 0 1   2 and 3 so when this I changes it gives a state  and it checks at every is equal 1 then we set   the relay to equal high so this will turn off the  relay else turns it on so when you send a command   from this screen you are actually changing the  real estate which I will explain next and here   we are just applying it to the pen so the relays  control this was for the debugging purpose if you   want to remove it will print the state of each  pen a zero at 1:1 for learning and debugging   leave it like this with forward slash otherwise  you are esp8266 would will respond very slowly   and then we with 100 millisecond and the loop  will continuously take the same action over or   over again her really control is a function that  again we have a loop that for each relay we check   it and we check a server argument ID is equal  on top of the code and here are 1 or 2 3 4 so   we check it if it is equal on then meaning that  we have to set it to 0 if the request comes four   on we said zero means on so we said the relisted  specificness as I 1 2 3 or 4 so that really will   set be set to 0 otherwise else every is equal  off then we set it to 1 so we change accordingly   specific relay because this will be R 1 equal  on or two or three or four whatever the value is Demonstration NodeMCU on Desktop now let me demonstrate it for demonstration  first we have to make sure that this device   whatever Wi-Fi SSID that this one has your  computer or your phone must be connected to   the same Wi-Fi SSID if I click here you will see  that this is connected to Robo Jack's after that   I can click here and open the serial monitor  and here I can press this reset button and   wait and it will print the IP address 192 168  1 and hundred I can also access it using this   Robo Jack's esp8266 this is trustworthy and  available for sure but some networks or some   devices were not recognized as it will not be  propagated through the network so you can use   this if it doesn't work this always works but  let's go 1 9 2 and then 100 and here I have   press ctrl-a press ctrl+ to increase the size you  can decrease the size like this if you press ctrl   0 that's the original size and then and then you  can increase it like that I'm going to show you   the LEDs here because one of the channel one  is connected to the bulb and the rest are just   these LEDs you will see and this is now connected  external power is also on so if I turn on channel   1 as you can see the LED is on channel 1 is on  and then channel 2 as you can see this is on   and then channel 3 and channel 4 channel 4  is also coincidentally it's connected to 0 so, it responds perfectly Demonstration D1 Mini on Desktop and using dual mini to turn on  and off the lights or relief Demonstration NodeMCU on Mobile I will demonstrate it using your mobile device  you must be connected to the same Wi-Fi as the   northern fuse this is now Robo jacks I'm connected  to the right and I have now entered 192 168 1 dot   hundred and as you can see on the screen we  see the same thing that we see here and now   let's turn on the light turn on the relay  channel as you can see all of them are on and can be turned on enough I would like to thank my patrons from Patreon.com Subtitle typed/corrected on November 04 2020 by Ahmad Shamshiri in , Canada I did my part to help you learn. Now it is your turn. You can subscribe to my channel, thumb up 👍 the video and type a comment by saying thank you. If you need devices used in this video, purchase them from the link in the description. If you don't skip ads it will also help you . My PayPal Account link is in the description if you want to make cash donation. Thank you thank you for watching this was how to  control for relay or for load using your   Wi-Fi and esp8266 or node MCU or D 1 mini.  if you learned something and found this   useful please thumb up as this will help my  video in the search algorithm of YouTube.   if you have comment our question posted on  the comment section below I always try to   answer and reply and make sure to subscribe  so you get updates of my upcoming videos.
Info
Channel: Robojax
Views: 11,383
Rating: undefined out of 5
Keywords: electronic, tutorial, training, video, robojax, arduino, code, download, project, diy, robot, robotics, afghanistani, canadian, engineer, nejrab, ahmad, shamshiri, ontario, ajax, english, esp8266, nodemcu, d1-mini, d1 mini, connect, control, ac, dc, load, fan, motor, setup, wiring, wifi, mobile, phone, desktop, router, mdns, url, home, industerial, automation, automate
Id: a8yJoeFsKWw
Channel Id: undefined
Length: 21min 28sec (1288 seconds)
Published: Mon Mar 09 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.