MQ-2 and MQ-7 Prototype

We have all the code behaving as we want it to, and the circuit responding to it we expected. The inputs and outputs are clearly observable, and moreover easily controlled. Unfortunately, the motor does not provide us with enough torque, and as a result does not turn the fan with a high enough velocity. Therefore, the whistle is not provided with enough directed air pressure to pass through it to make a noise. Despite this, the output of a motor turning could lead to a range of different functions to alert a passer-by that a flammable gas such as butane, or carbon monoxide is present.

Box Base     Box Lid

Because of how we have designed and structured the breadboard and Arduino, we had to then distance the sensors, LEDs and motor, so they were easily visible. We did this by taking them off and connecting them with female to male cables. We then designed the box around this arrangement. It featured a lid with six holes, and a base to contain the circuitry.

Box open

In hindsight, we should of positioned the holes for each smoke sensor on opposing sides of the box. This would of made testing far easier and proving of concept far easier.

Advertisements

MQ-2 and MQ-7 with DC Motor

I set up a simple circuit consisting of a DC Motor, Diode and Transistor. The code allowed me to control the RPM of the motor, by typing a number between 150 and 255 into the Arduino Serial monitor.

The image and video below shows this.

20180224_202008

 

The following code is what I used to control the motors speed:

int motorPin = 3;

 

void setup()

{

  pinMode(motorPin, OUTPUT);

  Serial.begin(9600);

  while (! Serial);

  Serial.println(“Speed 0 to 255”);

}

 

 

void loop()

{

  if (Serial.available())

  {

    int speed = Serial.parseInt();

    if (speed >= 0 && speed <= 255)

    {

      analogWrite(motorPin, speed);

    }

  }

}

The next stage was to combine the original MQ-2 and MQ-7 breadboard and code with the DC Motor circuit and code. The aim was to be able to set a different motor speed as an output for each different gas readings. A different speed for the MQ-2, MQ-7 and neural set up. This along with the separate LED displays would clearly determine what gas is being detected.

The image shows the Fritzing breadboard of the final set up.

Final

The next image shows the real circuit, as well as an additional 3D printed fan to clearly show the rotation of the motor.

Fan

The video shows the circuit in action, using all the components.

The red LED is shown when the MQ-7 sensor is detecting carbon monoxide, and the green LED lights up when butane is detected. The lighter used contains a combination of flammable gases, which explains why both sensors react to it. But when the fuel is released from the lighter in the direction of each sensor, it is clear that they are responding independently.

The readings on the Arduino Serial monitor also support these observations.

MQ-2 (Pin A0) Detected:

MQ-2

MQ-7 (CO value) Detected:

MQ-7

Both Detected:

Both

As well as the additional motor functions, the following code has also been improved from the last by making the tones more distinguishable between each sensor that is detecting a gas.

int redLed = 12;
int greenLed = 11;
int whiteLed = 7;
int buzzer = 10;
int smokeA0 = A5;
int AOUTpin = A4;
int DOUTpin = 8;
int motorPin = 3;

int sensorThres = 100;

void setup() {
// Output setups, LED, buzzer, motor
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(whiteLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
pinMode(DOUTpin, INPUT);
pinMode(motorPin, OUTPUT);
Serial.begin(115200);

 

}

void loop() {
// Defining the read intergers for the input
int analogSensor = analogRead(smokeA0);
int value = analogRead(AOUTpin);
int limit = digitalRead(DOUTpin);
int speed = Serial.parseInt();

//Output of serial print and LED, buzzer, motor
Serial.print(“Pin A0: “);
Serial.println(analogSensor);
Serial.print(“CO value: “);
Serial.println(value);
Serial.print(“Limit: “);
Serial.println(limit);
Serial.println(“Speed 0 to 255”);
delay(100);
if (analogSensor > sensorThres && value > 100) // Both triggered
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, HIGH);
digitalWrite(whiteLed, LOW);
tone(buzzer, 1000, 600);
delay(50);
tone(buzzer, 1000, 600);
delay(50);
tone(buzzer, 1000, 600);
digitalWrite(motorPin, 255);

}
else if (analogSensor < sensorThres && value > 100) // MQ-7 triggered
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
digitalWrite(whiteLed, LOW);
tone(buzzer, 500, 300);
digitalWrite(motorPin, 150);

}
else if (analogSensor > sensorThres && value < 100) // MQ-2 triggered
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
digitalWrite(whiteLed, LOW);
tone(buzzer, 2000, 1200);
digitalWrite(motorPin, 150);
}
else if (analogSensor < sensorThres && value < 100) // Neutral setup
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
digitalWrite(whiteLed, HIGH);
noTone(buzzer);
digitalWrite(motorPin, 0);
}
}

