ESP32 Tutorial 43 - IoT Internet Weather Station | SunFounder's ESP32 IoT Learning kit

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hi, welcome to internet of thing tutorials from  Robojax in this video we're going to use esp32 and   esp32 camera extension board from SunFounder that  comes also with a battery and built a real-time   weather station uh to display for example time  the sky whether it's cloudy mist or rainy or   whatever it is and temperature and humidity  on the LCD and we are going to learn how to   use this 204 with 20 characters and four line  and that today's minimum and maximum as esp32   starter kit from SunFounder this is the best  esp32 learning kit from SunFounder it has this   esp32 microcontroller which has built-in Wi-Fi  and Bluetooth this board can do everything Arduino   Uno can do or many other Arduinos can do plus  extra more features because we have Wi-Fi and   Bluetooth the possibilities are endless you can  get connected to the cloud or do the control or   read information or values via your mobile device  or your desktop or over the cloud from a far location it comes with a camera extension  kit where you can stream the video over   Wi-Fi either through the cloud or to your  network and also it comes with micro SD card   with where you can save images on the micro  SD card or you can write from the device any   information log the information on the device  and read it back you can power the board using   this included 18650 lithium battery and it has  built-in charger where you can connect micro USB   and charge the battery the kit comes with 320  pieces of component that you can learn tons of projects when you need to have the weather  there is an open Weather open weather map is   an option that is available on the internet and  we are going to program this esp32 first we are   going to open an account with them and then  they will provide us an API kit application   programmable interface and we are going to  program this esp32 with extension board and   this will connect over Wi-Fi as you can see  we are not connected and this information is   updated every 10 seconds and you can change  the time and you will select your city and   your country esp32 sends request and we will  get information such as uh uh temperature   humidity and the uh sky and also we get the  time from the international time server so we   are getting all of this together to have  a weather station and display it on this LCB this is the open Weather website you can  come here and open an account and uh after   opening the account it will provide you an API  application programmable interface and you can   pull data with our with our esp32 and we will  parse that data and display it on the screen at   the end I'm going to provide you the code once you  learn the basic one then you will be able to add   the minimum and maximum uh so this can display  only four characters here I set it to display   four characters so everything will fit with a two  digit with a double digit and single digit decimal places come to this page docs.SunFounder.com  then click on esp32 start starter kit   main on the left side click on  Arduino user and scroll down to 8.1 and here real time weather from open weather  map and this is an iot or Internet of thing   project that our device will be connected we  reading the weather from open Weather using   esp32 and this Ling it on a LCD screen we will  be using esp32 board esp32 extension uh board   jumper wires and LCD screen uh we need to open an  account in open Weather which I'm going to show   you next here is some steps there is a wiring  at the bottom we have the codes which I'm going   to show you step by step and also show you the  wiring here is some explanation for the code as well now let's click on open Weather  go sign in and not registered create an account now they will send you an email so you have to  check your email and confirm click on API Keys you   can there is a key available for you and you can  uh create a new key new key or name it if you want weather and here so we need to have this key now let me show you the wiring we are  getting this male to female one side is   female the other side is male connector  and when we are connecting it first first first let me connect this first let me  connect these four wires here I connect   them like this and if I turn it around it  looks similar to this color the bottom is   orange as you can see here then yellow and  then red and the top one this is like black   and white and we have brown like that  now I'm turning this so and from here   the top one the Brown goes to ground to  the ground and then the red goes to 5 vol so this portion is done  and then yellow goes to 21 and orange goes to pin 22 and 22 between 21 and 22  there is two there are two holes left so the wiring is now completed I'm opening Arduino IDE let's open our project by clicking on file  open on the left side click on downloads then   esp32 start our kit main on the right side double  click to open it double click on C double click   on codes and scroll down to iot open weather  and this is number one select it and click open for including this line is for  uh LCD screen this is to initialize   the Wi-Fi and this is for HTTP client and this   is for Arduino Json when we receive the  information here is the SS ID for our uh Wi-Fi enter your SS ID and enter the password and this is your API so  paste the API I'm going to change   it and I do not care so paste the API  we need to enter the city and let's   copy this and go and find the city  that we are working on so let's say so here Toronto Canada and there  is a geographic geolocation and   here is a coordinate but we have  Toronto and then the country is CA and country code is CA 10 second every 10  second we will have a call and this is the   variable that is holding the call number and this  is string Json buffer when we read the information   from the uh that server will come to this and this  is sitting number of column and row for the LCD   and here from the library for the LCD we create  an object called L LCD this is the address for the   LCD and this column is coming here this is as if  I type 16 and two and this is the ntp server that   the ntp server is for international time it goes  to this URL or and GMT offset 0 daylight offset   zero if you want to change it like daylight saving  time or whatever you initializing the Wi-Fi with   ISS ID and password and it's printing this text  when it gets connected and this is while Wi-Fi   status is not equal to WL connect if it's not that  then we delay and we until it's connected we will   continuously print this dot on the screen and this  will create a new line and it will print this on   the screen as connected with the IP address  and we will see the IP address with the text   and and timer is set to 10 seconds this is also  a text this is initial Iz in the screen this is   turning on the uh back light inside the loop we  get the current time that uh esp32 has started   running this is the time that esp32 starts and at  the moment it's number of millisecond in 1 second   it will be 1,000 and in 10 second this number will  be 10,000 and we are subtracting it from the last   time value which is at the top last time and if it  is greater than time delay then we get connected   to the Wi-Fi if the Wi-Fi is connected and then  it goes to the server path to the server plus the   city plus the country code unit metric and it will  append it append the weather API key at the end so   this one line is the call line to the server uh  so this will create a variable called server path   of type string and here we use HTTP get request  and we pass this server pth as a C string and   the request the information that comes will be a  Json buffer here and we print the Json buffer on   the screen to see how it looks like and then from  Json uh buffer this value we use json. parse we   are parsing it we are extracting it and putting  it in a format that we want uh in in a variable   called my object of type Json variable your V now  we can do a lot with this and here Json type if my   object is equal undefined then it will print the  error because if it cannot find it and there are   extra other values like pressure temperature  humidity this is for serial Monitor and here   this is getting time my object remember this my  object is from Json from server and this is GMT   set second stores in this variable and then we  configure the time pass this value and Delight   off and from ntp server so this will configure the  time and this will get a print local time and uh   this will be stored in a variable called time and  we clear the screen from the previous value LCD   do clear this is setting the cursor at character  0 line 0 and after that it prints this time here   with a space and it will print the weather main  weather value so this is main object we have one   array element zero and there is inside another  array me here I've created a URL based on this   information and I've replaced the city comma  country code with Toronto to and CA and then   I this is unit metric and then app ID the open  Weather API key when you put it all together it's   something like this let screen and enter here  it says we got City not found so toon two has spelling and I fixed it now press enter here this  is information that uh when our program runs at   request so this will come back let me Zoom you  see it has a property called latitude longitude   and we get the weather ID is it something and then  main Cloud description overcast icon and then base   station so these are the value temperature feels  like this is all cius visibility wind cloud in   the mean we could get the temperature and feels  like minimum maximum pressure and humidity at the   moment you are getting temperature and humidity  and displaying it from the main and then from   this uh weather we are getting mean and here  we have picked here my object weather the Zer   me if we open at a Json let's see whether zero me  where it is this is the Json that I've requested   that I've sent and here this is the main Json  and then we go WEA and then mean so WEA zero   zero is because we have this square bracket and  this is an array and the this item is item zero   and we could have more so this is zero and then  main that's why weather and then zero and then Main and we go to the main Json  we go to the Json and select   Main and then inside main we select the  temperature and the same with mean and humidity and as you can see the mean doesn't have  this square bracket so mean temperature from mean   we can get this and and Main humidity will give  us that this humidity and we are getting the value   then we go to line zero character one and then  we put T and then main temperature so this is   referring to the temperature and this will print  two 2 three the uh degree symbol and then C and   then after that humidity and we get a humidity  with percent now we here we said if the Wi-Fi   is connected do all this else it says Wi-Fi is  disconnected and then remember the current time in   the variable called last time so we can calculate  the time and based on that we know every 10 second   we do something and the print local time is called  this is a function at the bottom of this code here   and here if we print this value this was already  there I just uncommented and we can get all this   information from here as uh uh with a b c d a  b d day year hour M so minute and second here   let me just stop this and it will be printed like  this so the first one is the day the a let me go here this one so a is Friday and this B is  the month December and this D is the day 29   and then year hour and then we have colon 58 and  then colon minute so we get all this information   and here print local time we are using get local  time from the time info that we created at the   top and if the time is not true if does not exist  then we print this error and here we are creating   a character array called time hour with three  elements and for hour we have three elements   and we are getting the time info from here with  h I've shown you that H is our and we are getting   the hour here and then another array time minute  of character which with three characters so this   has three character for the hour and then for  minute also we have three characters and this   this line is converting uh string format and we  are getting the time hour this uh hour and we are   getting the information from here storing it in  this and the same way we are using uh uh string   format for the time we're getting minute and  in this line we are creating time of a string   using string we are get getting the hour and  converting it to a string so that will be our hour and and then we put column and then  string we are getting the minute so   we are showing just hour and minute  and this is printing the same time   on the screen with uh and and it  Returns the time so this will go back now let's see how we can select the esp32  board we can click here under the select board   and type here esp32 D as soon as you type Dev you  will see Dev board you can select it and click   okay so the board have been selected now we have  to select the port the other way to select the   board is Click On Tools board esp32 and select  the esp32 dev module now we have to select the   port if I click here it shows two port and I don't  know which one belongs to my device sometimes you   will see you will not see the number properly  so the best way to be sure the right click on   the start menu go to the device manager and you  will see here the ports if I click on this Arrow   it will show me the ports and is USB serial  ch340 one the other is USB serial device and   here now it's connected if I disconnect this one  of them disappear the one that disappeared is my board so six stays and it disappeared if I connect it so it is my comport ch340 now it is my  comport and I can select it or I can click   on tool port and here you will see it you can  select whichever you want ours is comp from it now   we have successfully selected the board and the  port and this is very important it must be done first now let's click to upload the code so we got connected the IP address  is there so it needs 10 seconds before   we refresh the screen and and as  you can see it shows the time at   the moment exactly at 8:00 it says M  and temperature 6.26 de C humidity is 99% I was playing with the  code here to check the offset time this line I've added this line  and this is printing that code so to   see my time zone in terms of offset I  can just upload it and it will not be printed again new upload 10 seconds we  have to wait and that offset should not be printed so this is the actual time I've changed this 16 to 20 and the number  of rows to four and inside the code I've done   some modifications so I will I was able to  display it in this line we are getting the   temperature and I've converted using this  is uh the temperature and I've used json.   stringy so we convert it to string and it's now  uh a variable called temp string temp value of   type string and here I used temperature value  this variable and I use substring I said get   from zero up to four characters so that's  why we are removing one decimal point and   the same way I used uh the temperature minimum  here from the main uh Json and convert it to   string and then from 0 to four and the same  way for the maximum as well I use the same method and here is a demonstration we are  reading the time and uh whether the sky   is clear and the temperature is 22° this  is Dubai time and minimum temperature is   19.1 and maximum is 22.9 and humidity  is 73% and I'm not connected to the   USB or anything it's just powered up  with uh the provided lithium battery excellent
Info
Channel: Robojax
Views: 1,049
Rating: undefined out of 5
Keywords: robojax, sun, founder, sunfounder, course, tutorial, kit, learn, learning, step by step, esp32, arduino, iot, wifi, ntp, openWeather, map, humidity, temperature, min, max, display, LCD, lcd1602, LCD2004, SSID
Id: B73KTaBaqhs
Channel Id: undefined
Length: 25min 48sec (1548 seconds)
Published: Sat Dec 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.