IoT Personal NodeMCU ESP12 WiFi Wireless Weather Station

14K35245

Intro: IoT Personal NodeMCU ESP12 WiFi Wireless Weather Station

In this Instructable I'm going to show you how to build personal wireless weather station using NodeMCU (ESP12)

One year ago I was create weather station based on Arduino. But always there are ways how to improve things to be better. New version need less power consumption. Rain reset 24h more precise, because time update from NTP server. Add OTA (Over the Air) compability to update is the process of loading a new firmware to
ESP8266 module using WiFi connection rather than a serial communication.

NodeMCU (ESP12) WiFi module will send sensors data to www.wunderground.com , https://weathercloud.net , https://thingspeak.com, https://www.pwsweather.com, www.windy.com

A Weather station is a device that collects data related to the
weather and environment using many different sensors. We can measure many things like:

  • Temperature
  • Humidity
  • Wind
  • Barometric Pressure
  • UV index
  • Rain

STEP 1: Types of Sensors Used for Weather Station

The following is a list of measurement devices that are used in weather stations:

1) NodeMCU (ESP12) main board

2) Thermometer SHT31 thermometer measures temperature. You can measure both the temperature indoors and outdoors, record highs and lows, show trend arrows to indicate temperature rising or falling, and even predict short-term future temperature ranges.

Hygrometer SHT31- A hygrometer measures relative humidity. Relative humidity is the quantity or percentage of water vapor (water in gas form) in the air. Humidity influences environmental factors and calculations like precipitation, fog, dew point and heat index.

3) Barometer (BME280) – A barometer measures atmospheric pressure. A barometer can help to forecast upcoming weather based on the changes it measures in the atmospheric pressure.

4) Davis 6410 anemometer measures how fast the wind is blowing, or wind speed.

ESP8266 weather stations can display wind speed in MPH, KPH or knots, and record current, peak and average wind speed readings.

Wind Vane – A wind vane, or weather vane, is an instrument that determines which direction the wind is blowing.

5) Rain gauge measures rainfall or liquid precipitation

STEP 2: Schematic and Wiring Diagram

STEP 3: NodeMCU PCB Weather Station Shield

Design printed circuit board (PCB), I was used ,,Sprint-Layout" software. Exported to Gerber files. PCB was made https://jlcpcb.com

To create this NodeMCU ESP12 weather station shield you will need:

  1. NodeMcu Lua CH340G/CH340/ ESP8266 Wireless WIFI Internet Devolop Module Ebay
  2. Waterproof Digital Thermal Probe or Sensor DS18B20 Arduino Sensor Ebay
  3. JST-XH Kit 4Pin 2.54mm Terminal Housing PCB Header Wire Connectors Ebay
  4. Atmospheric Pressure Sensor Temperature Humidity Sensor Breakout BME280Ebay
  5. 2x 1K 0805 resistor
  6. 1x 120R 0805 resistor
  7. 2x 4.7K 0805 resistor
  8. 1x 10K 0805 resistor
  9. 1x RJ45 socket Ebay
  10. 1x 47uF electrolytic capacitor
  11. 1 x 40pin 2.54mm Female Single Row Breakaway Pin header Ebay

STEP 4: Arduino Code


!!!! New version ESP8266 library will not work. At this moment only works old version. For example 2.4.2

Board manager ESP8266 - 2.4.2

1. Instal ESP8266 board into Arduino http://esp8266.github.io/Arduino/versions/2.0.0/do...

2.Enter your's Wifi router ssid and password.

  • const char* ssid1 = "xxxxxxxxxx";
  • const char* password1 = "xxxxxxxxxx";

3. Before upload code into your NodeMCU you will need register in wunderground.com to obtain a WU station ID and Key.

  • char ID [] = "xxxxxx";
  • char Key [] = "xxxxxx";

4. Register in weathercloud.net to obtain Weathercloud ID and Key.

  • char ID2 [] = "xxxxxxxx";
  • char Key2 [] = "xxxxxxxxxxx";

5. Register in pwsweather.com to obtain pws station ID and Api key

  • char ID5 [] = "xxxxxxx";
  • char Key5 [] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

6. Change altitudepws in meters (m) to get relative pressure.

7. Register in thingspeak.com to obtain apiKey

  • String apiKey ="XXXXXXXXXXXXXXX";


8 Register in Windy to get API key

char WINDYPAGE [] =

9. Change timezone to correct time zone

  • const int timeZone = 2; //GMT +2 )

I'm using 30 second loop time sending data to Wunderground.com. And 10 minutes loop time sending data to Weathercloud.net and Thingspeak.com


Last edit: 2023 06 15