Now that I have successfully built the circuit with all the necessary components along with the correct code, I now need to incorporate it into a housing with physical components that respond to the outputs.

Combining the MQ-2 and MQ-7 sensors

MQ-2 AND MQ-7 “sensor package”

After researching the two gas sensors individually Ed & I joined the two together to create a combined sensor system. we compiled the two separate breadboard layouts and code together to form a singular circuit. The aim was to allow the individual sensors to detect different gas inputs, and use the same output components but in a different format. For example, different LED display, sound, and motion.

Firstly we combined the two codes together in a simple way, adding the inputs together and giving the same output.

Code output

 

However, it did not behave as we expected. The readings were not clear, and the gas detection did not seem to have a pattern. Consequently, we decided to rewrite a new code instead of taking syntax from previous ones. This resulted in us achieving more effective and clearer instructions.

This image and video show what we did:

20180224_180249 (1)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

This was our improved code:

int redLed = 12;

int greenLed = 11;

int buzzer = 10;

int smokeA0 = A5;

int AOUTpin = A4;

int DOUTpin = 8;

 

int sensorThres = 400;

 

void setup() {

  // put your setup code here, to run once:

  pinMode(redLed, OUTPUT);

  pinMode(greenLed, OUTPUT);

  pinMode(buzzer, OUTPUT);

 

  pinMode(smokeA0, INPUT);

 

  pinMode(DOUTpin, INPUT);

 

  Serial.begin(115200);

 

 

}

 

void loop() {

  // put your main code here, to run repeatedly:

  int analogSensor = analogRead(smokeA0);

  int value = analogRead(AOUTpin);

  int limit = digitalRead(DOUTpin);

 

  Serial.print(“Pin A0: “);

  Serial.println(analogSensor);

  Serial.print(“CO value: “);

  Serial.println(value);

  Serial.print(“Limit: “);

  Serial.println(limit);

  delay(100);

  if (analogSensor > sensorThres && value > 80) // both triggered

  {

    digitalWrite(redLed, HIGH);

    digitalWrite(greenLed, LOW);

    tone(buzzer, 1000, 600);

    delay(100);

    tone(buzzer, 5000, 600);

 

  }

  else if (analogSensor < sensorThres && value > 80) //CO trigger4ed

  {

  //output goes here

  }

  else if (analogSensor > sensorThres && value < 80) //smoke triggered

  {

  //outpu goes here

  }

  else if  (analogSensor < sensorThres && value < 80)

  {

    digitalWrite(redLed, LOW);

    digitalWrite(greenLed, HIGH);

    noTone(buzzer);

  }

}

 

This code turned the red light and a series of tones, when either of the sensors detected a gas. A green LED was present when nothing was detected. This function does not determine what gas or sensor has detected anything, which would not be very beneficial in actual use.

For this reason, we wanted to increase the number of LED’s that would display each detection. Having one colour for neutral, one for each sensor, as well as multiple for both sensor detection. Another improvement from the last configuration, is an increase in resistance over each output component. We reduced the brightness of the LED’s and the amplitude of the buzzer to make it more bearable when testing the circuit.

The following image and video show the results.

20180224_205410

 

The following code achieves these functions.

int redLed = 12;

int greenLed = 11;

int whiteLed = 7;

int buzzer = 10;

