Live 1057

Free Internet Radio Stations
Arduino ESP8266 Project: WiFi Weather display using a Wemos D1 board and operweathermap.org website

Arduino ESP8266 Project: WiFi Weather display using a Wemos D1 board and operweathermap.org website


Dear friends welcome to another video! This
is Nick from educ8s.tv and today we are going to build this WiFi weather display, which
displays weather data from the openweathermap website. Without any further delay, let’s
get started! A few weeks ago I published a video about
the impressive WeMOS D1 board which is an ESP8266 based board which resembles the Arduino
Uno. Today we are going to build our first project with it. A weather display, using
this old LCD display shield I was using with Arduino Uno a long time ago. As you can see,
the display works fine with the WeMOS D1 board! The project, connects to my WiFi network,
and then it downloads the weather data for my location from the openweathermap website,
and prints some of data in the display! It downloads new data for my location every 10
minutes. It is nice project to start with the ESP8266 chip. Let’s see how to build
it. The parts needed in order to build this project
are these: • A WeMOS D1 board
• A 16X2 LCD display shield That’s all. We only need two parts to build
this project. The cost of the project is very low. It’s $10! You can find links for both
parts in the description of the video. It’s really impressive that we can now build projects
with WiFi capabilities very easily and with such a low cost.
All we have to do is to connect the parts together like this and load the code I provide.
After a few seconds, the project will connect to the WiFi network and it will get the weather
data from the openweathermap.org website. So, you can build this project in less than
a minute. Great! Let’s now see the code of this project, where the magic happens!
The code of the project is really simple for a project like 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. We also need the ArduinoJson library which
can be downloaded from this website. You can find the link for this library in the description
of the video. This library is really a gem. The developer of this library Benoit Blanchon
has put a huge amount of time and effort into developing this open source library. I happily
donated a small amount of money to him, because his library makes our life so much easier.
I think that we have to help the developers who help the community move forward.
Here’s why we need the ArduinoJson library. When we request weather data from the openweathermap.org
website, it returns back the data in Json format. Json is a new open data format. The
ArduinoJson library makes it really easy to extract the data that we need from the reply
of the server and save them in our own variables. Let’s now take a look at the code.
At first we have to set the SSID and the password of our WiFi network. Next we have to enter
the free APIKEY from operweathermap.org website. In order to create your own API key you have
to sign up in the website. Getting current weather data and forecast is free but the
website offers more options if you are willing to pay some money. Next we have to find the
id of our location. Find your location and copy the ID which can be found in the URL
of your location. Then enter your city’s id in the CityID variable. Now we are ready
to move on. At first we connect to the WiFi Network. Then
we request weather data from the server. We get a reply with the weather data in JSON
format. Before sending the data to the JSON library I manually delete some characters
that were causing me problems. Then the JSON library takes over and we can easily save
the data that we need in variables. We have to take a look at the structure of the JSON
data that the openweathermap website replies to see how to get the data we are interested
in. After we have saved the data in variables, all we have to do, is to display them in the
screen and wait for 10 minutes before requesting new data from the server. That’s all. As
always you can find the code of the project in a link in the description of the video.
As demonstrated by this project it is now extremely easy and very inexpensive to build
projects that can connect to the internet. With the use of the available hardware we
can build internet connected devices in minutes! With the help of the available libraries,
we can program our internet connected devices in a matter of hours. It’s amazing what
a maker can achieve nowadays! I will work more on this project of course, to add more
functionality and a big color tft display. Stay tuned! I would love to know your thoughts
on this projects. Do you find it useful, and how do you plan to improve it? Please post
your comments or ideas in the comments section below. If this is your first time here, I would love
to have you subscribed. In this channel I post videos about DIY projects every Saturday.
I love making things and I believe that anyone can make things, anyone can become a maker.
That’s why I created this channel, in order to share my knowledge with the community and
learn from the community. I hope you will join us. Until next Saturday, Watch, Learn,
Build! [ Translating these subtitles? Add your name
here! ]

