IoT Weather Station with NodeMCU OLED & OpenWeatherMap
Make an IoT Based Simple Online Weather Station using ESP8266 NodeMCU Wi-Fi board & OLED display & Retrieve Data from OpenWeatherMap
- Suitable forB.Tech/Diploma ESP8266/IoT students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
IOT Weather Station with NodeMCU OLED:
In this Latest IoT project, we will learn how to make an IoT Based Simple Online Weather Station using ESP8266 NodeMCU (ESP-12E) Wi-Fi development board, and an SSD1306 OLED display (128×64 Pixel). This project is a wonderful project for IoT beginners who want to learn about retrieving data from an Online Internet server to the NodeMCU board.
The NodeMCU pulls weather data like temperature, humidity, pressure, wind speed and wind directional degree from weather website called
openweathermap.org
and display it on SSD1306 screen.
Check some of the weather station based projects here:
ESP8266 & BME280 Based Mini Weather Station
IoT Live Weather Station Monitoring with ESP8266
MQTT Weather Station with GSM
LoRa Based Wireless Weather Station
Bill of Materials
As the topic is clear, i.e IoT Weather Station with NodeMCU OLED & OpenWeatherMap, we just need OLED Display and NodeMCU wifi Module for this project. You can purchase these components from Amazon.
S.N.
Components Name
Quantity
Purchase Links
NodeMCU ESP8266 Board
Amazon
AliExpress
0.96" I2C OLED Display
Amazon
AliExpress
Connecting Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
Block Diagram – IOT Weather Station:
This is a simple block diagram for IoT Weather Station which simply explains how the System works.
The website
openweathermap.org
provides an online service for weather data and forecast. The data is uploaded to a cloud server. NodeMCU ESP8266 Wifi Module collects the data information online and downloads/retrieves the info like temperature, humidity, pressure, wind speed, and wind directional degree.
These data are displayed on 0.96″ SSD1306 OLED Display along with City.
Circuit Diagram & Connection:
The SDA and SCL lines of the I2C bus come from GPIO4 (D2) and GPIO0 (D3) of the NodeMCU board (respectively), they are connected to SDA and SCL (SCK) pins of the SSD1306 display module. The OLED display module is supplied with 5V from the Vin pin of the NodeMCU board.
Generating API from OpenWeatherMap:
OpenWeatherMap
Access current weather data for any location including over 200,000 cities all over the world. Current weather is frequently updated from more than 40,000 weather stations. The data is available in JSON, XML, or HTML format. We will use the data in JSON format here.
Visit
https://openweathermap.org
and sign in by creating your account.
Create or Generate your API Key as it is needed for retrieving data.
Select the city and country code by entering your city name. Example: Jaipur, IN here Jaipur is a city, and IN is a country code for India. City name and country code need to be entered on the code.
Source Code/Programs:
Below is the code for IoT Weather Station with NodeMCU OLED & OpenWeatherMap. You need 3 different libraries for that, i.e
Adafruit_GFX.h
Adafruit_SSD1306.h
and
ArduinoJson.h
. You can get all these libraries from the Library Manager.
Enter the WIFI SSID, Password, and City Name with Country Code. Now you can upload this code to NodeMCU Board.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h> // http web access library
#include <ArduinoJson.h> // JSON decoding library
// Libraries for SSD1306 OLED display
#include <Wire.h> // include wire library (for I2C devices such as the SSD1306 display)
#include <Adafruit_GFX.h> // include Adafruit graphics library
#include <Adafruit_SSD1306.h> // include Adafruit SSD1306 OLED display driver
#define OLED_RESET 5 // define SSD1306 OLED reset at ESP8266 GPIO5 (NodeMCU D1)
Adafruit_SSD1306
display
(
OLED_RESET
)
;
// set Wi-Fi SSID and password
const
char
*
ssid
=
"Your Wifi SSID"
;
const
char
*
password
=
"Your Wifi Password"
;
// set location and API key
String
Location
=
"City Name, Country Code"
;
String
API_Key
=
"Your API Key"
;
void
setup
(
void
)
{
Serial
begin
(
9600
)
;
delay
(
1000
)
;
Wire
begin
(
)
;
// set I2C pins [SDA = GPIO4 (D2), SCL = GPIO0 (D3)], default clock is 100kHz
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display
begin
(
SSD1306_SWITCHCAPVCC
0x3C
)
;
// initialize with the I2C addr 0x3D (for the 128x64)
// init done
Wire
setClock
(
400000L
)
;
// set I2C clock to 400kHz
display
clearDisplay
(
)
;
// clear the display buffer
display
setTextColor
(
WHITE
BLACK
)
;
display
setTextSize
(
)
;
display
setCursor
(
)
;
display
println
(
" Internet Weather"
)
;
display
(
" Station - Jaipur"
)
;
display
display
(
)
;
WiFi
begin
(
ssid
password
)
;
Serial
(
"Connecting."
)
;
display
setCursor
(
)
;
display
println
(
"Connecting..."
)
;
display
display
(
)
;
while
(
WiFi
status
(
)
!=
WL
_
CONNECTED
)
{
delay
(
)
;
Serial
(
"."
)
;
}
Serial
println
(
"connected"
)
;
display
(
"connected"
)
;
display
display
(
)
;
delay
(
1000
)
;
}
void
loop
(
)
{
if
(
WiFi
status
(
)
==
WL_CONNECTED
)
//Check WiFi connection status
{
HTTPClient
http
;
//Declare an object of class HTTPClient
// specify request destination
http
begin
(
"http://api.openweathermap.org/data/2.5/weather?q="
+
Location
+
"&APPID="
+
API_Key
)
;
// !!
int
httpCode
=
http
GET
(
)
;
// send the request
if
(
httpCode
>
)
// check the returning code
{
String
payload
=
http
getString
(
)
;
//Get the request response payload
DynamicJsonBuffer
jsonBuffer
(
)
;
// Parse JSON object
JsonObject
&
root
=
jsonBuffer
parseObject
(
payload
)
;
if
(
!
root
success
(
)
)
{
Serial
println
(
F
(
"Parsing failed!"
)
)
;
return
;
}
float
temp
=
(
float
)
(
root
[
"main"
]
[
"temp"
]
)
273.15
;
// get temperature in °C
int
humidity
=
root
[
"main"
]
[
"humidity"
]
;
// get humidity in %
float
pressure
=
(
float
)
(
root
[
"main"
]
[
"pressure"
]
)
/
1000
;
// get pressure in bar
float
wind_speed
=
root
[
"wind"
]
[
"speed"
]
;
// get wind speed in m/s
int
wind_degree
=
root
[
"wind"
]
[
"deg"
]
;
// get wind degree in °
// print data
Serial
printf
(
"Temperature = %.2f°C\r\n"
temp
)
;
Serial
printf
(
"Humidity = %d %%\r\n"
humidity
)
;
Serial
printf
(
"Pressure = %.3f bar\r\n"
pressure
)
;
Serial
printf
(
"Wind speed = %.1f m/s\r\n"
wind_speed
)
;
Serial
printf
(
"Wind degree = %d°\r\n\r\n"
wind_degree
)
;
display
setCursor
(
)
;
display
printf
(
"Temperature: %5.2f C\r\n"
temp
)
;
display
printf
(
"Humidity : %d %%\r\n"
humidity
)
;
display
printf
(
"Pressure : %.3fbar\r\n"
pressure
)
;
display
printf
(
"Wind speed : %.1f m/s\r\n"
wind_speed
)
;
display
printf
(
"Wind degree: %d"
wind_degree
)
;
display
drawRect
(
WHITE
)
;
// put degree symbol ( ° )
display
drawRect
(
WHITE
)
;
display
display
(
)
;
}
http
end
(
)
;
//Close connection
}
delay
(
60000
)
;
// wait 1 minute
}
// End of code.
Video Tutorial & Explanation:
IOT Based Weather Station || NodeMCU with OLED & OpenWeatherMap
Watch this video on YouTube
In this Latest IoT project, we will learn how to make an IoT Based Simple Online Weather Station using ESP8266 NodeMCU (ESP-12E) Wi-Fi development board, and an SSD1306 OLED display (128×64 Pixel). This project is a wonderful project for IoT beginners who want to learn about retrieving data from an Online Internet server to the NodeMCU board.
The NodeMCU pulls weather data like temperature, humidity, pressure, wind speed and wind directional degree from weather website called
openweathermap.org
and display it on SSD1306 screen.
Check some of the weather station based projects here:
ESP8266 & BME280 Based Mini Weather Station
IoT Live Weather Station Monitoring with ESP8266
MQTT Weather Station with GSM
LoRa Based Wireless Weather Station
Bill of Materials
As the topic is clear, i.e IoT Weather Station with NodeMCU OLED & OpenWeatherMap, we just need OLED Display and NodeMCU wifi Module for this project. You can purchase these components from Amazon.
S.N.
Components Name
Quantity
Purchase Links
NodeMCU ESP8266 Board
Amazon
AliExpress
0.96" I2C OLED Display
Amazon
AliExpress
Connecting Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
Block Diagram – IOT Weather Station:
This is a simple block diagram for IoT Weather Station which simply explains how the System works.
The website
openweathermap.org
provides an online service for weather data and forecast. The data is uploaded to a cloud server. NodeMCU ESP8266 Wifi Module collects the data information online and downloads/retrieves the info like temperature, humidity, pressure, wind speed, and wind directional degree.
These data are displayed on 0.96″ SSD1306 OLED Display along with City.
Circuit Diagram & Connection:
The SDA and SCL lines of the I2C bus come from GPIO4 (D2) and GPIO0 (D3) of the NodeMCU board (respectively), they are connected to SDA and SCL (SCK) pins of the SSD1306 display module. The OLED display module is supplied with 5V from the Vin pin of the NodeMCU board.
Generating API from OpenWeatherMap:
OpenWeatherMap
Access current weather data for any location including over 200,000 cities all over the world. Current weather is frequently updated from more than 40,000 weather stations. The data is available in JSON, XML, or HTML format. We will use the data in JSON format here.
Visit
https://openweathermap.org
and sign in by creating your account.
Create or Generate your API Key as it is needed for retrieving data.
Select the city and country code by entering your city name. Example: Jaipur, IN here Jaipur is a city, and IN is a country code for India. City name and country code need to be entered on the code.
Source Code/Programs:
Below is the code for IoT Weather Station with NodeMCU OLED & OpenWeatherMap. You need 3 different libraries for that, i.e
Adafruit_GFX.h
Adafruit_SSD1306.h
and
ArduinoJson.h
. You can get all these libraries from the Library Manager.
Enter the WIFI SSID, Password, and City Name with Country Code. Now you can upload this code to NodeMCU Board.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h> // http web access library
#include <ArduinoJson.h> // JSON decoding library
// Libraries for SSD1306 OLED display
#include <Wire.h> // include wire library (for I2C devices such as the SSD1306 display)
#include <Adafruit_GFX.h> // include Adafruit graphics library
#include <Adafruit_SSD1306.h> // include Adafruit SSD1306 OLED display driver
#define OLED_RESET 5 // define SSD1306 OLED reset at ESP8266 GPIO5 (NodeMCU D1)
Adafruit_SSD1306
display
(
OLED_RESET
)
;
// set Wi-Fi SSID and password
const
char
*
ssid
=
"Your Wifi SSID"
;
const
char
*
password
=
"Your Wifi Password"
;
// set location and API key
String
Location
=
"City Name, Country Code"
;
String
API_Key
=
"Your API Key"
;
void
setup
(
void
)
{
Serial
begin
(
9600
)
;
delay
(
1000
)
;
Wire
begin
(
)
;
// set I2C pins [SDA = GPIO4 (D2), SCL = GPIO0 (D3)], default clock is 100kHz
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display
begin
(
SSD1306_SWITCHCAPVCC
0x3C
)
;
// initialize with the I2C addr 0x3D (for the 128x64)
// init done
Wire
setClock
(
400000L
)
;
// set I2C clock to 400kHz
display
clearDisplay
(
)
;
// clear the display buffer
display
setTextColor
(
WHITE
BLACK
)
;
display
setTextSize
(
)
;
display
setCursor
(
)
;
display
println
(
" Internet Weather"
)
;
display
(
" Station - Jaipur"
)
;
display
display
(
)
;
WiFi
begin
(
ssid
password
)
;
Serial
(
"Connecting."
)
;
display
setCursor
(
)
;
display
println
(
"Connecting..."
)
;
display
display
(
)
;
while
(
WiFi
status
(
)
!=
WL
_
CONNECTED
)
{
delay
(
)
;
Serial
(
"."
)
;
}
Serial
println
(
"connected"
)
;
display
(
"connected"
)
;
display
display
(
)
;
delay
(
1000
)
;
}
void
loop
(
)
{
if
(
WiFi
status
(
)
==
WL_CONNECTED
)
//Check WiFi connection status
{
HTTPClient
http
;
//Declare an object of class HTTPClient
// specify request destination
http
begin
(
"http://api.openweathermap.org/data/2.5/weather?q="
+
Location
+
"&APPID="
+
API_Key
)
;
// !!
int
httpCode
=
http
GET
(
)
;
// send the request
if
(
httpCode
>
)
// check the returning code
{
String
payload
=
http
getString
(
)
;
//Get the request response payload
DynamicJsonBuffer
jsonBuffer
(
)
;
// Parse JSON object
JsonObject
&
root
=
jsonBuffer
parseObject
(
payload
)
;
if
(
!
root
success
(
)
)
{
Serial
println
(
F
(
"Parsing failed!"
)
)
;
return
;
}
float
temp
=
(
float
)
(
root
[
"main"
]
[
"temp"
]
)
273.15
;
// get temperature in °C
int
humidity
=
root
[
"main"
]
[
"humidity"
]
;
// get humidity in %
float
pressure
=
(
float
)
(
root
[
"main"
]
[
"pressure"
]
)
/
1000
;
// get pressure in bar
float
wind_speed
=
root
[
"wind"
]
[
"speed"
]
;
// get wind speed in m/s
int
wind_degree
=
root
[
"wind"
]
[
"deg"
]
;
// get wind degree in °
// print data
Serial
printf
(
"Temperature = %.2f°C\r\n"
temp
)
;
Serial
printf
(
"Humidity = %d %%\r\n"
humidity
)
;
Serial
printf
(
"Pressure = %.3f bar\r\n"
pressure
)
;
Serial
printf
(
"Wind speed = %.1f m/s\r\n"
wind_speed
)
;
Serial
printf
(
"Wind degree = %d°\r\n\r\n"
wind_degree
)
;
display
setCursor
(
)
;
display
printf
(
"Temperature: %5.2f C\r\n"
temp
)
;
display
printf
(
"Humidity : %d %%\r\n"
humidity
)
;
display
printf
(
"Pressure : %.3fbar\r\n"
pressure
)
;
display
printf
(
"Wind speed : %.1f m/s\r\n"
wind_speed
)
;
display
printf
(
"Wind degree: %d"
wind_degree
)
;
display
drawRect
(
WHITE
)
;
// put degree symbol ( ° )
display
drawRect
(
WHITE
)
;
display
display
(
)
;
}
http
end
(
)
;
//Close connection
}
delay
(
60000
)
;
// wait 1 minute
}
// End of code.
Video Tutorial & Explanation:
IOT Based Weather Station || NodeMCU with OLED & OpenWeatherMap
Watch this video on YouTube
Technologies used
Hardware components
- ESP8266
- Arduino
- BME280
- SSD1306
- OLED
Software & tools
- MQTT
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.