int smokeA0 = A5;

int AOUTpin = A4;

int DOUTpin = 8;

 

int sensorThres = 400;

 

void setup() {

  // Output setups, LED, buzzer, motor

  pinMode(redLed, OUTPUT);

  pinMode(greenLed, OUTPUT);

  pinMode(whiteLed, OUTPUT);

  pinMode(buzzer, OUTPUT);

  pinMode(smokeA0, INPUT);

  pinMode(DOUTpin, INPUT);

  Serial.begin(115200);

 

 

}

 

void loop() {

  // Defining the read intergers for the input

  int analogSensor = analogRead(smokeA0);

  int value = analogRead(AOUTpin);

  int limit = digitalRead(DOUTpin);

 

  //Output of serial print and LED, buzzer, motor

  Serial.print(“Pin A0: “);

  Serial.println(analogSensor);

  Serial.print(“CO value: “);

  Serial.println(value);

  Serial.print(“Limit: “);

  Serial.println(limit);

  delay(100);

  if (analogSensor > sensorThres && value > 100) // Both triggered

  {

    digitalWrite(redLed, HIGH);

    digitalWrite(greenLed, HIGH);

    digitalWrite(whiteLed, LOW);

    tone(buzzer, 1000, 600);

    delay(100);

    tone(buzzer, 5000, 600);

 

  }

  else if (analogSensor < sensorThres && value > 100) // MQ-7 triggered

  {

    digitalWrite(redLed, HIGH);

    digitalWrite(greenLed, LOW);

    digitalWrite(whiteLed, LOW);

    tone(buzzer, 1000, 600);

    delay(100);

    tone(buzzer, 5000, 600);

 

  }

  else if (analogSensor > sensorThres && value < 100) // MQ-2 triggered

  {

    digitalWrite(redLed, LOW);

    digitalWrite(greenLed, HIGH);

    digitalWrite(whiteLed, LOW);

    tone(buzzer, 1000, 600);

    delay(100);

    tone(buzzer, 5000, 600);

    digitalWrite(redLed, LOW);

    digitalWrite(redLed, HIGH);

  }

  else if  (analogSensor < sensorThres && value < 100) // Neutral setup

  {

    digitalWrite(redLed, LOW);

    digitalWrite(greenLed, LOW);

    digitalWrite(whiteLed, HIGH);

    noTone(buzzer);

  }

}

Using a standard lighter proved to be a challenge to detect specific gases, as they do not always contain just butane. The readings on the Arduino Serial monitor show definite readings of each gas, so we know that they work and behave as we want the code to. However, we think the lighter also contains carbon monoxide, so the red LED also reacts to the lighter. Breathing on the sensor is another method of getting a reading from the MQ-7 sensor, and only the red LED responds.

The next step of this project is to incorporate an additional output, which will be a motor. We plan on connecting it to a fan, which will blow air through a whistle. This will be covered in the next blog post.

MQ-2 and MQ-7 in Series

After both smoke sensors were used for their own purpose correctly as independent components, we collaborated the code and breadboard layout to form one complete circuit. The aim was to allow the individual sensors to detect different gas inputs, and use the same output components but in a different format. For example, different LED display, sound, and motion.

We firstly combined the separate codes to form the following:

int redLed = 12;

int greenLed = 11;

int buzzer = 10;

int smokeA0 = A5;

int AOUTpin = A4;

int DOUTpin = 8;

 

int sensorThres = 400;

 

void setup() {

  // put your setup code here, to run once:

  pinMode(redLed, OUTPUT);

  pinMode(greenLed, OUTPUT);

  pinMode(buzzer, OUTPUT);

 

  pinMode(smokeA0, INPUT);

 

  pinMode(DOUTpin, INPUT);

 

  Serial.begin(115200);

 

 

}

 

