ESP32 Weather Clock with TM1637 Display using Weather API

This is in continuation to my earlier post on ESP32 Digital Clock using TM1637. Here we will see on how to build ESP32 Weather Clock with TM1637 Display using Weather API. We will use weather API to get local temperature and display along with local time.

Parts Required for this Project

  1. ESP32 dev board ( in my example I am using ESP WROOM 32 MCU Module Version: 1.1 )
  2. TM1637 4 Digit 7-segment display module
  3. Some connecting wires.
  4. USB cable to upload the code

Schematic diagram

ESP32+TM1637 Schematic Diagram
TM1637 DisplayESP32
CLKAny digital pin (for example: GPIO 4)*
DIOAny digital pin (for example: GPIO 5)*
VCCVIN
GNDGND

Step by Step Process

Getting Your API Key

  1. Go to the Weather API website: weatherapi.com/
  2. Signup to create an account.
  3. After verifying your account, login into your account.
  4. On your dashboard at weatherapi.com/my/ , you will find the API Key.

Installing required libraries

For this project we will be using Wifi, TM1637 module,Httpclient and Arduino Json parser library.

First 2 i.e Wifi and TM1637 library I have covered in detail in my previous blog and if you followed my blog you may already have it installed. Following 2 library will be used for HttpClient and Arduino Json parser.

  1. HttpClient by Adrian McEwen
  2. Arduinojson by Benoit Blanchon

You can use any other similar library, but in that case you may need to tweak the code to update the method name from that library.

Program

You can also download the code from my Github repo from below link.

https://github.com/pintushaw/ESP32Samples

Actual Temperature display

Working Explanation

The heart of this project is the Wifi connection and Weather API. We first connect to local wifi using the initWifi() method. Then We initialize the time by getting it from ntp using initTime(). After this we call updateTemperature() which we get weather info from Weather API and parse to get temperature in Celsius and Fahrenheit.

The updateTemperatures() function makes a request to the WeatherAPI request URL. The request returns weather data. We print all data to the Serial Monitor.

After this we parse the response and extract only the temperature and store it in global variable.

While displaying the data, we are displaying time, celsius temperature and Fahrenheit temperature every 5 sec alternatingly.

For more detail step by step process and code walkthrough, watch my Youtube video below. It will give you more detail insight in to the project.

Errors and Debugging

There are chances that you may get error while compiling, publishing or after publishing the code. Some of the troubleshooting points are listed below:

  1. If you have used some other library than what I mentioned, then the method name and parameter may vary. Review that in case of compilation error.
  2. Try to double check on wiring. It is easy to connect to different pins by mistake.
  3. Sometime cheap TM1637 comes faulty. Check by replacing with new ones.
  4. Use 3.3v instead of 5v. ESP32 sometime behave differently when 5v logic level are used.
  5. Check wifi ssid and password. Especially if there are connection issue.
  6. Copy API Key correctly. Sometime spaces are included when copying.

Let me know how it goes for you and if you have any issues/errors.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.