Weather Station NODEmcu i2c HD44780
Do you want to know the current weather? This article will show you how to build a simple weather station with NODEmcu board and HD44780 i2c display. The board uses the ESP8266 chip in order to connect to the internet and we are going to program it using the Arduino IDE. The project gets weather data from the openweathermap.org website and displays some of the data on the display. The display is connected to Nodemcu via the i2c module, so connection is very simple. All we need is the address of module.
Connection:
NODEmcu to Arduino:
D1 to SCL
D2 to SDA
Vin to Vcc
GND to GND
Warning: The i2c module needs 5 volts for proper operation.
Files:
Installation of the ESP8266 board:
Copy link to Additional Board Manager URLs ( Arduino IDE File -> Preferences )
1 |
http://arduino.esp8266.com/stable/package_esp8266com_index.json |

Now, add NODEmcu board to Arduino IDE. Open Board Manager ( Arduino IDE ->Board: “……….” -> Board Menager )


Libraries:
OK, your board is already added. Now we need to add libraries needed in the program. Add Liquid crystal_i2c, Open Tools -> Manager Libraries and type LiquidCrystal_i2c in the search engine and find the library “LiquidCrystal_i2c by frank de Brabander”.

All you need is a JsonArduino library, Open Adruino IDE -> Sketch -> Include Library -> Add .ZIP Library …. And select file ArduinoJson-6.x.zip

Address Module i2c:
If you do not know the address of your module, upload the following code to the board and open Serial Monitor there will appear the address. Mine is 0x3F.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
// ---------------------------------------------------------------- // // Arduino I2C Scanner // Re-writed by Arbi Abdul Jabbaar // Using Arduino IDE 1.8.7 // Using GY-87 module for the target // Tested on 10 September 2019 // This sketch tests the standard 7-bit addresses // Devices with higher bit address might not be seen properly. // ---------------------------------------------------------------- // #include <Wire.h> //include Wire.h library void setup() { Wire.begin(); // Wire communication begin Serial.begin(9600); // The baudrate of Serial monitor is set in 9600 while (!Serial); // Waiting for Serial Monitor Serial.println("\nI2C Scanner"); } void loop() { byte error, address; //variable for error and I2C address int nDevices; Serial.println("Scanning..."); nDevices = 0; for (address = 1; address < 127; address++ ) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address < 16) Serial.print("0"); Serial.print(address, HEX); Serial.println(" !"); nDevices++; } else if (error == 4) { Serial.print("Unknown error at address 0x"); if (address < 16) Serial.print("0"); Serial.println(address, HEX); } } if (nDevices == 0) Serial.println("No I2C devices found\n"); else Serial.println("done\n"); delay(5000); // wait 5 seconds for the next I2C scan } |
Configure Weather Station:
Now open the sketch Weather_Station_i2c_NODEmcu.ino and go to the configure section.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// ---------------- CONFIGURE ------------------------------ // initialize the library LiquidCrystal_I2C lcd(ADDRESS MODULE,2,16); const char* ssid = "NAME NETWORK"; // SSID of Wifi network const char* password = "PASSWORD NETWORK"; // Password on network String APIKEY = "APIKEY"; String CityID = "NUMBER CITY"; // London, GB. 2643743 // ------------------ END ------------------------------------- |
Enter your address module i2c:
// initialize the library
LiquidCrystal_I2C lcd( address module i2c ,2,16);
Enter your network name:
const char* ssid = “NAME NETWORK”;
Enter your network password:
const char* password = “PASSWORD NETWORK”;
Now, enter www.openweathermap.org register on the site and go to the pricing tab and click FREE FREE “get API KEY and start”. Go to home.openweathermap.org and open the APIKEY and copy it.
Then search for your city and from the link copy number city to skech https://openweathermap.org/city/2643743 city number 2643743.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
/* * ForbiddenBit.com * * http://arduino.esp8266.com/stable/package_esp8266com_index.json */ #include <ESP8266WiFi.h> #include <LiquidCrystal_I2C.h> #include <ArduinoJson.h> // ---------------- CONFIGURE ------------------------------ // initialize the library LiquidCrystal_I2C lcd(ADDRESS MODULE,2,16); const char* ssid = "NAME NETWORK"; // SSID of Wifi network const char* password = "PASSWORD NETWORK"; // Password on network String APIKEY = "APIKEY"; String CityID = "NUMBER CITY"; // London, GB. 2643743 // ------------------ END ------------------------------------- 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; void setup() { Serial.begin(115200); int cursorPosition=0; //display initialization lcd.init(); //turn on the backlight lcd.backlight(); 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] = '\0'; StaticJsonDocument<1024> doc; /* DeserializationError error = deserializeJson(doc, json); if (error) { Serial.print("deserializeJson() failed"); Serial.println(error.c_str()); return; } */ String location = doc["name"]; String country = doc["sys"]["country"]; float temperature = doc["main"]["temp"]; float humidity = doc["main"]["humidity"]; String weather = doc["weather"]["main"]; String description = doc["weather"]["description"]; float pressure = doc["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,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"); } |