void loop() {

  // put your main code here, to run repeatedly:

  int analogSensor = analogRead(smokeA0);

  int value = analogRead(AOUTpin);

  int limit = digitalRead(DOUTpin);

 

  Serial.print(“Pin A0: “);

  Serial.println(analogSensor);

  Serial.print(“CO value: “);

  Serial.println(value);

  Serial.print(“Limit: “);

  Serial.println(limit);

  delay(100);

 

  if (analogSensor > sensorThres)

  {

    digitalWrite(redLed, HIGH);

    digitalWrite(greenLed, LOW);

    tone(buzzer, 2000, 600);

    delay(100);

    tone(buzzer, 1000, 600);

   

  }

  else

  {

    digitalWrite(redLed, LOW);

    digitalWrite(greenLed, HIGH);

    noTone(buzzer);

   

  }

   if (value > 100)

  {

    digitalWrite(redLed, HIGH);

    digitalWrite(greenLed, LOW);

    tone(buzzer, 1000, 600);

    delay(100);

    tone(buzzer, 5000, 600);

   

  }

  else

  {

    digitalWrite(redLed, LOW);

    digitalWrite(greenLed, HIGH);

    noTone(buzzer);

   

  }

}

 

However, it did not behave as we expected. The readings were not clear, and the gas detection did not seem to have a pattern. Consequently, we decided to rewrite a new code instead of taking syntax from previous ones. This resulted in us achieving more effective and clearer instructions. The following images and video show what we did.

This is the Fritzing board containing all components.

MQ-2 and MQ-7 no white

This is the circuit we put together.

20180224_180249 (1)

The following video demonstrates our testing.

 

This was our improved code:

int redLed = 12;

int greenLed = 11;

int buzzer = 10;

int smokeA0 = A5;

int AOUTpin = A4;

int DOUTpin = 8;

 

int sensorThres = 400;

 

void setup() {

  // put your setup code here, to run once:

  pinMode(redLed, OUTPUT);

  pinMode(greenLed, OUTPUT);

  pinMode(buzzer, OUTPUT);

 

  pinMode(smokeA0, INPUT);

 

  pinMode(DOUTpin, INPUT);

 

  Serial.begin(115200);

 

 

}

 

void loop() {

  // put your main code here, to run repeatedly:

  int analogSensor = analogRead(smokeA0);

  int value = analogRead(AOUTpin);

  int limit = digitalRead(DOUTpin);

 

  Serial.print(“Pin A0: “);

  Serial.println(analogSensor);

  Serial.print(“CO value: “);

  Serial.println(value);

  Serial.print(“Limit: “);

  Serial.println(limit);

  delay(100);

  if (analogSensor > sensorThres && value > 80) // both triggered

  {

    digitalWrite(redLed, HIGH);

    digitalWrite(greenLed, LOW);

    tone(buzzer, 1000, 600);

    delay(100);

    tone(buzzer, 5000, 600);

 

  }

  else if (analogSensor < sensorThres && value > 80) //CO trigger4ed

  {

  //output goes here

  }

  else if (analogSensor > sensorThres && value < 80) //smoke triggered

  {

  //outpu goes here

  }

  else if  (analogSensor < sensorThres && value < 80)

  {

    digitalWrite(redLed, LOW);

    digitalWrite(greenLed, HIGH);

    noTone(buzzer);

  }

}

 

This code turned the red light and a series of tones, when either of the sensors detected a gas. A green LED was present when nothing was detected. This function does not determine what gas or sensor has detected anything, which would not be very beneficial in actual use.

For this reason, we wanted to increase the number of LED’s that would display each detection. Having one colour for neutral, one for each sensor, as well as multiple for both sensor detection. Another improvement from the last configuration, is an increase in resistance over each output component. We reduced the brightness of the LED’s and the amplitude of the buzzer to make it more bearable when testing the circuit. The following image and video show the results.

This is the Fritzing board containing both smoke detecting sensors, a buzzer, and a white, green and red LED.

MQ-2 MQ-7 and Buzzer

This is the circuit we put together.

20180224_205410

This video demonstrates all the components and their functions in use.

 

The following code achieves these functions.

int redLed = 12;

int greenLed = 11;

int whiteLed = 7;