2020 02 01 - Fix Wunderground.com upload protocol

2020 06 01 - Replace DS18B20 sensor with DHT22, Add rain counter to save in eeprom

2020 09 25 - Correct time sync from NTP server. Add time zone

2021 04 07 - Correct rain tip count write to eeprom

2021 06 24 - Fix Weathercloud.net upload protocol

2021 06 27 - Add upload protocol to Pwsweather.com

2021 07 02 Add upload protocol to Windy.com

2023 06 15 - Fix Windy.net upload protocol.

Replace DHT22 sensor with SHT31


Libraries download link >>> https://drive.google.com/u/0/uc?id=13S3nuOyM5pTfKrUkRHQFMLDRY1NRimir&export=download 

STEP 5: Testing Weather Station

NodeMCU ESP12 is sending sendors data to wunderground.com, weathercloud.net, pwsweather.com, windy.com, and thingspeak.com.

So it looks everything it's working. Job done.

Mine weather station which you can check >

STEP 6: OTA Over-the-air Programming

OTA (Over the Air) update is the process of loading a new firmware to
ESP8266 module using WiFi connection rather than a serial communication. This type of functionality is extremely useful in case of no physical access to the ESP module.

Uploading a new sketch wirelessly from Arduino IDE is intended for the following typical scenarios:

  • during firmware development – as a quicker alternative to uploading a new sketch over a serial
  • for updating the firmware of multiple ESPs in your network

Prepare for OTA capability

  1. Install Python on Your System
    You need to install python27 on your system in order to program ESP8266 from your system you need to run OTA script. Install python27 on System from where your going to upload firmware.
  2. Download and Install Arduino OTA Library Download The library and tools required for OTA
  3. Install "ArduinoOTa.zip" in arduino library.
  4. Go to Tools to select your ESP board model. You also have to choose your ESP’s COM port
  5. Upload file ,,IoT_Personal_NodeMCU_ESP12_WiFi_Wireless_Weather_Station.ino"

  6. Press the “Upload” button in the Arduino IDE and wait for the “Done uploading” message

Uploading a new sketch OTA (Over the Air)

Now your ESP8266 is ready to receive OTA firmware updates. You can
unplug your ESP8266 from your computer and power it through any power source. If your ESP8266 has a wireless connection to your router, you should be fine to upload new firmware.

  1. Go to your Arduino IDE. Open Tools tab select the Port option and you should see something like this:

    Nodemcu_weather_station and your_esp_ip_address

  2. Open your modified Nodemcu_weather_station.ino and upload over the air.

Info is taken from (Rui Santos)

https://randomnerdtutorials.com/esp8266-ota-updates-with-arduino-ide-over-the-air/

STEP 7: Solar Radiation Shield

Solar Radiation Shield is made from flower pot lower pad

STEP 8: Installing Personal Weather Station

The location weather station is the most important part of installation. If weather station is located under a tree or an overhang, the rainfall data measured by the station will not be correct. If you place your weather station in an alley, you could very well get a wind tunnel effect on the anemometer, resulting in erroneous wind data. Weather station should have good "fetch", or distance from any other tall object. The standard wind measurement should be taken at 10 meters above the ground. A roof-top works the best for me. Weather station is powered from solar panel. So it is autonomous.

The most common error in installing a weather station is associated with misplacing the thermometer sensor. Meteorologists define temperature as the temperature in shade with plenty of ventilation. When placing weather station, make sure:

  • The thermometer sensor never receives direct sunlight.
  • The thermometer receives plenty of ventilation and is not blocked from the wind.
  • If the thermometer is placed on a roof-top, make sure it is at least 1.5 meters above the roof-top.
  • If the thermometer is placed above grass, again, it should be at least 1.5 meters above the grass surface.
  • The thermometer is at least 15 meters from the nearest paved surface.

So I'm using weather shelter. Solar Radiation Shield is made from flower pot lower pad. This way, weather station can be placed in direct sunlight, with the thermometer located inside the shelter. More information about installing weather station here

STEP 9: WiFi Signal Quality

Added compatibility to check WiFi signal quality. If your weather station is to far from your router, you will lost communication. So you can try to mount weather station where WiFi signal strength is higher.

STEP 10: 3D Tipping Bucket Rain Gauge and Calibration

Tipping bucket rain gauge 3D link >> https://www.thingiverse.com/thing:4519605

Mine 3d funnel diameter - 95mm 9.5cm ( radius 4.75cm)

Funnel area S= pi *r2 = (3.14 * (4.75 *4.75)) = 70.88cm2

Mine syringe for calibration is 24mm. 24 ml give me 9 tips.

