A homebrew Temperature and Humidity sensor that posts reading over MQTT


Since i'm crazy in Home Automation i wanted to log the Temperature and Humidity in and around my house and cabin.

I have previously designed and soldered my own circuits and PCBs for this purpose, but wanted to move quickly from prototype to something that worked (in lack of spare time), so therefor i settled for the LOLIN Wemos D1 mini board with a SHT30 shield that could easily be ordered online for a few dollars.

As soon as i received the boards, hooked them up and pushed some sample code to them... I realized that the measured temperature is very high compared to what I had expected. It turns out that the high sensitivity of the SHT30 sensor easily gets affected by the relatively high-power ESP8266 chip :-(

The quick solution is to make sure that the ESP8266 chip is put into deep-sleep mode as much as possible to prevent it from heating up. And on top of this also make sure that when we wake up the ESP8266 chip, we sample the SHT30 sensor as quickly as possible to further lower the risk of heat-up.

The full code can be found on github at https://github.com/niklaswall/ESP8266-SHT30-MQTT.


Open up the src/setup.h file to do the initial configuration.

// SSID and PASSWORD for wifi connection
#define WIFI_SSID "default"
#define WIFI_PASSWORD "password"

//  MQTT Endpoint and credentials
#define MQTT_SERVER "mqtt1.iothingy.com"
#define MQTT_CLIENT_NAME "outdoor-sensor"
#define MQTT_USERNAME "username"
#define MQTT_PASSWORD "password"

// Topics for the temperature and humidity
#define MQTT_TOPIC_TEMP "home/sensor/outdoor/temperature"
#define MQTT_TOPIC_HUMID "home/sensor/outdoor/humidity"

// Publishing rate in seconds
#define PUBLISH_RATE 1 * 50

// Debug to serial port
#define DEBUG false

24h of temperature

My MQTT receiver has a hook that captures all values that matches specific topics and automatically created InfluxDB time series for that topic. This makes it very easy to later graph any sensor value to get a better understanding of the differances over time.

SHT30 Temperature Graph