int buzzer = 10;

int smokeA0 = A5;

int AOUTpin = A4;

int DOUTpin = 8;

 

int sensorThres = 400;

 

void setup() {

  // Output setups, LED, buzzer, motor

  pinMode(redLed, OUTPUT);

  pinMode(greenLed, OUTPUT);

  pinMode(whiteLed, OUTPUT);

  pinMode(buzzer, OUTPUT);

  pinMode(smokeA0, INPUT);

  pinMode(DOUTpin, INPUT);

  Serial.begin(115200);

 

 

}

 

void loop() {

  // Defining the read intergers for the input

  int analogSensor = analogRead(smokeA0);

  int value = analogRead(AOUTpin);

  int limit = digitalRead(DOUTpin);

 

  //Output of serial print and LED, buzzer, motor

  Serial.print(“Pin A0: “);

  Serial.println(analogSensor);

  Serial.print(“CO value: “);

  Serial.println(value);

  Serial.print(“Limit: “);

  Serial.println(limit);

  delay(100);

  if (analogSensor > sensorThres && value > 100) // Both triggered

  {

    digitalWrite(redLed, HIGH);

    digitalWrite(greenLed, HIGH);

    digitalWrite(whiteLed, LOW);

    tone(buzzer, 1000, 600);

    delay(100);

    tone(buzzer, 5000, 600);

 

  }

  else if (analogSensor < sensorThres && value > 100) // MQ-7 triggered

  {

    digitalWrite(redLed, HIGH);

    digitalWrite(greenLed, LOW);

    digitalWrite(whiteLed, LOW);

    tone(buzzer, 1000, 600);

    delay(100);

    tone(buzzer, 5000, 600);

 

  }

  else if (analogSensor > sensorThres && value < 100) // MQ-2 triggered

  {

    digitalWrite(redLed, LOW);

    digitalWrite(greenLed, HIGH);

    digitalWrite(whiteLed, LOW);

    tone(buzzer, 1000, 600);

    delay(100);

    tone(buzzer, 5000, 600);

    digitalWrite(redLed, LOW);

    digitalWrite(redLed, HIGH);

  }

  else if  (analogSensor < sensorThres && value < 100) // Neutral setup

  {

    digitalWrite(redLed, LOW);

    digitalWrite(greenLed, LOW);

    digitalWrite(whiteLed, HIGH);

    noTone(buzzer);

  }

}

Using a standard lighter proved to be a challenge to detect specific gases, as they do not always contain just butane. The readings on the Arduino Serial monitor show definite readings of each gas, so we know that they work and behave as we want the code to. However, we think the lighter also contains carbon monoxide, so the red LED also reacts to the lighter. Breathing on the sensor is another method of getting a reading from the MQ-7 sensor, and only the red LED responds.

The next step of this project is to incorporate an additional output, which will be a motor. We plan on connecting it to a fan, which will blow air through a whistle. This will be covered in the next blog post.

MQ-2 Smoke Sensor

The previous post showed the layout and structure of the circuit containing the MQ-2 Smoke Sensor. This blog post contains the testing of the sensor, including some videos and code.

In the following video, the buzzer produces a single tone when the sensor detects butane. The red LED is also switched on.

I have developed the previous circuit by adding a buzzer, which produces a long sound with varied pitches. The green light keeps on when the sensor does not detect any gases. The red light and buzzer turn and remain on until a gas is no longer detected.

MQ-2 LEDs and Buzzer

 

 

Code:

int redLed = 12;

int greenLed = 11;

int buzzer = 10;

int smokeA0 = A5;

 

int sensorThres = 400;

 

void setup() {

  pinMode(redLed, OUTPUT);

  pinMode(greenLed, OUTPUT);

  pinMode(buzzer, OUTPUT);

  pinMode(smokeA0, INPUT);

  Serial.begin(9600);

 }

 

