SPEC DGS sensors: new firmware, new behaviour


Yesterday I managed to damage the DGS-H2S sensor I used in my projects. No big deal, I dropped in on the floor, and the sensor broke. While I wait for a replacement sensor to arrive, I tried to work with a spare one, a new sensor that I plan to put into a permanent location.

SURPRISE!!! The new sensor didn’t work!

I expected that SPEC DGS sensors are drop-in replacements, but I was proven wrong. After a day of investigating this issue, I realized that there are two firmware versions of the same sensor, and each firmware comes with its features. To make matters more complicated, there is no marking on the sensor itself to tell the firmware version. Furthermore, all documentation on https://www.spec-sensors.com/ is for the old firmware.


But, here is what I have found about the new version:

Checking the firmware version of the sensor

To check the firmware version of the sensor one has to connect it to an Arduino Due or an Arduino Uno board, as described in my previous projects, and then run the SerialPassthrough Arduino sketch.

Open serial monitor, then configure it to send only the carriage return.

DGS-H2S - checking firmware version

DGS-H2S – checking firmware version

Reset the sensor by sending ‘r or ‘R. Then try to rapidly send several times the character ‘f’ (lower-case f, without quotation marks), until the sensor responds. If the sensor has the new firmware, it will respond with ‘15SEP17′.  If you have the old version, you will trigger a measurement, and then it will respond with ‘14FEB17′.

Oh, and the SPEC-DGS library is for the firmware version 25SEP17.

New firmware, new behavior

Some issues and features I have found so far in the new firmware:

  • When started, the first thing to do is reset the sensor by sending ‘r’ or ‘R’
    • The reset works by executing a while(1); loop and waits for the watchdog to reset the sensor. After issuing the reset command one needs to wait for about one second.
  • The sensor no longer expects the unlock code 12345/r
    • Setting the zero value is simply performed by sending ‘Z’. The sensor will respond with “Setting zero…done”
  • Triggering a single measurement works by sending ‘\r’ only
  • One can instead put the sensor in continuous mode by sending ‘c’.
  • continuous mode is stopped with c’.
  • Continous mode is one second only
  • The sensor is much faster!!!
  • There is a new command ‘A‘ which configures the sensor to perform the average of a given number of measurements. To use this feature, send ‘A‘ , without ‘/r’. The sensor will respond with “Enter Average Total:”. Insert the average value (between 1 and 300), followed by ‘/r’. If successful, the sensor will respond with ‘/r/n’
    • The response time of the sensor changes according to the average value. While triggering a single measurement by sending ‘/r’, the sensor responds in 287ms if A=1, and in 375ms if A=300.
    • You can check the Average_Total value in the EEPROM dump, by sending ‘e
    • Recommended values are least 60 for O3/NO2/H2S and 300 for SO.
  • There is a sleep command, ‘s‘. Wake up the sensor by sending anything on the serial port. Wait for about one second, then you can issue commands.
    • The sensor draws 4.2mA in normal mode. In sleep mode it needs only 26μA.

New Arduino code

Below is a code version that I have tested with Arduino Due.

// SPEC H2S Sensor demo code
// This code works with sensor firmware 15SEP17

// #define SERIAL1_RX_BUFFER_SIZE 256
// #define SERIAL1_TX_BUFFER_SIZE 256

// Sensor values
  // The format of the output is: SN[XXXXXXXXXXXX], PPB [0 : 999999], TEMP [-99:99],
  // RH[0:99], RawSensor[ADCCount], TempDigital, RHDigital, Day[0:99], Hour [0:23]
  // Note that on Arduino Due integer variable (int)  stores a 32-bit (4-byte) value. 
  // This yields a range of -2,147,483,648 to 2,147,483,647 
  // (minimum value of -2^31 and a maximum value of (2^31) - 1). 
  // On 8 bit boards some readings have to be recorded as floats

String SensorSerialNo; 
int H2S;
int Temperature;
int RH;
int RawSensor;
int TempDigital;
int RHDigital;
int Days;
int Hours;
int Minutes;
int Seconds;

#define command_delay 500
#define start_delay 2500
String dataString = "";
String responseString = "";
boolean dataStringComplete = 0;
char inChar;