24mm / 70.88cm2 = 0.338cm 3.38mm 3.38mm / 9 tips = 0.375mm

So one tip is 0.375 mm ( 0.0147 inches)

STEP 11: Info Is Taken From:

203 Comments

Windy and its bad manners.


For the second time, Windy suddenly stops accepting my data, while all other services are regularly receiving the information. After trying Windy forums without finding the root cause, a guy suggested to use this script from Leo Herzog:


https://github.com/leoherzog/WundergroundStationForwarder

I tried and it works flawlessly!

It basically reads your data from one weather provider and inputs in another.

I chose to read Wunderground >> Windy. But there are more!


Hope that helps.

Jeffo.

You're welcome. If for some reason you or another person finds out what needs to be changed in the code, let us know. Cheers.

Hello Family!
I hope everyone is well and receiving regular weather updates from their station.

Like other people, I changed humidity sensor to a SHT31 which turned out to be a simple code adjustment. I have been running this sensor for 8 months and it gives reliable and accurate readings.

I did suffer another issue. My station would crash at the same time everyday. A press of the reset button brought it online and everything worked as normal until early the next day.

I swapped between several PSU's and ESP's which made no difference. In the end, the line of code causing this problem was the ESP reboot which occurs in the early morning everyday. Simply commenting it out solved the problem and the station has run fault free without a crash (or reboot) for around 4 months.

I hope this may help someone in the future.
Thanks,
Scott
Scott, sorry, I replied over your post thinking it was one of my messages. Dumb...
Anyway...thanks for the hint.

