ESP8266 Weather Display

Hey guys, welcome to today’ s tutorial, today we will be building an esp8266 based weather monitor/display using the Wemos D1 board and the 16×2 LCD keypad shield for Arduino.

 

A few weeks back, I published a tutorial about the impressive WeMOS D1 development board which is a development board based on the esp8266 but with the Arduino Uno form factor and today, we are going to build our first project with the board. The board is pin compatible with the Arduino Uno, although most add-ons that work with the Arduino do not work with it yet due to library issues. The board, however, has all the features and capabilities of the esp8266 module, especially the superb WiFi functionality and it can be programmed using the Arduino IDE.

This project is a good beginner project for anyone interested in learning about building IoT based project as this project will totally be based on the internet.

Using the Esp8266 wifi functionality on the Wemos D1, our setup will join a specified WiFi network to access the internet and pull weather data from open weather map and display on the LCD Every 10 minutes. Open weather map is an openly sourced weather reporting platform through which anyone can subscribe to either hourly, weekly or daily update on the weather in their particular location. The platform also provides APIs on top of which users can build their own applications that makes use of the large amount of data which open weather map asks.

 

Required Parts and Where to Buy

The following components/parts are required to build this project and they can each be bought through the link in front of each component.

  1. Wemos D1 Board: https://educ8s.tv/part/WemosD1
  2. Keypad Display: https://educ8s.tv/part/KeypadShield
  3. Xiaomi Powerbank: https://educ8s.tv/part/Powerbank

Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!

[adsense]

Schematics

The connections for this project is simple. The 16×2 LCD display comes as a shield so all we need to do is plug the shield on the Wemos Board, ensuring that it is well fixed.

Code

The code of this project is really simple if we compare the technicalities involved with the fact that it needs less than 150 lines of code. We use 2 familiar libraries in this project, the ESP8266WiFi library and the LiquidCrystal library for the display. In addition to these two libraries, we will also be using the ArduinoJson library which allows us to process JSON files on the Arduino.

While the LiquidCrystal library comes with the Arduino, the esp8266wifi library and the Arduino JSON library can either be downloaded via the Arduino library manager or via the link below.

LIBRARIES

ArduinoJSON Library: https://github.com/bblanchon/ArduinoJson

ESP8266WiFi: https://github.com/esp8266/Arduino

When we request weather data from the openweathermap.org website, the data is returned to our Arduino in JSON. The ArduinoJson library makes it really easy for us to extract the exact data we need from the JSON tree reply from the server and save them in our own variables. A flow chart that explains it better is shown below.

As soon as the data is received, its parsed and displayed on the 16×2 LCD shield.

To take a brief look at the code. we start out by including the needed libraries after which we map the pins of the WEMOS D1 to the pins of the Arduino UNO so it is easy for us to interface the LCD.

#include <ESP8266WiFi.h>
#include <LiquidCrystal.h>
#include <ArduinoJson.h>

#define D0 3 // GPIO3 maps to Ardiuno D0
#define D1 1 // GPIO1 maps to Ardiuno D1
#define D2 16 // GPIO16 maps to Ardiuno D2
#define D3 5 // GPIO5 maps to Ardiuno D3
#define D4 4 // GPIO4 maps to Ardiuno D4
#define D5 0 // GPIO14 maps to Ardiuno D5
#define D6 2 // GPIO12 maps to Ardiuno D6
#define D7 14 // GPIO13 maps to Ardiuno D7
#define D8 12 // GPIO0 maps to Ardiuno D8
#define D9 13 // GPIO2 maps to Ardiuno D9
#define D10 15 // GPIO15 maps to Ardiuno D10

With that done, we declare the SSID and password of the WiFi to which we want to connect to for internet access.

const char* ssid     = "yourSSIDgoesHere";      // SSID of local network
const char* password = "yourWiFiPasswordGoesHere";   // Password on network

Next, we need to 0btain the APIKEY from operweathermap.org website and enter it into our Arduino code. In order to create your own API key, you have to sign up on their website. The API key is used as a unique identifier to recognize each individual’s request to the open weather map server.
Getting current weather data and forecast is free but the website offers more options if you are willing to pay.

String APIKEY = "yourAPIKEYgoesHere";

Next, we have to find the id of our location on the open weather map website. Find your location, copy the ID and store in the CityID variable as shown below.

String CityID = "253394"; //Sparta, Greece

With that done, we create some of the other variables that will be used within our sketch.

int  counter = 60;

String weatherDescription ="";
String weatherLocation = "";
String Country;
float Temperature;
float Humidity;
float Pressure;

At the beginning of the void setup function, we initialize the serial monitor as it will be used for debugging we then initialize the LCD and instruct the system to connect to the access point defined initially. The result of the connection attempt is displayed on the screen.

void setup() {
  Serial.begin(115200);
  int cursorPosition=0;
  lcd.begin(16, 2);
  lcd.print("   Connecting");  
  Serial.println("Connecting");
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    lcd.setCursor(cursorPosition,2); 
    lcd.print(".");
    cursorPosition++;
  }
  lcd.clear();
  lcd.print("   Connected!");
  Serial.println("Connected");
  delay(1000);

}

The algorithm for the code content of the void loop function is simple, after every 10 mins, the device makes a request to open weather map server to get the current weather data after which the data is parsed with the Arduino JSON library and displayed on the LCD.

void setup() {
  Serial.begin(115200);
  int cursorPosition=0;
  lcd.begin(16, 2);
  lcd.print("   Connecting");  
  Serial.println("Connecting");
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    lcd.setCursor(cursorPosition,2); 
    lcd.print(".");
    cursorPosition++;
  }
  lcd.clear();
  lcd.print("   Connected!");
  Serial.println("Connected");
  delay(1000);

}

The complete code for this project which includes some of the other functions used can be downloaded from the link below.

——————–

CODE OF THE PROJECT
——————–

 

 

 

Connect the LCD to the Arduino, upload the code and power it up, after a few minutes, the device should connect to the internet and you should see the weather information displayed on the LCD as shown in the image below.

Weather Monitor in Action

That’s it for this tutorial guys thanks for reading and watching, don’t forget to subscribe so as to get informed as soon as new tutorials are published.

SUBSCRIBE ON YOUTUBE

——————–

Never miss a video: Subscribe to educ8s.tv