void setup() {
  // Wait for serial port
  Serial.println("SPEC DGS-H2S sensor demo code!");
  // Normally, data is returned within one second
  // reserve 80 bytes for the dataString
  // Wait for sensor 
  Serial.println("Resetting sensor");
  // Print firmware version

  // EEPROM dump
  Serial.println(" ");
  Serial.println("STARTING MEASUREMENTS");
  Serial.println(" ");

void loop() {
  // Do a readout every 10 seconds

/* ********************************************************************************
 * This function triggers one measurement and receives the data from the sensor
void SPEC_Data_read(){
  // First, we do some initialization
  // dataStringComplete is set as "false", as we don't have any valid data received
  dataStringComplete = 0;
  // Clear the data string
  dataString = "";
  // Now we trigger a measurement
  //Serial1.print(" ");
  // We wait for the sensor to respond
  dataString = Serial1.readStringUntil('\n');

/* ********************************************************************************
 * This function takes the received string and upodates sensor data
void SPEC_parse_data(){
  // Parses the received dataString
  // Data string is comma separated
  // The format of the output is: SN[XXXXXXXXXXXX], PPB [0 : 999999], TEMP [-99:99],
  // RH[0:99], RawSensor[ADCCount], TempDigital, RHDigital, Day[0:99], Hour [0:23],
  // Minute[0:59], Second[0 : 59]\r\n
  // Take a look also at
  // https://stackoverflow.com/questions/11068450/arduino-c-language-parsing-string-with-delimiter-input-through-serial-interfa
  // We look first for the SN
  int idx1 = dataString.indexOf(',');
  SensorSerialNo = dataString.substring(0, idx1);
  int idx2 = dataString.indexOf(',', idx1 + 1);
  // Hint: after comma there's a space - it should be ignored
  String S_gas = dataString.substring(idx1 + 2, idx2);
  H2S = S_gas.toInt();
  int idx3 = dataString.indexOf(',', idx2 + 1);
  String S_temp = dataString.substring(idx2 + 2, idx3);
  Temperature = S_temp.toInt();
  int idx4 = dataString.indexOf(',', idx3 + 1);
  String S_humi = dataString.substring(idx3 + 2, idx4);
  RH = S_humi.toInt();
  int idx5 = dataString.indexOf(',', idx4 + 1);
  String S_raw_gas = dataString.substring(idx4 + 2, idx5);
  RawSensor = S_raw_gas.toInt();
  int idx6 = dataString.indexOf(',', idx5 + 1);
  String S_Tdigital = dataString.substring(idx5 + 2, idx6);
  TempDigital = S_Tdigital.toInt();
  int idx7 = dataString.indexOf(',', idx6 + 1);
  String S_RHdigital = dataString.substring(idx6 + 2, idx7);
  RHDigital = S_RHdigital.toInt();
  int idx8 = dataString.indexOf(',', idx7 + 1);
  String S_Days = dataString.substring(idx7 + 2, idx8);
  Days = S_Days.toInt();
  int idx9 = dataString.indexOf(',', idx8 + 1);
  String S_Hours = dataString.substring(idx8 + 2, idx9);
  Hours = S_Hours.toInt();
  int idx10 = dataString.indexOf(',', idx9 + 1);
  String S_Minutes = dataString.substring(idx9 + 2, idx10);
  Minutes = S_Minutes.toInt();
  int idx11 = dataString.indexOf('\r');
  String S_Seconds = dataString.substring(idx10 + 2, idx11);
  Seconds = S_Seconds.toInt();

/* ********************************************************************************
 * This function prints the sensor data
void SPEC_print_data(){
  Serial.print ("Sensor Serial No. is ");
  Serial.println (SensorSerialNo);
  Serial.print ("H2S level is ");
  Serial.print (H2S);
  Serial.println (" ppb");
  Serial.print ("Temperature is ");
  Serial.print (Temperature, DEC);
  Serial.println (" deg C");
  Serial.print ("Humidity is ");
  Serial.print (RH, DEC);
  Serial.println ("% RH");
  Serial.print ("Sensor is online since: ");
  Serial.print (Days, DEC);
  Serial.print (" days, ");
  Serial.print (Hours, DEC);
  Serial.print (" hours, ");
  Serial.print (Minutes, DEC);
  Serial.print (" minutes, ");
  Serial.print (Seconds, DEC);
  Serial.println (" seconds");
  Serial.println ("Raw Sensor Data");    
  Serial.print ("Raw gas level: ");
  Serial.println (RawSensor);
  Serial.print ("Temperature digital: ");
  Serial.println (TempDigital);
  Serial.print ("Humidity digital: ");
  Serial.println (RHDigital);
  Serial.println ("");

/* ********************************************************************************
 * EEPROM dump
void SPEC_dump_EEPROM(){
  dataString = Serial1.readStringUntil('\n');
  // You can uncomment this line if you wish
  for (int i=0; i<20; i++){ 
    responseString = Serial1.readStringUntil('\n');

void SPEC_reset(){

void SPEC_show_firmware(){
  responseString = Serial1.readStringUntil('\n');
  Serial.print("Sensor firmware version is ");

void flush_serial1(){
  // Do we have data in the serial buffer?
  // If so, flush it
  if (Serial1.available() > 0){
    Serial.println ("Flushing serial buffer...");
      inChar = (char)Serial1.read();
      if (inChar == '\n') break; 
    Serial.println (" ");
    Serial.println ("Buffer flushed!");




  1. Avatar

    I am trying since several days to use the sensor (968-036 Hydrogen Sulfide (H2S) Sensor USB) with firmware 15SEP17 with Arduino Due – as per your example but using the NativeUSB port. It simply does not return any data from sensor. I checked and the sensor is powered. On the USB connection directly to Teraterm, the sensor is working fine. The sensor has direct USB output. I tried Serial Passthrough using SerialUSB and still nothing.
    What else should I try?

  2. Avatar

    Hello, Teodor! I got it finally working tonight, by not using SerialUSB or Serial ports (the USB ports on the Due board) but using the Serial1 and direct connection of the sensor to pins 18/19. Although I changed several cables and adapters it seems that the UART to USB adapter the sensor was delivere with only works with the laptop (?) and not the Arduino Due board.

    I tried to use your suggestion – but “Serial” was already the programming port connected to my computer, the “SerialUSB” did not work and so on.

    I will look into opensensebox in the next days to pin it on the dynamic map, but I’ll have to add some wifi module to publish the H2S level.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.