void loop() {

  int analogSensor = analogRead(smokeA0);

 

  Serial.print(“Pin A0: “);

  Serial.println(analogSensor);

  if (analogSensor > sensorThres)

  {

    digitalWrite(redLed, HIGH);

    digitalWrite(greenLed, LOW);

    tone(buzzer, 3000, 6000);

    delay(100);

    tone(buzzer, 2000, 6000);

    delay(100);

    tone(buzzer, 1000, 6000);

    delay(100);

    tone(buzzer, 500, 6000);

    delay(100);

    tone(buzzer, 1000, 6000);

    delay(100);

    tone(buzzer, 5000, 2000);

    tone(buzzer, 3000, 2000);

    delay(100);

    tone(buzzer, 23000, 2000);

    delay(100);

    tone(buzzer, 1000, 2000);

    delay(100);

    tone(buzzer, 5200, 2000);

    delay(100);

 

  }

  else

  {

    digitalWrite(redLed, LOW);

    digitalWrite(greenLed, HIGH);

    noTone(buzzer);

  }

}

MQ-7 Carbon Monoxide Sensor

After reading the data sheet a bit more I found out a huge amount of information about how the MQ-7 sensor works.

It turns out that all of the MQ series sensors work the same way, they all use a small heater inside with an electro-chemical sensor. They are sensitive for a range of gasses and are used indoors at room temperature. The output is an analog signal and can be read with an analog input of the Arduino.

When looking more specifically at the MQ-7 Datasheet it explained (in broken english) that the sensor made it detection for Carbon Monoxide by running through cycles of high and low temperatures. The sensor will detect CO at a low temperature (when the heating element is at 1.5V). At the high temperature end of the cycle the sensor cleans out the other gasses that have been absorbed at the low temperature end of the cycle.

MQ-7 Circuit diagram

“Instructions: The above fig is the basic test circuit of MQ-7.The sensor requires two voltage inputs: heater voltage (VH) and circuit voltage(VC). VH is used to supply standard working temperature to the sensor and it can adopt DC or AC power. For this model sensor, VH should be at 1.5V±0.1V low voltage when detect CO while should be at 5V±0.1V at non detection status(resuming period). VRL is the voltage of load resistance RL which is in series with sensor. Vc supplies the detect voltage to load resistance RL and it should adopts DC power.”

This is taken directly from the MQ-7 data-sheet and explains the circuit diagram shown above.

Sensor CharacteristicsMq-7 sensor charateristics 2

The Circuit

When looking at tutorials for the MQ-7 Sensor I found a very simple way to use the sensor.

MQ-7 Fritzing

The above shows the circuit that i used for the MQ-7 Sensor, with the following code;

const int AOUTpin=0;  //the AOUT pin of the CO sensor goes into analog pin A0 of the arduino
const int DOUTpin=8;  //the DOUT pin of the CO sensor goes into digital pin D8 of the arduino
const int ledPin=13;  //the anode of the LED connects to digital pin D13 of the arduino

int limit;
int value;

void setup() {
Serial.begin(115200);  //sets the baud rate
pinMode(DOUTpin, INPUT);  //sets the pin as an input to the arduino
pinMode(ledPin, OUTPUT);  //sets the pin as an output of the arduino
}

void loop()
{
value= analogRead(AOUTpin);  //reads the analaog value from the CO sensor’s AOUT pin
limit= digitalRead(DOUTpin);  //reads the digital value from the CO sensor’s DOUT pin
Serial.print(“CO value: “);
Serial.println(value);  //prints the CO value
Serial.print(“Limit: “);
Serial.print(limit);  //prints the limit reached as either LOW or HIGH (above or underneath)
delay(100);
if (limit == HIGH){
digitalWrite(ledPin, HIGH);  //if limit has been reached, LED turns on as status indicator
}
else{
digitalWrite(ledPin, LOW);  //if threshold not reached, LED remains off
}
}

the image above shows the above circuit when in use with that code, i was able to get a reading from the CO sensor when I blew smoke onto the sensor.

 

Links:

https://playground.arduino.cc/Main/MQGasSensors