33 comments on “Arduino ESP8266 Project: WiFi Weather display using a Wemos D1 board and operweathermap.org website

  1. Hi I would like to use a small chip with temp & hum sensor, but need to shrink the size a coin size, also would like to send the captured data to a server for some data analysis

  2. Hi, great video. The keypad shield you suggest in the parts list looks a little different (DFRobot shield). Do you know if the keys in this keypad shield work with wemos? The keys connect to A0 that only allows 3.3V. Hope you can help me on this one. Thanks.

  3. hi . using dht11 i save data into a sd card and using Bluetooth module i want to sent the data to mobile . but i am facing some problem in sending data ?? do you pls help me for sending sd card data to mobile phone through Bluetooth module ??

  4. i bought this one from ebay http://www.ebay.com/itm/162425864880?ssPageName=STRK:MESELX:IT&_trksid=p3984.m1555.l2649
    this one is based on ESP-12E in the tutorial your board based on ESP-12F is there any difference between this to module?

  5. I managed to print correctly to serial monitor and read data but, just blank screen on LCD display. I'm using D1 R2. I tried adding : #define D9 2 GPIO2 // maps to Ardiuno D9 but no display. Can anyone suggest something please?

  6. I do you know how to easily make this board send an email or text message when it detects motion? please help

  7. wouldn't it be better to build this in a normal lcd screen 12*2 so we can see what cables are you connecting and what changes you will make?? apart from learning more we would be able to mount the screen somewhere…

  8. Hello. First of all, thank you for this tutorial. Secondly, I want to make an irrigation system and I will use this. My question is, however, what data do I need from the API to tell me the forecast of the current day? For example, I want to know if it will rain today. Or perhaps the chance of rain in the current day? Thank you very much.

  9. // This is for the people who have the Original WeMos D1 and want to learn with it
    // Set Arduino IDE to WeMos D1 (Retired)
    // This is tested and working on the WeMos D1 R1
    // Temperature set to Fahrenheit

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

    const char* ssid = "-—-"; // SSID of local network (Name of Your WiFi Network)
    const char* password = "-——"; // Password on network
    String APIKEY = "-————————–";
    String CityID = "-——"; //HomeTown, State

    WiFiClient client;
    char servername[]="api.openweathermap.org"; // remote server we will connect to
    String result;

    int counter = 60;

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

    LiquidCrystal lcd(D8,D9,D4,D5,D6,D7);

    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);
    }

    void loop() {
    if(counter == 60) //Get new data every 10 minutes
    {
    counter = 0;
    displayGettingData();
    delay(1000);
    getWeatherData();
    }else
    {
    counter++;
    displayWeather(weatherLocation,weatherDescription);
    delay(5000);
    displayConditions(Temperature,Humidity,Pressure);
    delay(5000);
    }
    }

    void getWeatherData() //client function to send/receive GET request data.
    {
    if (client.connect(servername, 80)) { //starts client connection, checks for connection
    client.println("GET /data/2.5/weather?id="+CityID+"&units=metric&APPID="+APIKEY);
    client.println("Host: api.openweathermap.org");
    client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Connection: close");
    client.println();
    }
    else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
    }

    while(client.connected() && !client.available()) delay(1); //waits for data
    while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    result = result+c;
    }

    client.stop(); //stop client
    result.replace('[', ' ');
    result.replace(']', ' ');
    Serial.println(result);

    char jsonArray [result.length()+1];
    result.toCharArray(jsonArray,sizeof(jsonArray));
    jsonArray[result.length() + 1] = '';

    StaticJsonBuffer<1024> json_buf;
    JsonObject &root = json_buf.parseObject(jsonArray);
    if (!root.success())
    {
    Serial.println("parseObject() failed");
    }

    String location = root["name"];
    String country = root["sys"]["country"];
    float temperature = root["main"]["temp"];
    float humidity = root["main"]["humidity"];
    String weather = root["weather"]["main"];
    String description = root["weather"]["description"];
    float pressure = root["main"]["pressure"];

    weatherDescription = description;
    weatherLocation = location;
    Country = country;
    Temperature = temperature;
    Humidity = humidity;
    Pressure = pressure;

    }

    void displayWeather(String location,String description)

    {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(location);
    lcd.print(", ");
    lcd.print(Country);
    lcd.setCursor(0,1);
    lcd.print(description);
    }

    void displayConditions(float Temperature,float Humidity, float Pressure)
    {
    lcd.clear();
    lcd.print("T:");
    lcd.print(((Temperature * 9.) / 5.) +32.,1);
    lcd.print((char)223);
    lcd.print("F ");

    //Printing Humidity
    lcd.print(" H:");
    lcd.print(Humidity,0);
    lcd.print(" %");

    //Printing Pressure
    lcd.setCursor(0,1);
    lcd.print("P: ");
    lcd.print(Pressure,1);
    lcd.print(" hPa");

    }

    void displayGettingData()
    {
    lcd.clear();
    lcd.print("Getting data");
    }

  10. Hello.
    I thank you for the good work you do.
    Everything is clear and well laid out.
    I have changed your Wemos wifi weatherstation sketch before use
    With I2c LCD.
    It works very well here.
    Best regards Bert Heideveld (71 Young).

    www.bertheideveld.eu

    ————————————————————————————————————————-

    // Version v1.02 Works with the Wemos D1 board R2 http://bit.ly/WEMOS_D1
    //
    //For I2c LCD. 17-07-2017
    //By Bert Heideveld.

    #include <ESP8266WiFi.h>
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    #include <ArduinoJson.h>

    LiquidCrystal_I2C lcd(0x27, 16, 2); //Lcd 16 karakters 2regels

    const char* ssid = "TELE2-2F202F_2.4G"; // SSID of local network
    const char* password = "D3D562A27DDD"; // Password on network
    String APIKEY = "f64669ed90065de8927a4398dfe9f08e";
    String CityID = "2759661"; //Arnhem, Nederland

    WiFiClient client;
    char servername[] = "api.openweathermap.org"; // remote server we will connect to
    String result;

    int counter = 60;
    int WiFiStrength = 0;

    String weatherDescription = "";
    String weatherLocation = "";
    String Country;
    float Temperature;
    float Humidity;
    float Pressure;
    WiFiServer server(80);

    void setup() {
    Serial.begin(115200);
    lcd.begin();
    lcd.backlight();

    int cursorPosition = 0;
    lcd.setCursor(0, 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(" Wifi Connected!");
    Serial.println("Wifi Connected");
    delay(1000);

    }

    void loop() {
    if (counter == 60) //Get new data every 10 minutes
    {
    counter = 0;
    displayGettingData();
    delay(1000);
    getWeatherData();
    } else
    {
    counter++;
    displayWeather(weatherLocation, weatherDescription);
    delay(5000);
    displayConditions(Temperature, Humidity, Pressure);
    delay(5000);
    }
    }

    void getWeatherData() //client function to send/receive GET request data.
    {
    if (client.connect(servername, 80)) { //starts client connection, checks for connection
    client.println("GET /data/2.5/weather?id=" + CityID + "&units=metric&APPID=" + APIKEY);

    client.println("Host: api.openweathermap.org");
    client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Connection: close");
    client.println();
    }
    else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
    }

    while (client.connected() && !client.available()) delay(1); //waits for data
    while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    result = result + c;
    }

    client.stop(); //stop client
    result.replace('[', ' ');
    result.replace(']', ' ');
    //Serial.println(result);

    char jsonArray [result.length() + 1];
    result.toCharArray(jsonArray, sizeof(jsonArray));
    jsonArray[result.length() + 1] = '';

    StaticJsonBuffer<1024> json_buf;
    JsonObject &root = json_buf.parseObject(jsonArray);
    if (!root.success())
    {
    Serial.println("parseObject() failed");
    }

    String location = root["name"];
    String country = root["sys"]["country"];
    float temperature = root["main"]["temp"];
    float humidity = root["main"]["humidity"];
    String weather = root["weather"]["main"];
    String description = root["weather"]["description"];
    float pressure = root["main"]["pressure"];

    weatherDescription = description;
    weatherLocation = location;
    Country = country;
    Temperature = temperature;
    Humidity = humidity;
    Pressure = pressure;

    }
    void displayWeather(String location, String description)
    {
    Serial.print(location);
    Serial.print(" , ");
    Serial.print(Country);
    Serial.print(" , ");
    Serial.println(description);

    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print(location);
    lcd.print(", ");
    lcd.print(Country);
    lcd.setCursor(0, 1);
    lcd.print(description);
    }

    void displayConditions(float Temperature, float Humidity, float Pressure)
    {
    Serial.println("");
    Serial.print("T:");
    Serial.print(Temperature, 1);
    Serial.print("Gr/C ");
    Serial.print(" , ");

    //Printing Humidity
    Serial.print(" H:");
    Serial.print(Humidity, 0);
    Serial.println(" %");
    Serial.println("");

    //Printing Pressure

    Serial.print("P: ");
    Serial.print(Pressure, 1);
    Serial.println(" hPa");
    Serial.println("");
    //————————
    lcd.clear();
    lcd.print("T:");
    lcd.print(Temperature, 1);
    lcd.print((char)223);
    lcd.print("C ");

    //Printing Humidity
    lcd.print(" H:");
    lcd.print(Humidity, 0);
    lcd.print(" %");

    //Printing Pressure
    lcd.setCursor(0, 1);
    lcd.print("P: ");
    lcd.print(Pressure, 1);
    lcd.print(" hPa");

    }

    void displayGettingData()
    {
    lcd.clear();
    lcd.print("Getting data");

    }

  11. After a few hours, I will not get more data. Everything stands at zero then.
    Also after a reset of the Wemos.
    What can I do to see if the data is yes or no?
    It stops by "getting data" and downt start again. sam tiems after reset the wemos its oke. Bad after 20 minutes its over again
    Thank you. Sorry poor english

  12. Hello.
    Sometimes Wemos does not get data.
    Often I have to reset.
    But often the data does not come.
    This happens a few times a day.
    The data will never return spontaneously but only after a reset of the Wemos.
    Do you have any idea what to do?
    I assume that the data is always present at api.openweathermap.org
    Or is not that true?

    Greetings Bert. (The Netherlands).

    www.bertheideveld.eu

  13. Hi Nick,
    Thank you for sharing this project. Just wondering if I want to display sunrise and sunset data to LCD, how can I do that?

  14. Hi friends!
    I have a code for "NodeMCU Weather Station" but the Time is incorrect; instead of showing, for example, 03:00h, is showing 07:00h (+4) in Brazil. It should be (-4) Hours
    Is it possible to change this in code? If you could help me, I would be very grateful!

  15. Hi Nick,

    Thanks for the code! Although i do have to point out something so that others may not repeat the same mistakes as i did. For anyone using the older WEMOS D1 board you have need to comment out the pin definitions in the code like this:

    //#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 14 // GPIO14 maps to Ardiuno D5
    //#define D6 12 // GPIO12 maps to Ardiuno D6
    //#define D7 13 // GPIO13 maps to Ardiuno D7
    //#define D8 0 // GPIO0 maps to Ardiuno D8
    //#define D9 2 // GPIO2 maps to Ardiuno D9
    //#define D10 15 // GPIO15 maps to Ardiuno D10

    Else you will not be getting any text displayed on the LCD.
    Additionally if your lcd is show showing any "boxes" i.e. just blanks, use a screwdriver and turn the potetiometer on the lcd clockwise until you see the text. Initially i thought my lcd shield was faulty but i tried it on my UNO running a sample code under "Example use of LiquidCrystal library" from https://www.dfrobot.com/wiki/index.php/Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009) which proves it was working fine.

    Good Luck and cheers!

  16. It looks like the lcd is connected to Arduino using white usb plug but i don’t see anywhere on the lcd description mentioning a usb plug can you verify for me how the lcd is hooked up,Thank You

  17. In case anyone needs to know which board they have (and you haven't Googled for "difference between D1 and D1R2"), the R2 board has a 4×2 array of holes roughly in the middle, they offer 3.3V, ground, Tx, Rx and SDA and SCL. Some boards have pins already there, but no pin is better, you can put male or female headers on, suit yourself.

  18. I found that the ArduinoJson assistant was very useful, it gives you the size of the buffer you will need and the parsing commands for the Openweathermap data:
    "https://arduinojson.org/assistant/" no quotes (I don't think links are allowed on YouTube, so if it gets taken out, then you'll just have to Google for it)

    Nick, it also shows why you had to remove the square brackets; the weather data is an array element. The basic data that you and I are using only has one location, but a bigger (more expensive?) query can return several array elements. The sample given with the assistant shows how to parse that sort of result, too.

  19. we dont need readymade shields, we want proper breadboard setup and connections, there is nothing to learn from this otherwise!! please keep that in mind for the next project video, people dont watch these for sheilds and branding other stuff!!

  20. I am trying to set this up, but use a local weather website which outputs .json files for my area. The problem I am having is the apikey. I am not sure how to find that for the website I wish to use. Any ideas?

  21. Niko kalispera.

    Exw analavei mia ptyxiaki ergasia stin opoia tha prepei na ftiaksw mia plaketa pou tha kanei to idio pragma me to video pou anevases. to provlima einai oti o kathigitis mou protine na parw tin arduino uno wifi rev2. ti prepei na allaksw ston kwdika gia na leitourgisei?

  22. Καλησπέρα, έχει ανατεθεί στην ομάδα μου παρόμοιο project με arduino uno και esp8266. Ξέρει κανένας πως θα συνδέσω το esp8266 με το το arduino και πως θα το συνδέσω μετά στο wifi μου?

Leave a Reply

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