I am currently fighting (almost quitting) the Windy.com API that refuses to accept my data that was working flawlessly before. Cheers.
Oh, and I also replaced ALL screws in the contraption by stainless steel ones. No more rust. Cheers.
I finally replaced my humidity and temperature sensor with the SHT31 (IP68 dust and waterproof) unit as giano2002 have suggested. Just add it in parallel to the BME280 sensor since it is I2C. Code changes are really small (basically adding library and replacing call to DHT22 to SHT31 instead. Readings are a lot more precise now (comparing to METAR and other PWSs near here). Hope this one lasts more than the DHT22 (mine lasted around a year before going 100% umidity all the time). Thanks, Giano.
That's a good looking station Jeffo! (although the beautiful Brazilian sky always helps)
Thanks, man. I recently purchased a decent radiation shield and installed.
Hi RickE51,

I have posted, five months ago, the following (maybe you did not read it):

" I was finally able to solve the problem of the anomalous values of the wind speed and direction of my weather station.
After replacing the 1K resistor with a 4.7K one and changing the debounce
value, taking it from 30 to 15 milliseconds, as I was advised, nothing
had changed, the values continued to be absolutely out of range. A sign that the problem was to be found in the hardware.
So, double-checking all the circuits, I realized that the connections
between the Davis probe and the ESP8266 board had been reversed, in
preparing an extension of the Davis sensor cable. A stupid mistake,
in crimping the RJ14 plug and socket. Once I fixed the 4 leads
correctly, everything worked as expected.
But in addition to solving that problem, I made another important change to RimvydasP project.
As everyone knows, I2C connections must be very short (no more than two
meters). This greatly limits the possibility of using sensors over
distances greater than 2 meters. But to solve this problem, I found an
effective solution, thanks to the Adafruit LTC4311 circuit.
This circuit, easy to use (see https://learn.adafruit.com/adafruit-ltc4311-i2c-e... allows you to extend the I2C connections, using a network cable, over 30 meters. In my case, I used a 15 meter CAT5E network cable, between the SHT31 sensor and the ESP8266 board, and there were no problems. I also did the test with a 30 meter cable, without encountering any problems.
Just connect this Adafruit to the SDA and SCK terminals of the ESP8266 card,
as well as the two power supply terminals, and connect the EN pin with a 10K resistor to VCC.

I hope that this solution will be useful for those who have to use I2C sensors over long distances"

The schematics of my station and my code are here attached.
Consider that from May till now my station is working fine (https://www.wunderground.com/dashboard/pws/ICASACA...

Let me know if you solved.


Thank you for all of your help
I have the most of the station working except for the weather vane. Are you using a davis vane or pot to measure windSpeed? I have a sparkfun weather sensor and the vane uses 8 reed switches to detect direction. The code doesnt give me correct wind direction what ever I try . I measure the voltage at the A0 pin Adc and its correct with what its supposed to be but it displays the wrong directions on WeatherUnderground.

Tnx again
Hi,
starting from May 2022 I have added a Davis 6410 wind vane on my station. Now it is well working.

Before that date I have used Misol wind wane, thanks to RimvydasP, who helped me to modify the code.

If you want, try my old code, that you can find on a my Comment of one year ago.

The code is: WEATHER_STATION_19_11_2021.ino

Maybe that code could work for your wind cane. Just try.

I can't do more, sorry.
Hi
Ok I finally have the vane working, ( sparkfun reed type) . After trying all kinds of code I finally just took the other alternative. I did some testing with the current code ( for davis type) on breadboard to get the resistances need for the proper direction. I then disassembled the vane assembly and replaced the 0603 smt resistors which the values I needed and reassembled. And it worked great and no code modification . Thanks for all of your help

R
Greetings giano2002 and rimdydas
I have been following your tips and suggestions concerning this great project. I have most everything working except wind direction. I also am using a sparkfun weather sensor station ( with a magnet and reed switches/ resistors) for the vane . I have read where the 10k resistor for the voltage divider was changed to 100k, I've done that, I have tryed using the code you guys came up with but still and getting the wrong wind direction values. Was wondering if you ever came up with a code that worked using this reed vane? I'm actually only using weather underground site for readings. Any tips ideas I may try ?

Thanks fellows
Ricke
Greetings
Enjoying the project but seem to have a issue. it seems that the temperature reading that I'm getting on WeatherUnderground is from the BME280 and not the DHT22. Am I missing something here ? On the serial monitor it is measuring temp and humidity but the temp is in C. On the DHT22. The code seems to list it at DHT22 temp_f . ( when I remove the DHT22 there is no temp from either bme or Dht) . Any one got an idea? Tnx
RICVICE
tempc= dht.readTemperature(); ????

temp2c = bme.getTemperature_C(); ????

temp_f = (tempc_min * 9.0)/ 5.0 + 32.0; ???

Show me your WeatherUnderground upload code
////////////////////////////// SEND DATA TO Wunderground.com //////////////////////////////////////////////

//------------------------------------------------------------------------------------------------------------

void wunderground(void)

{

  Serial.print("Connecting to ");

  Serial.println(server);

  WiFiClient client;

 if (client.connect(server, 80)) {

    Serial.print("connected to ");

    Serial.println(client.remoteIP());

    delay(100);

  } else {

    Serial.println("connection failed");

  }

  client.print(WEBPAGE);

  client.print("ID=");

  client.print(ID);

  client.print("&PASSWORD=");

  client.print(Key);

  client.print("&dateutc=now&winddir=");

  client.print(CalDirection);

  client.print("&tempf=");

  client.print(temp_f);

  client.print("&windspeedmph=");

  client.print(wind_speed_avg);    

  client.print("&windgustmph=");

  client.print(windgustmph);

  client.print("&dewptf=");

  client.print(dewpt_f);

  client.print("&humidity=");

  client.print(humidity);

  client.print("&baromin=");

  client.print(baromin);

  client.print("&rainin=");

  client.print(rain1h);

  client.print("&dailyrainin=");

  client.print(rain24h);

  client.print("&softwaretype=NodeMCU-ESP12&action=updateraw&realtime=1&rtfreq=30");

  client.print("/ HTTP/1.1\r\nHost: rtupdate.wunderground.com:80\r\nConnection: close\r\n\r\n");

  Serial.println(" ");

  delay(1000);

  Thank you for your all of your help and a great project!
If you didn't change these lines it should work.

tempc= dht.readTemperature(); ????

temp2c = bme.getTemperature_C(); ????

temp_f = (tempc_min * 9.0)/ 5.0 + 32.0; ???
I ask for the support of everyone who built this weather station using Davis wind sensors.

I replaced the Chinese anemometer with the Davis 6410 one, using the connections indicated by RimvydasP and its latest software version released on 2 July 2021, modified only in the part concerning the temperature and humidity sensors [attachment 1].

Everything seemed to work well but then, observing the data recorded over 24 hours, I noticed that wind speed peaks are absolutely wrong and not real (from a few km / h wind speed suddenly rises to 60-80-160 Km / h and then return to normal values) [attachment 2].

I add that the wind was almost absent at the time these peaks occurred and similar speeds have never been reached on the site of my weather station (https://www.wunderground.com/dashboard/pws/ICASACAL2).

The connections between the various sensors and the NodeMCU ESP8266 are made according to the diagram that I attach [attachement 3 and 4].

How can these anomalous peaks be explained?
Anyone have any suggestions?
Thank you!

Guanio, greetings
I'm not sure if this will help but an idea. On the Davis sensor , Davis and several other projects recommend using a 4.7k ohm resistor ( pull up resistor)in place of the 1k that is shown on this project. It shouldn't but I've seen strange things happen on a pullup voltage.
Best of luck!
Rick
More Comments