https://cdn.sparkfun.com/datasheets/Sensors/Biometric/MQ-7%20Ver1.3%20-%20Manual.pdf

https://en.wikipedia.org/wiki/Electrochemical_gas_sensor

http://www.learningaboutelectronics.com/Articles/MQ-7-carbon-monoxide-sensor-circuit-with-arduino.php

 

MQ-7 Carbon Monoxide Sensor

All the MQ series of gas sensors use a small heater inside with an electro-chemical sensor. They are sensitive for a range of gasses and are used indoors at room temperature.

The output is an analog signal and can be read with an analog input of the Arduino.

Carbon Monoxide Sensor.

This is a simple-to-use Carbon Monoxide (CO) sensor, suitable for sensing CO concentrations in the air. The MQ-7 can detect CO-gas concentrations anywhere from 20 to 2000ppm.

This sensor has a high sensitivity and fast response time. The sensor’s output is an analog resistance. The drive circuit is very simple; all you need to do is power the heater coil with 5V, add a load resistance, and connect the output to an ADC.

After searching a bit more I found some code to use the sensor and how to set it up correctly.

After working on the code and creating a fritzing layout that matched the diagrams, the sensor still did not work.

I did a bit more research into the MQ-7 and found that it has to be properly calibrated for it to work.

I found this step by step run-through in how to calibrate the sensor.

“According to manufacturer’s datasheet, sensor should be running heating-cooling cycles for 48 hours in a row before it can be calibrated. And you should do it if you intend to use it for a long time: in my case, sensor reading in clean air changed for about 30% over 10 hours. If you won’t take this into account, you can get 0 ppm result where there is actually 100 ppm of CO. If you don’t want to wait for 48 hours, you can monitor sensor output at the end of measurement cycle. When over an hour it won’t change for more than 1-2 points – you can stop heating there.

Rough calibration:

After running sketch for at least 10 hours in clean air, take raw sensor value in the end of the measurement cycle, 2-3 seconds before heating phase starts, and write it into sensor_reading_clean_air variable (line 100). That’s it. Program will estimate other sensor parameters, they won’t be precise, but should be enough to distinguish between 10 and 100 ppm concentration.

Precise calibration:

I highly recommend to find a calibrated CO meter, make 100 ppm CO sample (this can be done by taking some flue gas into syringe – CO concentration there can easily be in the range of several thousands ppm – and slowly putting it into closed jar with calibrated meter and MQ-7 sensor), take raw sensor reading at this concentration and put it into sensor_reading_100_ppm_CO variable. Without this step, your ppm measurement can be wrong several times in either direction (still ok if you need alarm for dangerous CO concentration at home, where normally there should be no CO at all, but not good for any industrial application).”

I tried to calibrate the sensor following the steps above, however I didn’t do it over ten hours. I added the sensor value to sensor_reading_clean_air after about 3 ½ hours instead.

After trying to hold the sensor next to my gas hob for a few seconds there was still no change in the reading.

 

 

 

Links:

https://playground.arduino.cc/Main/MQGasSensors

https://cdn.sparkfun.com/datasheets/Sensors/Biometric/MQ-7%20Ver1.3%20-%20Manual.pdf

https://en.wikipedia.org/wiki/Electrochemical_gas_sensor

 

 

 

MQ-2 Smoke Sensor

Gas Sensor (MQ2) module is useful for gas leakage detection. This is a sensor that detects smoke and to the following flammable gases:

  • LPG
  • Butane
  • Propane
  • Methane
  • Alcohol
  • Hydrogen

Due to its high sensitivity and fast response time, measurement can be taken as soon as possible. The resistance of the sensor is different depending on the type of the gas. The smoke sensor has a built-in potentiometer that allows you to adjust the sensor sensitivity according to how accurate you want to detect gas.

The sensor value only reflects the approximated trend of gas concentration in a permissible error range, it does not represent the exact gas concentration. The detection of certain components in the air usually requires a more precise and costly instrument, which cannot be done with a single gas sensor.

There are 4 kinds of gas sensors which can detect different type of gas:

