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.
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.
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:
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
The username and password is found on the URL of the MQTT channel. For example, if this is your URL: mqtt://7fb2fd2f:email@example.com ( found in namespace settings). Your username is 7fb2fd2f and the password is b9f1e26ae8d3dac8.