H2S sensing revisited: using the sensor with Arduino Uno

26

Ever since I wrote the blog post on sensing hydrogen sulfide using Arduino Due, I have received a lot of comments and messages about using the sensor with the more popular Arduino Uno.

To use the sensor with the Arduino Uno, one must overcome two issues. The first issue relates to the fact that the sensor uses 3.3V logic and power, while the Arduino Uno is a 5V board. The second issue lies in the fact that Arduino Uno has a single serial port, and that post is commonly used for debugging.

Overcoming these two issues is relatively easy.

To solve the logic level issue, one can take 3.3V power from the Arduino Uno and use a logic level converter like BOB-12009 from Sparkfun.

Then, one can rely on using SoftwareSerial to create a emulate a second serial port in software, and make some minor changes in the code to accommodate this. Please note that SoftwareSerial doesn’t work on all Arduino pins. In my code example I used pins 10 and 11, but if you wish to change that, do read first the documentation and make sure the pins are supported by the code library.

For this example, I have connected the H2S sensor as follows:

Connecting the H2S sensor to Arduino Uno

Connecting the H2S sensor to Arduino Uno

The logic level converter receives 5V (orange wire) and 3.3V (red wire) from Arduino Uno. The 3.3V voltage also goes to pin 8 of the H2S sensor.

GND (blue wire) runs from Arduino Uno to the logic level converter and then to the H2S sensor.

Pin 11 runs to the HV4 pin of the logic level converter. Its counterpart LV4 is connected to pin 2 (RXD) of the H2S sensor. Later, in the code, this pin will become SoftwareSerial TX.

Pin 10 runs to the HV3 pin of the logic level converter. Its counterpart LV3 is connected to pin 3 (TXD) of the H2S sensor. Later, in the code, this pin will become SoftwareSerial RX.

This is how the connections are made on a breadbaord. I used the same colors of wire as in the above diagram, to make things easier to follow:

Arduino Uno connections to H2S sensor

Arduino Uno connections to H2S sensor

If you don’t want to dig into the datahsheet of the sensor, here is a detailed image of the H2S sensor connector:

H2S sensor pinout

H2S sensor pinout

From top to bottom we have:

pin 1 – N/C
pin 2 – RXD
pin 3 – TXD
pin 4 – N/C
pin 5 – N/C
pin 6 – GND
pin 7 – N/C
pin 8 – V+ (2.6 to 3.6V)

H2S sensing with Arduino Uno: the code

The code is the same as in the original blog post, with only minor changes to accommodate SoftwareSerial:

That’s all folks!

Share.

26 Comments

  1. Avatar

    What is going on in your physical wiring with both the 5V and 3.3V pins from the Arduino going to the same outer rail track, and the red wire on the inner rail track connecting to the same inter rail? I’m throughly confused.

    • Teodor Costachioiu
      Teodor Costachioiu on

      5v goes to outer rail
      3.3v goes to inner rail (the angle of the wire is a bit misleading)
      on breadboards from wishay the rails are split in half, tbat’s why the short red wire connecting the inner rails

      • Avatar

        So the 3.3v pin from the Arduino is going to the inner track? Now that makes sense.

        If one were to use a nodencu or similar ESP8266 3.3V device, there would be no need to use a logic level converter, right? And if it has WiFi you wouldn’t have to bother with even using SoftwareSerial as you could use MQTT or webhooks to display your output.

  2. Avatar

    For anyone wondering, the reason you need to use this logic converter is because the RX/TX pins work on 5v, which will fry your sensor. It’s probably easier to just get a 3.3v controller and use that.

  3. Avatar

    Thank you for your posting.
    I have one question. What kink of wire you used for connection?
    I have one but it is so weak to connect each other.

      • Avatar

        Thank you for reply.
        I bought all of things you used above and assembled.

        Unfortunately, it didnt work when i upload code to arduino uno. I dont know why….and it seems to be wrong that mismatch rx pin between in the picture and code you wrote (dgs h2s sensor used rx pin 2nd place where green wire stuck to digital 11, but code used 10 for rx)

        Can i ask why you used level converter though arduino uno can provide 3.3v output? Is it important?

        Regards.

        • Teodor Costachioiu
          Teodor Costachioiu on

          Arduino Uno can provide 3.3V power, but it uses 5V logic levels. That means, on (software) TX and RX pins you will have 5V for logical “1”. The H2S sensor uses 3.3V logic, thus the need for the logic level converter.

          If it doesn’t work, you can try to swap TX and RX lines.

  4. Avatar

    TEODOR

    Thank you for taking the time to write this. I was thinking of making a similar project but I dont have the programming skills for it. I appreciate that you made public your efforts

  5. Avatar
    Breno Galendi on

    First of all, thank u for this tutorial!

    Well, i’m having some issues with my project…
    My sensor keeps returning no data, no matter what i change on it…

    Everything is the same as is described in your tutorial, but the final results aren’t

    Thanks again!

    • Teodor Costachioiu
      Teodor Costachioiu on

      Hi Breno,

      The easiest thing to do is run the SerialPassthrough sketch and communicate directly with the sensor. Try to send a c character, that should trigger a new measurement and you should see some output. If not, check connections. Also, try to reverse the RX and TX lines.

      Also, please observe that not all Arduino pins can be used with SoftwareSerial. See the library notes on https://www.arduino.cc/en/Reference/softwareSerial. My choice of pins 10 and 11 is not random.

      You may also wish to take a look to this new DGS sensor library: https://github.com/SPEC-Sensors/DGS

  6. Avatar

    thank you for this tutorial! …
    I have one question which of gas sensor gives accurate results for H2S gas. ?

Leave A Reply