DIY Wireless based Weather Station Project by using Nextion LCD

by Robert Poloboc
0 comment

Project Abstract:

A Wemos D1 Mini is constantly receiving weather information from the internet for your city and sends it over to the display. Simultaneously, an RTC Module sends the current date and time to the Wemos D1 Mini to also display it on the display. Additionally, a BME280 temperature and humidity sensor send the corresponding values to the Wemos and it sends the data over to the display, to show it beside the data from the internet. For the communication between the Wemos, RTC Module and BME280 Sensor we will be using the I2C protocol. The display uses a serial interface for communication. 

Software necessities

Now in order to complete this project, you need to make sure that you have the ESP8266, as well as the SparkFun BME280 libraries installed in the Arduino IDE. You also need the Nextion Editor software(free).

Circuit diagram

Given this functioning principle, I designed a schematic for this circuit.

PCB Gerber View – PCBGOGO Online Gerber Viewer



How to add PCB Gerber File to View Online | Video Demonstration 

The PCBs Arrived For Our Project :

PCBGOGO is a very qualitative Chinese PCB manufacturer with very fast shipping time. we received our PCBs in 2 (!!!!) days, which is awesome.  PCBGOGO provides amazing work on PCB manufacturing and as well as PCB assembling. This website can really help you guys, to place your orders. PCBgogo promises its’ customers to provide them with a fast delivery service and to place their order as soon as possible.

Watch PCBGOGO Package Unboxing Video:

Final Look of PCB After the Assembling of Components :

Final Video of the Project Demonstration


Arduino Source code Explanation:

In the Arduino code, you need to set the I2C address of your BME sensor. What happens in the following line:

You also need to select the Wemos D1 board from the board manager, as shown below.

Data readings

You get the actual weather readings from these 2 lines:

For the WiFi part, you need to fill out the following parameters:

For displaying the date and time, I had to do some workarounds to have them properly shown on the display. The GUI doesn’t automatically add a 0 if the time has 1 letter, for example, it will show 8:30, which doesn’t look that good. In the following lines, I made sure that when the date/hour consists of 1 number, the code adds a 0 in front of the number. Additionally, I had to subtract 1 from the hour value because of the wintertime.

In the following lines, I convert the string readings for the date/time in integer.

As explained beforehand, here I add a 0 to the numbers with an IF statement, if the date/time only consists out of 1 number.

Transmitting data to display

In order to transmit the data/time values, this is how you need to send the values over to the display.

The variable “data” consists of the hours + : + minutes, in order to achieve the format 08:56 for example. The same goes for the date.

The temperature and humidity are transmitted with the following lines:

Online weather data

The display needs to get 4 hexadecimal 0xFF in order to process the data packet. For the weather values from the internet, I used to get the local weather from my city.

You need to register yourself for free in order to get your API Key.

After searching for your city, you can copy the city ID from the link.

A place for Adding API and City id into Source Code


This is how the GUI looks like. we designed it by using the Nextion Editor software.

Complete Source Code: 

#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <Wire.h>
#include <DS3231_.h>
#include "SparkFunBME280.h"
BME280 mySensor;
float temps;
float hums;
String data;
float tempitod;
float humitod;
String result;
DS3231 clock_ds;
RTCDateTime dt;

String string1;
String string2;
String string3;
String string4;
String string5;
int hour_int;
int minute_int;
int day_int;
int month_int;
String string_h;
char ssid[] = "type your wifi name";
char pass[] = "type your wifi password";
String APIKEY = "a3b00f5ba21ccc4fedf1b1846b3f37b0";
String CityID = "2778067";

WiFiClient client;
char servername[] = "";

void setup() {

  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {


void loop() {
  dt = clock_ds.getDateTime();

 string1 = (dt.hour)-1;
 hour_int = string1.toInt();

 if((dt.hour) == "00" ){

 string2 = dt.minute;

string3 =;
string4 = dt.month;
string5 = dt.year;

minute_int = string2.toInt();

day_int = string3.toInt();
month_int = string4.toInt(); 

if (hour_int < 10)
  string1 = "0" + string1;

if (minute_int <10)
  string2  = "0" + string2;

 if (day_int <10)
  string3  = "0" + string3;

if (month_int <10)
  string4  = "0" + string4; 

 hums = mySensor.readFloatHumidity();
 temps = mySensor.readTempC();


void getWeatherData()
  if (client.connect(servername, 80)) { 
    client.println("GET /data/2.5/weather?id=" + CityID + "&units=metric&APPID=" + APIKEY);
    client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Connection: close");
  while (client.connected() && !client.available()) delay(1); 
  while (client.connected() || client.available()) { 
    char c =;
    result = result + c;
  result.replace('[', ' ');
  result.replace(']', ' ');
  char jsonArray [result.length() + 1];
  result.toCharArray(jsonArray, sizeof(jsonArray));
  jsonArray[result.length() + 1] = '\0';
  StaticJsonBuffer<1024> json_buf;
  JsonObject &root = json_buf.parseObject(jsonArray);
  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"];
  tempitod = temperature;
  humitod = humidity;

void NextionData() {

  data = "time_h.txt=\"" + string1+ ":" + "\"";

  data = "time_m.txt=\"" + string2 + "\"";

  data = "day.txt=\"" + string3 + "\"";

  data = "month.txt=\"" + string4 + "\"";

  data = "year.txt=\"" + string5 + "\"";

  data = "temps.txt=\"" + String(temps, 1) + "\"";
  data = "hums.txt=\"" + String(hums, 1) + "\"";

  data = "tempitod.txt=\"" + String(tempitod, 1) + "\"";
  data = "humitod.txt=\"" + String(humitod, 1) + "\"";

Click Here To Download Nextion Source Code File | Human Machine Interface (HMI)

A sponsor of this project

The sponsor of this project is PCBGOGO which delivered us 10 PCB’s for this project. PCBGOGO produces high-quality PCBs in a very short time and delivers them very quick too. So, if you are thinking of making your project professional, don’t hesitate to upload your Gerber files to PCBGOGO to receive 10 PCBs for a very low price.

Placing Your Order Made Easy at PCBGOGO 

Related Articles

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy