H2S IoT monitoring node with ESP8266 and openSenseMap

Jul 19, 2019 0 comments

In this blog post, I will show you how to build an IoT H2S monitoring node based on SPEC DGS-H2S sensor and ESP8266, and how to upload the data to openSenseMap. The same approach should work with other digital gas sensors from SPEC Sensors such as DGS-NO2, DGS-O3, and DGS-CO, with only minor changes in the code.

To publish the gathered data, I will use the openSenseMap cloud platform. There are two reasons for choosing this platform:

  • It is a map-centered cloud platform, allowing me to show the position of my IoT node on the map. Visitors can navigate the map and see what sensors are available in their area of interest
  • The sensor data is explicitly accessible to anyone who wants to use it, under the Public Domain Dedication and License 1.0. Under this license terms you are free:
  • to Share: To copy, distribute, and use the database
  • to Create: To produce works from the database
  • to Adapt: To modify, transform, and build upon the database

If you wish to know more about what you can do with the data, you can read the full PDDL 1.0 license text for the exact terms that apply.

openSenseMap is an open data platform for location-related measurement data, developed by a team from the GI@School Lab at the Institute for Geoinformatics at the University of Münster.

The cloud service openSenseMap, along with the Arduino-based IoT node senseBox, facilitates the development of citizen science projects, allowing for the collection of data with do-it-yourself sensor stations — thus providing an accessible way to work with geographic information and environmental data.

The senseBox fact sheet states:

The senseBox was developed within a BMBF research project at the Institute of Geoinformatics at the University of Münster. The resulting project and research work have won several awards in the university competition of the Federal Ministry of Education and Research (BMBF) (2013, 2014 and 2016). In addition, the senseBox:edu received the special prize for Digital Learning and Teaching at the CeBIT Innovation Award 2017. In 2018 Reedu GmbH & Co KG was founded as a spin-off from the research project. Reedu ensures that further development and distribution of the senseBox scale with the increasing demand for citizen science tools in education and society. Reedu is supported by the Federal Ministry of Economics and Energy and the European Social Fund as part of the EXIST programme.
Not surprisingly, the largest number of stations that send data to openSenseMap is found in Germany. A large number on openSenseMap of IoT nodes are luftdaten.info PM2.5 and PM10 particle monitoring stations. Those can be configured to send the gathered data to openSenseMap with ease — but more about luftdaten.info in a future blog post.

With some browsing on the map, someone might find some interesting sensors. Some contributors publish pictures with their sensor nodes — a great source of inspiration.

My country, Romania, is almost blank. Even Bulgaria fares better 🙁

Various IoT nodes on openSenseMap

Creating an openSenseMap node

While the senseBox is the official hardware, one is not limited on using it — such as I will do with ESP8266 Thing dev. All I have to do is to configure the node in manual mode and change the code generated by openSenseMAp according to my needs. It sounds a bit complicated but, trust me, is not that difficult.

Before anything else, one needs to create an account with openSenseMap. Be sure to use a working email address — you will receive the Arduino sketch by email.

Once the account is created and the email address you have provided is verified, you can create a new senseBox. Below is a guide on how to create a new sensor box that uploads four variables:

  • H2S is the computed value, in ppm
  • H2S-RAW is the RAW ADC data. Combined with the temperature and humidity data, it can be later used to recompute H2S levels.
  • Temperature
  • Humidity

I will start by creating a new senseBox:

Then I give a name to my station, I select the exposure of the station (indoor/outdoor/mobile), and I place it on the map:

Then I will configure the station. In the next screen, I will scroll down to manual configuration:

Then I will click the “Add sensor” button to create the four new variables for the gas sensor.

In the next screen, I click “confirm” to accept the license terms for uploading the data.

Finally, I will be presented with a summary screen and the Arduino sketch will be generated and sent by email.

Write down the sennseboxID and the ID’s of each sensor — you will need them later.

This completes the creation of the sensor node. We can now proceed to build the hardware of the sensor.

openSenseMap H2S station — the hardware

I wanted to keep things as simple as possible and to create a sensor node that is as cheap as possible. So, my sensor uses one DGS-H2S digital gas sensor from SPEC Sensors, and one ESP8366 Thing Dev from Sparkfun.

The DGS-H2S sensor is featured in other articles; as such I won’t repeat the basics here. I mention only that this project works with sensors with firmware version 15SEP17 or 25SEP17. Sensors with firmware version 14FEB17 will require some changes in the part of the code that reads the sensor values. Regardless of the firmware version of the sensor, I recommend setting the averaging value A to 300, as this improves the noise profile. Also, be sure that the zero point of the sensor is set in clean air.

Regarding the ESP8266 board used, bear in mind that between the ESP8266 Thing and ESP8266 Thing Dev boards there are some significant differences — some hardware changes must be done to use ESP8266 Thing — part no. WRL-13231. The code will run on both boards with no changes in the software.

The schematic below is for the ESP8266 Thing Dev — part no. WRL-13711. Furthermore, to enable waking-up from deep sleep, I have installed the SJ2 jumper (it comes unpopulated).

If you plan to use this project on battery power, be advised that ESP8266 Thing Dev has no battery charger onboard — you will have to remove the battery and charge it with a separate charger when it discharges. As explained in this post, the upload of new data will be disabled if the battery goes below a certain threshold. Some might also wish to cut the SJ1 bridge on the bottom side of the board to disable the power LED.

With that being said, below is the connection diagram for the sensor node.

ESP8266 with DGS-H2S sensor

The connections are as follows:

  • DGS-H2S pin 8 V+ to ESP8266 pin 3V3 (red, 3.3V power)
  • DGS-H2S pin 6 GND to ESP8266 GND pin (green, GND)
  • DGS-H2S pin 3 TXD to ESP8266 pin 12 = SoftwareSerial RX (orange)
  • DGS-H2S pin 2 RXD to ESP8266 pin 13 = SoftwareSerial TX (yellow)

The following sketch can be used to communicate with the sensor using the Serial Monitor in Arduino IDE:

#include <SoftwareSerial.h> 
// RX = digital pin 12, TX = digital pin 13
SoftwareSerial portOne(12, 13);void setup() {
}void loop() {
  if (Serial.available()) {      
  // If anything comes in Serial (USB),
    // read it and send it out Serial1 (pins 0 & 1)
  }  if (portOne.available()) {     
  // If anything comes in Serial1 (pins 0 & 1)
    // read it and send it out Serial (USB)

And below are some images with a prototype of the sensor node:

openSenseMap H2S station — the code

Now that the hardware part is completed, it’s time to upload the code.

In the code below, you will have to replace the WiFi credentials. with your own.


You might notice that sometimes the sensor returns negative values. This is not wrong; it can be due to high levels of other gases such as NO2, ozone, and chlorine, as given in the table below.

I have decided to set a threshold for the minimum gas level to -50 ppm. Anything below this value won’t be sent to openSenseMap.

A typical two-day recording of H2S levels recorded by my station looks like this:

The measurement is quite noisy. Considering that the sensor is placed quite close to a 110kV power line, this might bring a significant contribution to the noisy data. In particular, I have noticed a big spike almost every day, at around 8.30 in the morning.

Using an ESP8266 Thing board

Finally, a few words about using ESP8266 Thing or similar boards: there are hardware differences that one must take into account.

The two boards are different, the ESP8266 Thing doesn’t have an FTDI chip, but it has a battery charger. Furthermore, the jumper onboard ESP8266 Thing is for auto control of GPIO0 during programming.

To use an 8266 Thing board, one must use an external 3.3V FTDI adapter. You will have to solder the FTDI VCC bridge on the back of the board to power the board from the FTDI adapter.

The power LED onboard the 8266 Thing cannot be disabled; you will have to physically remove it to lower power consumption.

And finally, you will have to connect the RST and GPIO16 (DTR and XPD pins) to enable waking up from deep sleep. Take care to remove the connection between DTR and XPD to program the board.

Related Posts


{{posts[0].date}} {{posts[0].commentsNum}} {{messages_comments}}


{{posts[1].date}} {{posts[1].commentsNum}} {{messages_comments}}


{{posts[2].date}} {{posts[2].commentsNum}} {{messages_comments}}

Contact Form


Email *

Message *

Recent Comments