Don’t trust a plumber, “Trust in Arduino” – Hydrogen Sulfide Gas Detector

Some time ago I had nasty smells in my kitchen and no I didn’t leave an egg salad on the table for a few weeks or a bucket of prawns in the sun… The smell was hydrogen sulfide or commonly know as sewer gas. My first step was to get a plumber in to try and trace the issue, it was intermittent and not constant so it was quite difficult to pinpoint. To me it was an issue with the venting of the outside main sewer link into my house but the plumber assured me that the venting was done fine as he worked on the house originally when it was renovated. About once a day, usually in the mornings we got this horrific stink only for a few minutes or so. Not trusting the plumber after all this I decided to look into Gas Sensors and found the Figaro TGS 2602 sensor which does loads of other gasses apart from hydrogen sulfide see data sheet I bought a bunch of these and hooked them up to Arduino UNOs and placed them all over the house. Well believe it or not the first sensor to go off was not in my kitchen but in my attic and as hydrogen sulfide is a heavy gas I was in a quandary. So I had a look inside the roof to attic cavity and lo and behold the vent pipe did not go out onto the roof. This meant that the gas while heavy was going down the wall cavity three flights and under the kitchen floor to the other side of the room. Problem solved, plumber on end of angry phone call….

I threw the design into Fritzing to share to all for the next time your plumber is a lazy #*^%$# and won’t look in the roof.

Full project is here

Here is the Fritzing part for the 2602 gas sensor Download

I used an xbee shield on the Arduino UNOs so I could do it wirelessly around the house with multiples. I won’t go into how to setup an xbee mesh try here

The base code is simple

int gasSensor = 0; // select input pin for gasSensor
int val = 0; // variable to store the value coming from the sensor

void setup() {

void loop() {
val = analogRead(gasSensor); // read the value from the pot
Serial.println( val );

Lets link it to Pachube so I can monitor it on my iPhone. This requires another Arduino UNO with an xbee and an Arduino Ethernet Shield. See

#include <SPI.h>
#include <Ethernet.h>

// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// assign an IP address for the controller:
byte ip[] = {
10,0,1,95 };
byte gateway[] = {
byte subnet[] = {
255, 255, 255, 0 };

// The address of the server you want to connect to (
byte server[] = {
173,203,98,29 };

// initialize the library instance:
Client client(server, 80);

long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const int postingInterval = 10000; //delay between updates to

void setup() {
// start the ethernet connection and serial port:
Ethernet.begin(mac, ip);
// give the ethernet module time to boot up:

void loop() {
// read the analog sensor:
int sensorReading = analogRead(A0);

// if there’s incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c =;

// if there’s no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {

// if you’re not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() – lastConnectionTime > postingInterval)) {
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();

// this method makes a HTTP connection to the server:
void sendData(int thisData) {
// if there’s a successful connection:
if (client.connect()) {
// send the HTTP PUT request.
// fill in your feed address here:
client.print(“PUT /api/feeds/14050.csv HTTP/1.1\n”);
// fill in your Pachube API key here:
client.print(“X-PachubeApiKey: 069557631a9d5ee274840079dc8ea66c2c2758b0cdfeeae6f1c730f7f366a215\n”);
client.print(“Content-Length: “);

// calculate the length of the sensor reading in bytes:
int thisLength = getLength(thisData);
client.println(thisLength, DEC);

// last pieces of the HTTP PUT request:
client.print(“Content-Type: text/csv\n”);
client.println(“Connection: close\n”);

// here’s the actual content of the PUT request:
client.println(thisData, DEC);

// note the time that the connection was made:
lastConnectionTime = millis();
else {
// if you couldn’t make a connection:
Serial.println(“connection failed”);

// This method calculates the number of digits in the
// sensor reading. Since each digit of the ASCII decimal
// representation is a byte, the number of digits equals
// the number of bytes:

int getLength(int someValue) {
// there’s at least one byte:
int digits = 1;
// continually divide the value by ten,
// adding one to the digit count for each
// time you divide, until you’re at 0:
int dividend = someValue /10;
while (dividend > 0) {
dividend = dividend /10;
// return the number of digits:
return digits;

Create the Page

<?xml version=“1.0” encoding=“UTF-8”?>

<html xmlns=“” xml:lang=“en”>
        <title>Gas Sensor Hydrogen Sulfide</title>

<script type=“text/javascript” src=“”></script><script language=“JavaScript” src=“”></script><script language=“JavaScript”>createViz(14050,0,600,200,”FF0066”);</script>


Pachube Output




Breadboard layout




Your done!

Enjoy smell free air 🙂



One thought on “Don’t trust a plumber, “Trust in Arduino” – Hydrogen Sulfide Gas Detector

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s