Introduction: Easy IoT Weather Station With Multiple Sensors

Picture of Easy IoT Weather Station With Multiple Sensors

A weather station is a fun project that teaches you a ton about electronics with the added benefit being an actually useful little device. The project requires a bunch of cheap parts and sensors totaling less than $15, and the whole thing ends up fitting in your hand. The station creates a web site that monitors temperature, dew point, humidity, pressure, light index, and rain (Thingspeak channel). It’s a pretty easy set up, and you’ll just need some basic electronics skills to get it going.

There are some other NodeMcu or ESP8266 weather stations published on the web. Nevertheless they do not include the sensors I used and often are programmed in the more difficult language: LUA. This weather channel has got the following (unique) characteristics:

This channel will stream the following sensor data to a Thingspeak channel:

  1. Temperature DHT11/22;
  2. Temperature BMP180;
  3. Humidity DHT11/22;
  4. Pressure BMP180;
  5. Dew point temperature DHT11/22;
  6. Altitude BMP180;
  7. Light intensity LDR;
  8. Rain value.

The specific materials needed for this project are mentioned per step. General materials needed are:

    • Breadboard;
    • Perfboard;
    • NodeMCU V0.9 or 1.0;
    • Some wires;
    • Micro USB to USB cable;
    • 2 '1N4001 1A 50V Diodes'
    • 3 '10K resistors'

    I estimate the costs of the project around 15$. (NodeMCU=4,76$, DHT22=3,10$ OR DHT11=1$, BMP180 = 3,50$, Rain sensor = 0.99$, additional materials such as perfboard, wires, 2 diodes, 2 resistors and 1 LDR, I estimate around 4$)

    Step 1: The NodeMcu Board

    As I am a newby, I bought the NodeMcu board for less than 6$, more or less per exident. I was looking for a board that could connect my projects to the internet. The NodeMcu board did look a lot like an arduino and therefore it felt very familar. At that time I had no idea of the big advantages of the board.

    The NodeMcu board is in fact an arduino with a wifi shield. You can reconise this shield by the metal plate on top of it. This wifi shield is called the esp8266. The shield can be bought and used as an individual controler, a well known version is the esp8266 V1 which has only got 2 digital pins. The later version (one of them is placed on top of the NodeMcu board) do have more digital pins.

    The big advantage of the NodeMcu board is that the board can be programmed in the arduino environment: arduino IDE. Also, the board consists of a 5 volt step down converter. You can safely connect the board by USB to your computer without having to buy a 3.3 volt stepdown module.

    If you want to buy a NodeMcu board you can buy either the 0.9 version or the 1.0 version. The only difference I know is that the 0.9 version is wider than the 1.0 version. Yyou can not use the 0.9 version on a broadboard and plug in wires next to it.

      I found a lot of tutorials on the internet where they programmed the board with LUA software. As I never used this software before I preffered to stay with the arduino IDE software.

      Programming the nodeMCU with arduino is easy!

      Simply open arduino IDE, the latest version (I use 1.6.6). Go to 'file' and click on 'preferences'. Add the following link in the field 'additional board URL':

      http://arduino.esp8266.com/stable/package_esp8266c...

      After this you can restart the software and you must be able to select the board in the board manager (V1.0 or V0.9).

      Pins of the NodeMcu

      A small note: when you are programming an NodeMCU board, the pin layout is slightly different from an arduino board. Use the image below to compare the pins. If you mention an GPIO pin in the sketch for the NodeMCU, you have to connect the wire to the pin indicated in the picture below. (google: 'NodeMCU pin map')

      For example: If you want to connect some sensor to D5, you have to mention pin 14 in your arduino code. In the code below and the corresponding Fritzing visualisation, the connections are already adjusted.

    Step 2: Connecting to Thingspeak

    Picture of Connecting to Thingspeak

    As we are going to push our data to Thingspeak we have to make an account. Thingspeak is a cloud service. It is great, easy and looks realy cool! Next to this, Thingspeak provides several options for interaction with your data such as Thingtweet, Thinghttp etc.

    Simply go to thingspeak.com and make an account. Fill in at least the first and second field in the settings. If you connect a temperature and humidity sensor such as described in the next step, fill in 'temperature' in field 1, 'humidity' in field 2 and 'dew point' in field 3. If you want to connect other sensors such as the BMP sensor, rain sensor, LDR, simply do the same forthe rest of the fields.

    You can find a key that you have to mention in your arduino sketch under the tap 'API key'. This key is necesarry to connect the arduino to the Thingspeak channel. See step 4 :)

    Step 3: Connecting the Sensors

    Picture of Connecting the Sensors

    I can recomment you to connect the sensors one after the other, starting with the DHT11/DHT22 sensor. Once a sensor is working properly you can go on and add the next sensor.


    The DHT11/22

    This is a simple sensor to start with! The DHT22 is slightly more accurate compared to the DHT11 but is less costly. I started with the blue DHT11 but get enthusiastic and bought the white DHT22 soon after. As you can see in the image above I add all the sensors in the broadboard next to the NodeMcu.

    Connecting the DHT11 or DHT22 sensor is very easy. Make sure you check the following:

    If your sensor is on a small board, there is already a resistor between pin 1 and 2. The board with the DHT11/DHT22 has only three pins. If not (as presented in the picture), add a 10K resistor between the first and the second pin. Connect the first pin to the 3.2 volts (presented on the board) and the 4th pin to the ground. Connect the second pin to digital pin 4 (D$) of the NodeMcu board.

    If you look closely you will see that the D4, 5V and ground pin on the NodeMcu board are all next to eachother! When you make use of a DHT sensor on a small board you can easily prick the sensor in the broadboard next to the NodeMcu as the pins will match!

    The BMP sensor

    The BMP sensor meassures the temperature and the air pressure. Yes, we already have a temperature sensor added in the previous step but not an air pressure sensor. Connect the power pin to the 3.2 volt line of the NodeMCU and the ground pin to the ground of the NodeMCU. The SCL has to be connected to D1 and the SDA to D2.

    The Rain sensor and Light sensor

    This is a tricky part as the NodeMCU has only one analog pin (see image, buttum left). We can solve this problem by multiplexing the analog pins. With the help of two diodes and two GPIO pins we power both sensors in sequense. I have written a seperate instructable about this. Please click here. The instructable is based on an arduino board. Since the NodeMCU is programmed with arduino IDE this will be no problem.

    As you can see the rain sensor is powered by pin D7 (GPIO13). The LDR is powered by pin D8 (GPIO15).

    A small node on the rain sensor used in this project. The rain sensor was dilivered with a small module. This module is not required for the rain sensor to work as we want to read the analog value. The reason people use these modules is that connection to digital pins of the microcontroler is possible. The onboard potentiometer sets the value in order to pull the digital pin of the microcontroller high or low.

    Step 4: Coding

    As I am not very good in programming I tried several sketches availible on the internet. I found out that most of the sketches where written in LUA language and therefor useless for me. An other thing I found is that when you find a sketch for a seperate esp8266 shield (one of them is on top of the NodeMcu) it is possible to use this sketch on the NodeMCU without any problems. Ok, this should sound stupid to you, but I realy didnt know that!

    I found a good sketch for temperature and humidity on this website. As one can see this sketches is made for the esp8266V1.0 (only the wifi shield with 2GPIO pins) but workes on the NodeMcu board. The library of the ESP8266WiFi.h is automaticly downloaded when you add theNodeMcu board, the DHT library you can simply download by using the inbuild library manager. I found that when using the DHT library (and not the DHT11 library) it doesnt matter which sensor you use, the DHT22 or the DHT11! Simply change everywhere where DHT11 is written in the text into DHT22. Great!

    The sketch from this website served as basis for the sketch I developed and is given below. I simply started with the DHT22 sensor to push the temperature and humidity to thingspeak whereafter I added the BMP sensor, rain sensor and LDR sensor. If you compare the sketch above with the sketch below you will see how to add aditional sensors!

    After I added all the sensors I discoverd that you can derive the dew point from the temperature and the humidity. It is also possible to retreave the alltitude from the temperature and the air pressure, althrough this is from less importance for a weather channel it is fun. I added the formula for the dew point and the alltitude in the arduino sketch.

    1. Change the apiKey with the one of your account of thingspeak
    2. Add the 'ssid name' of your wifi network. This is simply the name you see when you click in the right bottum corner of you screen.
    3. Add the password of this wifi network

    If you uploaded the sketch you can verify in the serial monitor how it works. Simply open the monitor by pressing CNTR + M.

    Step 5: Getting Everything in One Box

    Picture of Getting Everything in One Box

    I love to use old screw boxes for project enclosures as they have the perfect size for microcontrollers and are watertight. The rain sensor fitted perfectly on top of the screw box I used. The DHT sensor and the BMP sensor I positioned on the side of the box. I covered both sensors with some multiplex so that rain could not invluence the readings.

    A small update: I see that the temperature (see my thingspeak channel) is a bit on the high side during the day. I think this is the result of the screw boxes that have limited mass and heat up quickly. Mabey a more solid structure (from wood or bricks) will give more accurate readings.


    update: Mabey it is not a good idea to put it in a screw box. I thought that they would be watertight but it appeared to be different. See last picture.

    Step 6: Getting Cool Gauges

    Picture of Getting Cool Gauges

    Thingspeak has lots of plugin options. One of them is that it is possible to make gauges and publish them on your website. Thingspeak will automaticaly generate a code for the gauges. It is possible to adjust the gauges (change the colors, numbers, scale etc.) by adjusting the code. Unfortunately viewing the gauges is only possible in the 'private view' tab of Thingspeak. If you link the gauges to your private website (such as I did) by using an iframe you have to be logged in to Thingspeak to be able to view the gauges.

    In my gauges I adjusted the position of the colors. I also added the collor green. Please copy the following code in the HTML section, the CSS section and the Javascript section of Thingspeak. (The code below I use to view the temperature)

    Step 7: Extra Features

    I added a piezo buzzer that indicates when the board is connected to the wifi. The piezo buzzer is not included in the sketch presented above. Please contact be if you have problems connecting a piezo buzzer.

    An other future I added is a flashing led. On the NodeMcu one can find an onboard led that flashes everytime data is send. I demolished the led with a soldering iron and soldered wires on the old connection points of this led before adding a 4mm led. This led tells me when data is send. This extremely easy when the NodeMCU is positioned inside the screw box.

    Step 8: Have Fun

    Picture of Have Fun

    Have fun building and learning! Please let me know what you think of this instructable. I would love to make some improvements if necesarry.

    Regards,

    Vincent

    Comments

    brandon28139 (author)2016-06-17

    Anyone else had a issue where the serial monitor output from Arduino IDE is just garbage ASCII like !%Ǣɸ9▓. I have read it is a power or cable issue. I have tried two different usb cables, Is it possible the usb ports on my laptop don't put out enough power? It runs the blinking example uploaded from Arduino IDE so it seems to be setup correctly. The output from es explorer when running lua scripts looks fine though so I'm stumped.

    mocraft (author)brandon281392017-08-14

    Make sure you have the right baud rate. 115200.

    I fixed my issue buy reinstalling the driver and rebooting. Anyhow I re-coded to upload the data to weather underground so I can use their mobile app and use their servers to do the logging. Did away with the ldr and rain sensor and plan on adding an anemometer and wind direction in their place.

    WannaDuino (author)brandon281392017-05-16

    WELL done sir.

    can you please post the code? thank you

    JacobS162 (author)brandon281392016-07-16

    I had this same problem and found out that the baud rate in the serial monitor needs to match the upload speed of my board (Tools> Upload Speed).

    WannaDuino (author)2017-05-16

    Hello

    Very well made sir, byI am amazed, you shut put a lipo in it for portable uses.

    And maybe check if you can talk to an APP or so.

    But i have a question about you ripping the onboard led out! why did that?

    you could just add the NEW led on pin 4 if i am right that is exact the same output as that led. ( you drive it from a home power source ) and no lipo so it will not affect anything. so yeah i did not understand that action?

    I like it

    Ingenerare (author)WannaDuino2017-05-28

    uhm... i riped the led off as i planed to power the project from battery and those leds use great amounts of power. when i knew that a battery was to weak to power the station for more than a few days i decided to power it with a wall adapter. Is the led on the node the same as pin 4? didnt know that... so when i connect a led to pin 4 it will blink?

    WannaDuino (author)Ingenerare2017-06-22

    yep, with the simple blink sketch, you can test it.

    but for battery use, i get it of corse, put it in DEEP SLEEP mode.

    i made a similar ESP8266 wifi Magnetic reedswitch door alarm, in deep sleep mode and it gives also the correct batterie voltage when it`s waking up, it's a magnetic door alarm disguised in a wifi SMS MAIL alarm, or other way around.LOL.

    and as you see, i LOVE the ESP8266 chips

    jerry.ericsson2 (author)2017-05-17

    Is there a way a fellow an bypass the internet, and simply set up two esp8266's with one broadcasting the weather from outdoors, the other receiving and reporting both the indoor and outdoor weather on a nice small color screen?

    I am sorry that i can not tell you how to set up a esp as a LAN connetion. I think there are some instructables of people that just show the data of their wheater station in their browser (most of the time without memory or nice graphs). The only thing you need then is getting this data of the IP of the nodemcu. ps. you can also use a RF module https://www.instructables.com/id/Weather-Monitor-1/

    AlmirL1 (author)2017-02-07

    Hi,

    First of all, congratulations for the project. The maximum voltage supply of the digital inputs of the ESP8266 is 3,3V. And the LDR, LM35, and others sensors need a voltage supply equals 5V.

    How did you fix it? Did your project work well?

    Thank you!

    Ingenerare (author)AlmirL12017-05-28

    Hi Almir, thanks for the question. The esp module on the node mcu runs on 3.3 indeed but the nodeMCU has a power regulator on board so that it can run on 5V. The sensors can manage the power as far i know, when not you can connect them to the 3.3V pin on the Node board

    KobusT1 made it! (author)2017-02-16

    I made it! (without a rain sensor and with a DHT11) I must admit that I battled at first with the Arduino IDE part, and had to do some serious research before I was able to connect my NodeMcu (v1.0 12E) to the Arduino IDE.

    As you will notice, I made my weather station mobile by adding a 2000 mAh battery that can be re-charged. The bty life is about 12 hours and provides 3.7V that seems to be sufficient to drive all the sensors.

    TO DO: 1. put weather station in weatherproof housing. 2. Replace DHT11 with DHT22. 3. Add rain sensor. 4. Get 5000 mAh battery.

    Thanks Ingenerare in electronics.

    Ingenerare (author)KobusT12017-05-28

    cool looks great, please upload a picture when you have the enclosure

    JohnL183 (author)2017-05-15

    Has anyone connected this to a WeatherUnderground account?

    ve3vxy (author)JohnL1832017-05-16

    I was just thinking about that I do use WeatherUnderground but all of these Instructables I find use this Thingspeak site of which i not a fan of. I really like the projects that are found here but that ends fast with this Thingspeak thing, Owell so be it

    scubajoe63 (author)JohnL1832017-05-16

    I have the same question/request

    Moschtertaart (author)2017-05-16

    Wouldn't it be better to use an other power supply (battery) to be able to put the module in the shade on the east side of a building to have more accurate temperature values?

    kavish laxkar (author)2017-05-12

    cool

    ParampreetS1 (author)2017-04-18

    Hello! I have used this code for connecting my BMP180 to ESP8266 12. But unfortunately, I am not getting Pressure Value. I am getting following vale. I want to know how will we gonna set D1 and D2 pins to BMP180 sensor. Please help me out.

    <<stack<<<

    ets Jan 8 2013,rst cause:2, boot mode:(3,6)

    load 0x4010f000, len 1384, room 16

    tail 8

    chksum 0x2d

    csum 0x2d

    v60000318

    ~ld

    Failed to read from BMP sensor!!

    pingouin_ (author)2017-03-01

    Hello !

    Thanks for sharing :)

    Is there a specific reason why you used a BMP280 and a DHTxx instead of a BME280 that includes pressure, temp and humidity ?

    moonlight0551 (author)2017-02-28

    Nice instructable. Easy to follow and great intro to Thingspeak. Just need to put it outside in a suitable enclosure. Thanks.

    Laurent_J (author)2016-12-20

    Forget my precedent message, issue is solved.

    Laurent_J (author)2016-12-20

    Hi,

    Thanks a Lot for this great project. I'm just trying to make it working here, only with a DHT11 plugged at this time.

    The arduino IDE gives me this error code :


    compilation terminated.

    exit status 1
    Error compiling for board NodeMCU 1.0 (ESP-12E Module).

    Have you got an idea of what's going wrong ?

    Thanks

    Laurent

    lfzuluaga (author)2016-12-15

    https://thingspeak.com/channels/202780

    lfzuluaga made it! (author)2016-12-15

    Buen proyecto!!!

    bruster999 made it! (author)2016-06-09

    Great instructions! I made it in about 2 hours thanks to you filling in a lot of the blanks and providing code.

    Ingenerare (author)bruster9992016-06-13

    Nice to see that you made it! how cool is it! Do you have accurate readings? is it comparable with my thingspeak channel?

    bruster999 (author)Ingenerare2016-06-13

    Thx. Didn't really compare it to your channel yet but it seems to be accurate based on other sources such as the weather report and other (commercial) sensors I have. I have it monitoring my attic as I'm concerned about heat buildup. If you're curious I've made a public ThingSpeak channel that has the output plus a couple of cool Google gauges.
    https://thingspeak.com/channels/123447
    Bruster

    Ingenerare (author)bruster9992016-06-13

    Hi Bruster,

    I need your help! How did you put the gauges public! I surched everywhere how to do this and even posted a topic on the thingspeak community http://community.thingspeak.com/forum/general/can-not-add-visualisation-to-public-page/ Can you please tell me how you fixed this!?

    bruster999 (author)Ingenerare2016-06-13

    Sure. All I did was set the channel to be public in the "Channel Settings" section then in the Apps/Plugins/<myplugin> section (where you modify the code for the plugin) I set the "Make Public" checkbox then just below that I added a check for "Private View" and "Public View" in the "Add this visualization to a Channel". As far as i know this should work for anyone.

    Ingenerare (author)bruster9992016-06-16

    Mmmm, I tried to figure it out but with no succes. Can I send you a printscreen of my thingspeak section (where i modify the code for the plugin) by email? I think this option is missing or so. I send you a PM

    Ersin494 (author)Ingenerare2016-12-09

    can you make it public?

    RobertM456 made it! (author)2016-06-16

    This is a fantastic introduction to home automation and relatively easy to complete. I didnt add the rain sensor as I live in England where it usually rains haha. I will probably add the light sensor at a later date. Very happy with the project! :)

    Ingenerare (author)RobertM4562016-06-16

    Thnx! looks good. I think you can plug in the DHT22 sensor without wiring as you use a board that includes the resistor. If I`m right the power, ground and D4 pins are next to eachother on the 1.0 board

    RobertM456 (author)Ingenerare2016-06-17

    I'm using the V3.0 board so it won't work that way. Also I will eventually put it in some kind of box like yours so its probably better to have the sensors loose for the moment. Thanks for the tip anyway! :)

    mcapocchione (author)RobertM4562016-07-27

    I also have the NodeMCU v3.0 board from Lolin producer (it's larger than "original" nodemcu v1.0) but I can't upload any sketch with Arduino. Can you help me? I think it's a problem about baud rate or something... Thank you

    chupo_cro (author)mcapocchione2016-11-23

    Set the Upload speed (baud rate) in Arduino IDE > Tools to 115200, press and hold the Flash button on the NodeMCU and then plug the USB cable or press and hold the Flash button and press&release the Reset button while the USB cable has already been plugged. Now you can program the board. Change

    Serial.begin(115200);

    to:

    Serial.begin(74880);

    and choose 74880 baud for the Serial Monitor (drop-down menu in the lower-right corner) so you can see not only the messages sent from the code but even the error&restart info messages sent by ESP8266 itself.

    If NodeMCU disconnects-reconnects-disconnects-reconnects... from the USB then you can power the board by the phone charger and connect USB to serial adapter to TX/RX pins to see the messages or you can just ignore the Serial port. LoLin boards seem to have disconnect-connect problem when using serial port, I have 2 of them and both have the same problem but sometimes, after 10-15 resets (by pressing the Reset button) they start to work normally.

    AxitV2 (author)2016-11-07

    I am trying to read input from switch at pin D8 of node mcu v1, but can not read it for some reason. Any suggestion on it.?

    I already have used other gpio for the projects

    Thank you in advance!

    RizalA15 (author)2016-11-02

    Thank you so much sir :)

    mahirk8 (author)2016-10-29

    I used the same code but substituted with my api, ssid and password and now i'm getting connection to thingspeak failed. Any ideas?

    JohnS911 (author)2016-10-11

    Yes, and use an Adafruit's specialized USB / Solar Lithium Ion Polymer Battery Charger! with a 6V 3.4W solar panel with a Lithium ion battery pack - 3.7V 6000mAh

    vaxus (author)JohnS9112016-10-12

    Oooo, thanks. I found that Adafruit's board.

    .... BUT, It is so expensive (17 usd direct or 30 euro on Amazon.de) !!!!

    I rather consider to take a ready accu+integrated solar panel for 15 euro, available also in outdoor waterproof package.

    Have you considered that ?

    vaxus made it! (author)2016-10-10

    Thanks a lot!!! I followed instructions and had a great experience with my first IoT project.

    Unfortunatelly it did not work as-is, while:

    1. I used the only DHT11 sensor and no other - script was not working at runtime

    2. some libraries were not loadable as per instuction, needed to play around

    Overall was original Instructables are great!!!

    I posted my personal Instructables with missing (or corrected) steps, tested with 2 boards (ESP12E DEVKIT V2, NodeMCU AMICA)

    You can find mine here:

    http://instructables.com/id/Easy-IoT-Weather-Station-With-Multiple-Sensors-enc

    MattiaGrazia (author)2016-10-03

    how can i change the update interval of each sensor? e.g 1 read per hour,,, ty

    bijoybarua01 (author)2016-09-28

    i want to add "soil sensor" in here, how to add soil sensor, can u help me?

    JohnS911 made it! (author)2016-09-25

    Built with an Adafruit Feather Huzzah with ESP8266 and a LiPoly battery.

    Thanks for tutorial.

    AmiyaK made it! (author)2016-09-19

    Works really great. My first IoT project. Thanks for tutorial.

    Ingenerare (author)AmiyaK2016-09-20

    You are welcome!

    About This Instructable

    108,878views

    1,059favorites

    License:

    Bio: The term, engineering originates from the Latin word Ingenerare, which means "to create". My name is Vincent and I am a graduating student in the ... More »
    More by Ingenerare:Turn me on, an ATtiny RGB mood lampEasy IoT Weather Station With Multiple Sensors Multiple analog inputs using one analoge pin
    Add instructable to: