How to use a RELAY with ESP32 | Easy Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so let's start off with our esp32 over here now there are a lot of pins on the esp32 that you can use but what I have seen is that sometimes you use the Wi-Fi module so some of the pins don't work properly and some of the pins are for input only like these row of pins over here so what I found out is that the pin number D5 over here is absolutely perfect for your inputs and outputs even if you are using the Wi-Fi module so we will use that one and this is basically a single Channel relay over here so we only need one output pin the rest of the two are for the power supply so on the relay here you can see we have the VCC which will be our positive power supply in which is for the input so this will actually turn on and off this relay over here and the ground which will obviously go to the ground now on the other side of the relay you can see we have three terminals over here the middle one being the common terminal the right one being the normally closed and the left one being the normally open you can also see that how the markings are printed on the PCB over here so as you can see from the common the line is slightly tilting towards the right side that means that when the relay is turned off these two points are connected together and these two points are not connected so once we turn on the relay the connection between these two pins or terminals will gray and that would be transferred to these two terminals over here so like I said let's connect it up so first we will connect our VCC to the 3.3 volts out on the esp32 over here as you can see at the bottom left then we will connect our ground to the ground just like so and then finally our input pin will be D5 which is right over here as you can see and unlike the esp8266 the pin number over here are actually the gpio pins so now that we have connected the esp32 now let's head over to our computer and program it now before we do anything first we need to make sure that our IDE can actually upload this code to the esp32 board so first of all what you have to do is just go to file then click on preferences and in the additional boards manager URL we have to paste this link over here I will give it in the description box and then click on ok now we need to install the esp32 boards on the ID so for that we'll go to Tool select the board and then click on board manager you will get this window over here and all you have to do is just type esp32 and at the bottom there you can see we have this esp32 by espresso system so you will need to install that I have currently installed it so that's why I'm getting the remove option but if you have installed you will get this install button and once that is done now we can finally upload this code to the esp32 boot so let me just give you a brief explanation of what this code is first we Define the relay pin over here and I have just set it as relay one so the relay one will store a value of 5 5 being our gpio pin then in the setup function we will set the pin mode of relay one relay one being the value 5 as output so the esp82 knows that we need to Output a signal through this pin then in the loop function which will run again and again we will digitally write the value to relay one again pin number five to low so in digital write function we only have two options of writing either high or low and as you know it will be either 0 or either one so in case of low it will be 0 in case of high it will be 1 when 0 being the case nothing will be changed on the relay so it will just remain at its uncharged state but when the relay is set at high the relay will turn on and switch its position to the left side as I have said earlier and in between those we have a delay of one second so every one second the relay will turn off and turn off as you can see over here the relay is in milliseconds so 1000 milliseconds equal to one second obviously you can decrease or increase it so this is just a simple code just to show you how you can get the relay working so let's just quickly connect the computer to our esp32 board first and now let's go to the top there and select our board and com Port so in the board section you have to write esp32 I am using the dev module so I will write just Dev over here as you can see I get the esp32 dev module over here if you have any other model all you have to do is just search it for here and it will show up in this section over here so just select that and whatever com Port you get over here just select that it's usually the com port in which your tsp 32 is connected in my case it is com port number five so I will select that and then click on OK so now that our com port and our board are selected now we can just go ahead and simply click on upload and this will first compile the sketch as you can see over here and upload it to the esp32 board so now as you can see it has uploaded to the board now let's head over to our esp32 and see how it is working so let's power it up and see how it functions so let me just connect the USB cable over here and as you can see we get a ticking sound in the relay over here and that is basically meaning that the switch is being turned on and off so in the off position as I said before these two terminals will be connected together and in the on position these two terminals will be connected together and you can actually see that once the relay is turned on you get a green light so let me just reduce my light so you will be able to see that as you can see the green LED is turning on and off so when the LED is turned off that means the relay is in off position which means that these two terminals are entered together and if the green light is on that means the relay is in its charged or on position so that means these two terminals will be connected together so there it is guys that's how you can control a simple relay with the esp32 module and if you want to add more of these relays just use any of the GPI input spins that are available when you use the Wi-Fi so Define all of them as outputs and connect the input one two three four something like that to the any GPI open you like so thanks for the video guys hopefully you like it if you have any doubts you can comment down below I will try to answer them as soon as possible so I will see you all in the next one
Info
Channel: INOVATRIX
Views: 15,356
Rating: undefined out of 5
Keywords: #creative, #hobby, #inovation
Id: 5v3hguC41Kk
Channel Id: undefined
Length: 5min 59sec (359 seconds)
Published: Mon Aug 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.