Random Nerd Tutorials

ESP8266 Weather Forecaster

This project was written by Emmanuel Odunlade and edited by Rui Santos.


In this post you’re going to build a weather forecaster with an ESP8266.

I hate being out on a rainy day without an umbrella and I’m pretty sure it’s the same for everyone else.

Often, the weather widget on our smartphones displays the weather forecast but when you’re in a hurry you forget to pay attention to it.

So, it would be nice to have a device hanging at the back of the door which reminds you to leave your house with an umbrella on a day where it might rain. This device tells you the weather forecast with a change in the LED color. This device wouldn’t have an alarm neither a screen, just a few LEDs that would fit naturally into your environment.

Parts required

Here’s a complete list of the components you need for this project (click the links below to find the best price at Maker Advisor):

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Open Weather Map

This project is based on the Open Weather Map API, so it’s necessary to sign up on their platform and obtain an API key before we get down to putting together the schematics and writing the code.

OpenWeatherMap’s free plan provides everything you need for thins example. To use the API you need an API key, known as the APIID. To get an APIID:

  1. Open a browser and go to OpenWeatherMap
  2. Press the Sign up button and create a free account
  3. Once your account is created, you’ll be presented with a dashboard that contains several tabs (see figure below)
  4. Select the API Keys tab and copy your unique Key

This is a unique key you need to pull information from the site. Copy and paste this key somewhere, you’ll need it in a moment.

To pull information on weather in your chosen location, enter the following URL with the sections in curly brackets replaced with your chosen location information and your unique API key:

http://api.openweathermap.org/data/2.5/forecast?q={your city},{your country code}&APPID={your API Key}&mode=json&units=metric&cnt=2

Replace {your city} with the city you want data for, {your country code} with the country code for that city, and {your API key} with your unique API key we found previously. For example, our API URL for the town of Porto in Portugal, after replacing with the details, would be:


Note: more information on using the API to get weather information is available here.

Copy your URL into your browser and it should give you a bunch of information that corresponds to your local weather forecast information.

Keep your unique API key safe and we can then move to the code section.

Installing the ArduinoJson library

For this project you need to install the ArduinoJson library in your Arduino IDE that allows you to Decode and Encode JSON with Arduino or ESP8266. Follow these next steps:

  1. Click here to download the ArduinoJson. You should have a .zip folder in your Downloads folder
  2. Unzip the .zip folder and you should get ArduinoJson-master folder
  3. Rename your folder from ArduinoJson-master to ArduinoJson
  4. Move the ArduinoJson folder to your Arduino IDE installation libraries folder
  5. Finally, re-open your Arduino IDE

Uploading code

Having the ESP8266 add-on for the Arduino IDE installed (how to Install the ESP8266 Board in Arduino IDE), go to Tools and select “NodeMCU (ESP-12E Module)”.

Copy the following code to your Arduino IDE and upload it to your ESP8266 board.

Go through the code to add your SSID, password, city, country code and Open Weather Map API key.


Wire your circuit accordingly to the schematic below:


The next figure describes what each LED indicates: (D2) Rain, (D3) Clear sky, (D4) Snow and (D5) Hail:

Here’s a photo of the final circuit:

Wrapping up

Nowadays, the goal of computing is to create a natural user interface between man and computers. We are looking to things like AR (Augmented Reality) to make that reality, but the truth is we are all getting tired of constantly looking at our phones and PCs for the tiniest piece of information.

I think having this project hanged somewhere around the house where you can easily know the weather on your way out is extremely useful.

To take this project further, I may throw in a 3D printed enclosure with a battery back up to make this look more neat. I will certainly share with you when that is done.

Thanks for reading!

You might also like reading our Home Automation using ESP8266 eBook.

MicroPython Programming with ESP32/ESP8266 eBook

Learn how to program the ESP boards with MicroPython, including projects, tips, and tricks! The registrations are open for a limited time, so SIGN UP NOW »

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our course even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Registrations are open for "MicroPython Programming with ESP32 and ESP8266" eBook