Fart Detector with Fan/Ventilator Made with Arduino

I couldn’t wait to get my hands on Arduino and start playing with it. I ordered directly from Arduino and it finally arrived. I started to learn it with my first project: The Farting Detector with Ventilator.

Here is what you need to get it done:

Hardware

1. Arduino Board

Arduino Ethernet_Board

I got myself Arduino Ethernet with POE (power over ethernet):
http://store.arduino.cc/index.php?main_page=product_info&cPath=11&products_id=316  .
But you can achieve the same thing with much cheaper Arduino Uno:
http://store.arduino.cc/index.php?main_page=product_info&cPath=11&products_id=195 

2. Methane Sensor

FC-22-H mq-9 gas sensor

The model I used is FC-22-H (PCB board) which has MQ-9 gas sensor
http://dx.com/p/fc-22-h-combustible-gas-detector-sensor-module-for-arduino-179310#.Uue6k8Y1jsM (they take some weeks to ship it to Europe)

3. 433Mhz Radio frequency transmitter and receiver

433Mhz RR Receiver and Transmitter

http://dx.com/p/433mhz-rf-transmitter-module-receiver-module-link-kit-for-arduino-arm-mcu-wl-green-220194#.Uue6kMY1jsM

4. Remote Controlled Mains Sockets

Elro AB440S-3C mains sockets

I bought some made by HomeEasy  (Home Easy HE808S ) but they didn’t work. Then I got Elro AB440S/3C  which are fully compatible.
http://www.amazon.es/gp/product/B002QXN7X6/ref=oh_details_o01_s01_i02?ie=UTF8&psc=1

Optional:
If you are going to play with Arduino it is useful to get some wires and breadboard to avoid soldering.

Breadboard:

Breadboard

http://dx.com/p/830-point-solderless-breadboard-118354#.Uue7hMY1jsM

Wires:

Arduino Wire Jumpers

arduino-female-female-200mm-wire-jumper-cable-61-700x700
http://dx.com/p/30cm-breadboard-wires-for-electronic-diy-40-cable-pack-80207#.Uue7ecY1jsM
http://dx.com/p/breadboard-jumper-wires-for-electronic-diy-70-cable-pack-80208#.Uue7fsY1jsM

Software

1. Arduino IDE
http://arduino.cc/en/main/software

Arduino IDE

Download and install it.

2. RC Switch library
http://code.google.com/p/rc-switch/downloads/list

Download the zip folder and extract it.
Find files RCSwitch.cppRCSwitch.hkeywords.txt and zip them together into RCSwitch.zip

1. Open Arduino IDE and go to Sketch > Import Library > Add Library

Arduino Import Library

Select file RCSwitch.zip you have just zipped and you are ready to go!

Let’s start

1. Connections

Fart Detector with Fan/Ventilator Made with Arduino

I made this sweet diagram with Fritzing.

http://fritzing.org/download/

2. Set up ELRO mains sockets

arturito.net-fart-detector-with-fan-ventilator-made-with-arduino-elro

We setup pins with code 1 and buttons C

3. Learn RF codes

Let’s learn ON code and OFF code for C button set on the remote. In the RC-Switch library we extracted there are examples projects. Open project called ReceiveDemo or use this code


/*
 Simple example for receiving

 http://code.google.com/p/rc-switch/

 Need help? http://forum.ardumote.com
*/

#include

RCSwitch mySwitch = RCSwitch();

void setup() {
 Serial.print("Begin");
 Serial.begin(9600);
 mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
 pinMode(9,OUTPUT) ;
}

void loop() {
 if (mySwitch.available()) {

 int value = mySwitch.getReceivedValue();

 if (value == 0) {
 Serial.print("Unknown encoding");
 } else {
 digitalWrite(9,HIGH);
 Serial.print("Received ");
 Serial.print( mySwitch.getReceivedValue() );
 Serial.print(" / ");
 Serial.print( mySwitch.getReceivedBitlength() );
 Serial.print("bit ");
 Serial.print("Protocol: ");
 Serial.println( mySwitch.getReceivedProtocol() );
 delay(1000);
 digitalWrite(9,LOW);
 }

mySwitch.resetAvailable();
 }
}

Upload it to Arduino and open Serial Monitor. Press ON and OFF button on the remote. You should get your codes.

Fart Detector with Fan/Ventilator Made with Arduino

Once you have your codes set them in your program as shown below:

#include
RCSwitch mySwitch = RCSwitch();

int sensorPin = A0;
int sensorValue = 0;
int ledPin = 9;
int serialValue = 9600;

unsigned long switch_bits = 24;
unsigned long switch_on = 1394001;
unsigned long  switch_off = 1394004;
boolean is_on_switch = false;

void setup() {

  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
  // declare Serial
  Serial.begin(serialValue);
  // Transmitter is connected to Arduino Pin #7
  mySwitch.enableTransmit(7);
  mySwitch.setProtocol(1);
  mySwitch.send(switch_off, switch_bits);
  digitalWrite(ledPin,LOW);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  Serial.println(sensorValue);

  if(sensorValue >= 220 && !is_on_switch)
  {
    Serial.println("switching on");
    digitalWrite(ledPin,HIGH);
    mySwitch.send(switch_on, switch_bits);
    is_on_switch = true;
  }

  if(sensorValue < 220 && is_on_switch)
  {
    Serial.println("switching off");
    digitalWrite(ledPin,LOW);
    mySwitch.send(switch_off, switch_bits);
    is_on_switch = false;
  }
}

Test

In order to test it I used a lighter which contains butane . It will work fine with methane too :-)