MQ2      Combustible Gas, Smoke  

MQ3      Alcohol Vapor

MQ5      LPG, Natural Gas, Town Gas

MQ9      Carbon Monoxide, Coal Gas, Liquefied Gas

Features

Wide detecting scope

Stable and long lifetime

Fast response and High sensitivity

Specification

How does it Work?

The voltage that the sensor outputs changes accordingly to the smoke/gas level that exists in the atmosphere. The sensor outputs a voltage that is proportional to the concentration of smoke/gas.

The relationship between voltage and gas concentration is the following:

  • The greater the gas concentration, the greater the output voltage.
  • The lower the gas concentration, the lower the output voltage.

The output can be an analog signal (A0) that can be read with an analog input of the Arduino or a digital output (D0) that can be read with a digital input of the Arduino.

Pin Wiring

 The MQ-2 sensor has 4 pins.

Pin————————————-Wiring to Arduino Uno

A0————————————-Analog pins

D0————————————-Digital pins

GND———————————–GND

VCC————————————5V

Circuit 2

Gas Detection

In this example, the sensor is connected to A0 pin. The voltage read from the sensor is displayed. This value can be used as a threshold to detect any increase/decrease in gas concentration.

void setup()

{

    Serial.begin(9600);

}

 

void loop()

{

    int val;

    val=analogRead(0);

    Serial.println(val,DEC);

    delay(100);

}

 

The Arduino Serial monitor window below shows the sensor reacting to a butane lighter.

rduino Serial monitor window

Measurement : Approximation

These examples demonstrate ways to know the approximate concentration of Gas. As per the data-sheet of the MQx sensors, these equations are tested for standard conditions and are not calibrated. It may vary based on change in temperature or humidity.

void setup() {

    Serial.begin(9600);

}

 

void loop() {

    float sensor_volt;

    float RS_air; //  Get the value of RS via in a clear air

    float R0;  // Get the value of R0 via in H2

    float sensorValue;

 

    /*— Get a average data by testing 100 times —*/

    for(int x = 0 ; x < 100 ; x++)

    {

        sensorValue = sensorValue + analogRead(A0);

    }

    sensorValue = sensorValue/100.0;

    /*———————————————–*/

 

    sensor_volt = sensorValue/1024*5.0;

    RS_air = (5.0-sensor_volt)/sensor_volt; // omit *RL

    R0 = RS_air/9.8; // The ratio of RS/R0 is 9.8 in a clear air from Graph (Found using WebPlotDigitizer)

 

    Serial.print(“sensor_volt = “);

    Serial.print(sensor_volt);

    Serial.println(“V”);

 

    Serial.print(“R0 = “);

    Serial.println(R0);

    delay(1000);

 

}

Then, open the serial monitor of Arduino IDE. Write down the value of R0 and this will be used in the next program. Please write down the R0 after the reading stabilizes. Replace the R0 below with value of R0 tested above . Expose the sensor to any one of the gas listed above.

void setup() {

    Serial.begin(9600);

}

 

void loop() {

 

    float sensor_volt;

    float RS_gas; // Get value of RS in a GAS

    float ratio; // Get ratio RS_GAS/RS_air

    int sensorValue = analogRead(A0);

    sensor_volt=(float)sensorValue/1024*5.0;

    RS_gas = (5.0-sensor_volt)/sensor_volt; // omit *RL

 

          /*-Replace the name “R0” with the value of R0 in the demo of First Test -*/

    ratio = RS_gas/R0;  // ratio = RS/R0

          /*———————————————————————–*/

 

    Serial.print(“sensor_volt = “);

    Serial.println(sensor_volt);

    Serial.print(“RS_ratio = “);

    Serial.println(RS_gas);

    Serial.print(“Rs/R0 = “);

    Serial.println(ratio);

 

    Serial.print(“\n\n”);

 

    delay(1000);

 

}

We can then get the concentration of gas from the figure below:

Graph

This is the Fritzing board.

MQ-2 with LEDs

This is the circuit I put together.

Circuit 3