Home / Projects / ESP8266 Projects / NodeMCU IoT Environment Monitor

NodeMCU IoT Environment Monitor

Project Overview

This NodeMCU IoT project is a simple demonstration on how to send sensor data to the Internet. Powered by a NodeMCU ESP8266 microcontroller, this project is able to show temperature, humidity and atmospheric pressure to any MQTT subscriber.


Using MQTT is much faster than using HTTP because of reduced overhead. In fact, MQTT is one of the preferred protocols for Internet of Things.

To use MQTT, we need a broker and there are lots of them! For this project, I used Shiftr.IO. I already detailed how to use the MQTT protocol with the NodeMCU so kindly check that out first.


For temperature and humidity, I used SHT1x from DFRobot. For the atmospheric sensor, I used the old reliable BMP085. My Arduino BMP085 tutorial covers how to use this sensor with the Arduino. The NodeMCU uses the same Arduino IDE and code as long as the ESP8266 core is installed.

Another requirement for this project is a free account in Shiftr.IO. I’ve created an “environment-monitor” channel in Shiftr and was promptly given username and passwords which is needed when connecting to the broker.

Also, the MQTT library is required and is downloadable here. Finally, you’ll be needing the SHT1X library and the BMP085 library, both of which (thankfully) are NodeMCU-compatible.

Wiring Diagram

The SHT1X library uses software SPI while the BMP085 uses I2C.

The default I2C pins of the NodeMCU are D1 (SCL) and D2 (SDA) or GPIO5 and GPIO4. Naturally, the BMP085’s SDA and SCL pins should be connected to those pins. As for the the SHT1X, I decided to use the D3 and D4 pins for clock and data respectively.

Here is the Fritzing diagram:

NodeMCU IoT Environment Monitor Wiring Diagram

Arduino Sketch

The sketch is similar to that in my MQTT tutorial. The first part of the sketch is establishing the WiFi connection. Then, we connect to the MQTT broker through

Next, I connected to the MQTT channel using

The username and password is found on the URL of the MQTT channel. For example, if this is your URL: mqtt://7fb2fd2f:[email protected] ( found in namespace settings). Your username is 7fb2fd2f and the password is b9f1e26ae8d3dac8.

To publish data, I used

There is no need to create the /temperature topic as it’s automatically created once you call the function above. Of course, you can publish multiple topics:

Anyway, here’s the full sketch:

The sensor data is published every second.


Here’s some pictures of my actual setup:

I had to go from the computer to take better pictures, hence the project is powered by a small power bank. It will still run drawing power from a computer.


Project Files

I provided the project files for anyone who want to replicate this project:

Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *