Build a Weather Display with ESP32 and OpenWeatherMap API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up everyone in today's project I'm going to show you how to use another API recently we have used the joke API to get a single choke and display it using this OLED display in this project we're going to use another one and it is called the open weather map API which allows you to get your current weather State and there are so many services that you can pick up like the road risk API today we will focus on the first one that Returns the current weather data and we are going to display it using this LCD display of course you're going to need an esp32 microcontroller that has a Wi-Fi capability to send the request we need to connect our esp32 microcontroller to the internet through the router using nsid and password then we can send the HTTP requests using URL also you have to pass in a few information with this URL like your location then we'll get a Json format that contains the information about the weather state from the open weather map API anyways let's go back to the website by the way you can download the project files from the link under the video description by going to code and download it as a zip file you will find the circuit schematic as well as the sketch that is responsible for sending this request but first of all let's understand how this API Works let's open up the documentation as you can see we have the URL that we have talked about and you will need to add few parameters like the latitude and the longitude which is your location credentials to get these two values we can open up Google Maps and select the location that we want like India when you right click with the mouse we have these two values which are the latitude and the longitude I'm gonna copy them and let's open up a text editor and the second value is the longitude that we're going to use some apis require some sort of key that we need to put in this link so that we can use this service but don't worry it is free you only have to login using any mail and password then let's select my API keys and here it is let's copy it and paste it right here so that we can use it in our code but before that I want to test the API using a web browser like Microsoft Edge Let's Get Back to the documentation and copy the URL using Ctrl C and open up a new tab as I said we have to provide it with the API key next we have the latitude which is this value make sure to replace it with this parameter and finally the longitude now if we enter this URL and there you go we have a Json format that contains few information about the weather in India like the description so we have few clouds there are other measurements like the temperature as well as the humidity and the pressure now that we know how this API Works let's check out the circuit schematic diagram as I said I'm going to use the LCD display that comes with the i2c module we're going to use it to display the information that we want like the description of the weather as well as the temperature and the humidity first you have to connect the gnd to the gnd and the VCC to the 5 volt pin to power up the module then we have two more pins the SDA gets connected to the SDA of the board and it is the gcpo PIN number 21 the scl goes to the scn like this and if you don't know how to use this display I'm going to add a link under the video description that shows you how to use it in depth I've already connected the pens using female female jumper wires and let's open up the sketch on top we have the libraries that we need like the Wi-Fi Library the HTTP client to send the request these two are built in you don't have to install them and the last two libraries are not built in you have to go to the library manager and search for the Arduino Json Library which allows us to extract the information that we need from the Json format just write the name Arduino Json like that and here it is we've already installed it in our previous video and the second library is liquid Crystal i2c make sure to search for the same name Equity Crystal i2c and it is this one by Frank you could also use the OLED display which allows you to print the information that you need for me I've created this object which is the LCD that takes in three parameters the first one is the address of the i2c module this could be 0x3f or 0x27 if the first one doesn't work make sure to change it to the second address then we have the size I have 16 columns and two rows next I'm going to put the Sid and the password of the router then we have the URL that we have just copied I decided to separate the other parameters so that you can change them very easily like the API key I'm gonna copy my own and finally we have the location credentials I can use these two values is the location of India and that's pretty much it the rest of the code is connecting the esp32 microcontroller to the network using the Sid and password then we have the HTTP client object to send the request using the URL and the parameters that we have declared on top like the API key next we use http.get to start the connection between the esp32 microcontroller which is the client and the open weather map API which is the server side this method returns a code if it's a number that is greater than zero that means everything is fine and we can get the Json format using http.getstrength and to retrieve the description we use OBG and in these square brackets we have to provide it with the path we need to get the value of the weather Key which is an array of elements that's why we have to add 0 and finally we pass in the description the same thing applies for the other informations like the temperature as well as the humidity last but not least we use the LCD object to display the description as well as the temperature and the humidity in Celsius and in percent if something went wrong we are going to print the message can't get data and we are updating the weather State each 30 seconds if you want to get the updates each minute make sure to change this to 60. and that's pretty much it that's how we can use all kind of apis you simply have to know the URL as well as the parameters that it needs now we can select the board and the port of the USB cable which is com11 I have a node mcu32 export let's hit OK and upload and once it's done compiling we have to hold down the boot key so that we can start uploading the sketch until you go these are the weather information in India we have few clouds and the temperature is 38 Celsius the humidity is 16 percent I think that's all for this video if you have any questions or comments make sure to write it under the comment section down below also don't forget to subscribe to my channel that helps me a lot and I will see you in the next one
Info
Channel: Enjoy Mechatronics
Views: 9,928
Rating: undefined out of 5
Keywords: enjoy mechatronics, esp32 beginners, esp32, basic tutorial, internet of things, wifi, esp32 API, server, ESP32 Project, random nerd tutorials, esp8266, arduino poject, DIY, LCD, Display, Tutorial, IoT development, Weather API integration, IoT project tutorial, DIY electronics, esp32 iot, esp32s, ESP32 Weather Station, DIY Weather Display, Openweathermap, API, what is API, ESP32 weather display, OpenWeatherMap API, Weather forecasting with ESP32, Real-time weather data with ESP32
Id: AsNh1Z-iihw
Channel Id: undefined
Length: 7min 28sec (448 seconds)
Published: Fri Jun 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.