Connect ESP32 to WiFi - ESP32 Beginner's Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone and welcome back to my YouTube channel so in this part of the series which is the second part we are going to talk about the esp32 Wi-Fi capability so as I have mentioned in the previous video the esp32 comes with a couple of Wireless connectivity which are Wi-Fi and Bluetooth today I would use the Wi-Fi capability and will be able to control the LED from any device like the computer using this link and as you can see the LED turns on and we can turn it off of course in the next few videos we are going to improve this and create some buttons to control the devices like lamps or other appliances anyways before we get started make sure to smash that subscribe button and the notifications Bell so that you don't miss my next videos and let's jump right into it [Music] so first of all we have to understand how to use the Wi-Fi capability of the esp32 basically we have different modes the first one is called station mode in this mode the esp32 will act as a station so it gets connected to an existing Network like the router using its name and password so here the esp32 is like any other devices then you could control the esp32 from the mobile phone that is connected to the same Wi-Fi network so that's very important using its IP address so if you don't know about IP address don't worry the router will assign some kind of address to all of the devices including the esp32 in station mode so that these devices communicate with each other then we can use the IP address of the esp32 to control its built-in LED and the second mode is called access point in this mode the esp32 will act like a router so it's going to create Wi-Fi network and all of the devices gets connected to wet using its own SSID and password that we can set from the code and the same thing we can control the esp32 using nip address so all of the devices including the esp32 will have an IP address that we can use to control it even from another esp32 that operates in station mode and the third mode is basically a combination between the two we can use the esp32 in station mode and an access point mode but I'm not going to cover that we will simply talk about the station mode and the access point mode and to do that let's open up the Arduino IDE luckily the esp32 package comes with a few examples that we can use to get started with this feature Wi-Fi and to do that of course you have to watch the first video in which we have installed the esp32 package now we can select the esp32 board from tools board then we have esp32 make sure to select the one that you have for me it is called node MCU 32s then the port of the USB cable of course make sure that the esp32 is plugged in using the USB cable for me this is the port com6 and once you do that we can open up an example using file examples and all the way down we have Wi-Fi so this is a library that comes with the esp32 package under this drop menu we have different examples and let's start with the first one which is simple Wi-Fi server as I said in this sketch the esp32 operates in station mode Let's go down here as you can see we have two variables one that is called SSID and the other one is password here we have to provide it with the SSID and password of our router for me I have a Wi-Fi network which is called my network I'm gonna write the name and the password and once you do that the esp32 will create some kind of server that is listening to clients and a client is another device that is connected to the same router we can open up a browser from the mobile phone and write the esp32 IP address and if you do that you will see an HTML file or two links want to turn the LED on using digital right High and another one to turn it off using digital right glow for now you don't have to understand all of this but you need to put the SSID and password then let's change the pen so as I have mentioned in the previous video the built-in LED which is blue is connected to the pin number two and not 5. we have to change this to two same thing under here we are turning the LED on when we click on the first link to improve this code we can create a variable and we can call it led pen and if you don't know how to use variables I've talked about that in the first video basically we can declare it on top using int then we can give it the name EDD pen and assign the value to using equals to now if you want to change the LED pin to 5 you can change it from here and you don't have to go in all of these lines and change the value and that's one of the variables big advantage I'm going to put this line under here so it doesn't matter I only want to separate this part and our variable from here now we can upload this code and test it before that make sure to select the board and the port then we can hit upload which is this one for some esp32 boards you have to hold down the boot key in order to upload the code directly now we only need the IP address of the esp32 basically it gets printed on the serial monitor so if you don't know what is the serial monitor basically it's a tool that comes with the Arduino IDE you can open it up from tools then serial monitor and it is this window of course make sure to select the right baud rate which is used under the code using serial.begin make sure to select the right one don't worry I will create a video about the serial Monitor and how to use it now to get the IP address we have to reset the esp32 board using this reset push button and once you do that you will see that we have connecting to my network and there you go the esp32 gets connected and we have the IP address now we can copy it using Ctrl C and let's open up a browser so make sure to be connected to the same Wi-Fi network if you are using a mobile phone or a computer it doesn't matter then we can open up a browser like Google Chrome and type in the IP address or just paste it and once you do that you will see that we have two links the first one to turn the LED on and there you go it turns on and the other one to turn it off in the next tutorial I'm going to show you how to change this HTML file and create some buttons to turn the LEDs on and off for example if we want to change the text that is created under the HTML page you see down here that we have client.print to print the text which is Click at the first link to turn the LED on pin 2 in this case and let's change this to two so this will update the HTML page and let's upload it again and there you go it is changed to pin 2. we can turn the LED on and off using these two links now let's move on to the second mode which is access point mode actually there is no big differences we only have to set the Wi-Fi to a soft access point mode and let's open up the example sketch to understand that using file then examples and under Wi-Fi and it is this one Wi-Fi access point let's open it up luckily we have the LED pin is number two and as you can see we have the same parameters we have to pass in nsid and password but this time it's the Sid and password of the esp32 it will create its own Wi-Fi network that we can connect to using the Sid and password so let's write something like my esp32 and let's choose a password and the same thing we will see the IP address on the serial monitor and you will note that all of the lines of code that are under the loop function is the same the only difference is how we set up the esp32 under the setup function we have this wi-fi.soft access point that takes the Sid and password and it is called Soft because the esp32 doesn't have any kind of ethernet wired connection then we can get its IP address using Wi-Fi dot soft access point IP and here it gets printed under the serial monitor and once you set up the Sid and password we can upload the code and once it's done we have to connect to the same Wi-Fi network you will see that we have this one that is called my esp32 which is the Sid let's hit connect and write the same password and let's hit next and once you do that we have to type in the IP address of the esp32 we can open up the serial monitor from this button and let's hit reset and here's the new IP address let's copy it again and let's paste the link and there you go we have the two links the first one to turn the LED on and the second one to turn it off so I think that's pretty much it guys for this video I hope you like it if you have any question or comment make sure to write it under the comment section down below and I will see you in the next one
Info
Channel: Enjoy Mechatronics
Views: 82,568
Rating: undefined out of 5
Keywords: Arduino, tutorial, enjoy mechatronics, how to, electronic, microcontroller, programming, getting started, esp32 beginners, esp32, introduction, esp8266, beginner, learn, sketch, connected, basic tutorial, gpio, pin, internet of things, smart, wifi, howto, basics, arduino, sensor, wireless, lesson, course, espressif, chip, iot, esp32 tutorial, ESP32, esp32 introduction, esp32 arduino, arduino ide, first esp32 project, diy, how, to, beginners, guide, project, WiFi, control, ide, server, web, easy, automation, internet
Id: aH3sLEQI4_w
Channel Id: undefined
Length: 12min 13sec (733 seconds)
Published: Thu Oct 27 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.