Pages: [1]   Go Down
Author Topic: Hooking up a gas & smoke (MQ-2) sensor  (Read 5793 times)
0 Members and 1 Guest are viewing this topic.
Asnieres sur Seine - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to build a networked smoke & gas detector. I got a few MQ-2 sensors to hook up to my Arduino (Uno with WiFi Shield) via my breadboard.

My local suppliers didn't have the ones with the breakout boards so I have the "raw" 6-pin sensors.

http://www.pololu.com/catalog/product/1480

I have gone through the data sheet (http://www.pololu.com/file/0J309/MQ2.pdf) as best I can. I have also looked at the Arduino Playground page (http://playground.arduino.cc//Main/MQGasSensors) as regards the sensors and tried to follow that as best as I can. I have also looked at some video examples. But they all seem to be using breakout boards for their connections...

But I am lost in the wiring. Basically I see there are 2x A pins, 2x B pins and 2x H pins. My understanding is that I should be connecting the two A pins together, the two B pins together and the 2 H pins together. My assumption therefore was to run two wires from the two A pins to two holes in the breadboard but in the same column, two wires from the two B pins to a same column in the breadboard and two wires from the two H pins to a same column in the breadboard. I would then run one wire from the A pin column in the breadboard to the Arduino, one from the B pin column to the Arduino and one from the H pin column to the Arduino (ie 3 wires from the breadboard to the Arduino).

The sensor appears to take 5V directly and I am going to need to add a load resistor (from 2kOhm to 47kOhm) connected to the ground part of the circuit.

My basic problem is that I can't decipher which of the sensor pins goes where. I believe one of the pins goes to the 5V, one goes to GND and one goes to an analog input port such as A0. But I don't know which pin (pair - column) corresponds to each of these.

From the Playground page I believe the A pins go to the 5V. But I'm not sure. I then don't know which goes to the GND (B pins or H pins). Whichever goes to GND then gets the resistor between it and the GND on the Arduino and the other pin pair goes to A0.

Any ideas or suggestions?

Many thanks.
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You must be sure to have it right, because the sensor can be damaged easily.

Look at the bottom, see the pictures here for A, B, and H (don't look at the schematic, that is different).
http://www.thaieasyelec.com/Review-Product-Article/Gas-Sensor-Getting-Started.html

The pins in the middle are 'H', that is the heater.
One of the 'H' should be ground, the other 'H' should be 5V.

Connect both 'A' pins to 5V.
Connect both the 'B' pins to a load resistor and to Arduino analog input.

You could upload a photo of your breadboard, so we can take a look at it, before you power it.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17261
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Keep in mind that at 5 volt the sensor's heater draws around 160ma so there is a limit of how many of these you can power off an arduino's 5V pin.

Lefty
Logged

Asnieres sur Seine - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Erdin : Thank you so much for your very helpful and detailed reply. I believe I was able to both understand and follow your instructions.

I tried taking pictures but you can't see much on them. I made a Fritzing diagram instead which you'll find attached.

I have attached red wires to both A bins and the left H pin.
I have attached a white wire to the right H pin.
I have attached green wires to both B pins.

On the breadboard you'll notice a 22k ohms resistor in the same column as the 2 green wires and heading to the wire which goes to A0.

I truly appreciate your having a look before I power this up.

Lefty (who I see all over these forums!) : I should have been clearer in my original point. I bought several MQ-2 sensors. But I am only using 1. When one is learning electronics and tinkering by trial and error one must allow for "replacement parts"... just in case.

[Incorrect Fritzing attached files removed]
« Last Edit: February 25, 2013, 06:19:00 pm by DerekErb » Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17261
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Lefty (who I see all over these forums!) : I should have been clearer in my original point. I bought several MQ-2 sensors. But I am only using 1. When one is learning electronics and tinkering by trial and error one must allow for "replacement parts"... just in case.

Been there, done that. Unless a component/part/module is expensive I never buy just one, two is the minimum to protect against brain farts, as one never stops learning in this hobby.  smiley-wink

Lefty
Logged

Asnieres sur Seine - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm sorry... the Fritzing files I uploaded were wrong. They didn't correspond to the wiring I had done.

That incorrect version had a black wire going from GND on the breadboard to 5V on the Arduino and nothing going from the power row to the Arduino.

This new version has the correct, in that it corresponds to what I've done, wiring.


* MQ-2 Breadboard.png (300.75 KB, 2025x1368 - viewed 534 times.)
* MQ-2 Breadboard.fzz (3.31 KB - downloaded 105 times.)
Logged

Asnieres sur Seine - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So, as I have 4 other MQ-2 sensors and I can be quite impatient and it's late. I plugged in the setup as described.

Nothing blew up so I guess that's a good sign.

I tried using the following very simplistic code
Code:
/*
  MQ-2 Sensor connected to Arduino Uno
  Both A pins and left H pin connected to 5V out
  Right H pin connected to GND
  Both B pins conncted to 22k ohms resistor and A0
*/

int iSensorValue = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  // Read value on A0
  iSensorValue = analogRead(A0);
 
  // Display value
  Serial.print(F("MQ-2 Sensor Value = "));
  Serial.println(iSensorValue);
 
  // Loop 10 times per second
  delay(100);
}

I get a value ranging from 1019 to 1022 every 1/10 of a second.

Unfortunately even when I light a match directly under the sensor, blow it out, cup my hand over it and engulf the sensor in smoke those values never change to anything lower or different.

I'm thinking that they should be lower at the start, "at ease" as it were, and go higher when the sensor comes in contact with smoke. But, as I said, the standard values it shows, upon startup, continually range from 1019 to 1022 which seems to me to be basically at the maximum ceiling of 1023...

I'm hoping that means I have just screwed up something in the wiring somewhere... but not enough to fry the sensor?
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, the sensor is not damaged that way, but the output is not correct.

The load resistor connects to both 'B'. You have that. But that should also go to the analog input.
The load resistor must also connect to ground.

The heater should warm the sensor, after 5 or 10 minutes the metal of the sensor should get warm.

The 'signal path' is like this: 5V to both 'A' pins -> 'A' to 'B' is the sensor -> both 'B' pins to resistor and to analog input -> resistor to ground.

Also, 22k is very high. The output could be at the maximum.
I would suggest to use 2k2 to start with.
Even with 2k2 it should be very sensitive.

Your sketch is okay.
Logged

Asnieres sur Seine - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That last message from Erdin was what I needed. The resistor needs to be connected to both the GND and the Analog input. You can see the newly corrected Fritzing attached.

I knew it had worked as soon as I ran the original code on the new wiring. It started with values around 790-810 and slowly went down and down to the 500s and then the 400s and finally it settled around the upper 360s after 15 minutes. That's when I decided to test. I lit a match underneath the sensor and it went crazy. It shot to 800 immediately. I blew out the match and it stayed up in the 800 range and hovered there while the smoke billowed in my hand. When I moved my hand away and let the smoke dissipate it dropped to 600 and, a few seconds later, slowly worked its way back down to the upper 360s.

I modified the code slightly to map the values as a percentage: in other words I took the incoming range of 0 to 1023 and applied it to a range of 0 to 100. The "standard" mapped reading seems to be around 35-36 now and I can therefore check for differences from that to see if it's in the presence of smoke.

Code:
/*
  MQ-2 Sensor connected to Arduino Uno
  Both A pins and left H pin connected to 5V out
  Right H pin connected to GND
  Both B pins, and right H pin, connected to 22k ohms resistor and A0
*/

// Sensor value read from analog pin (range from 0 to 1023)
int iSensorValue = 0;

// Mapped value from 0 to 100
byte bySensorVal = 0;

// Message string to be displayed on serial monitor
char cMsg[124];

//////////////////////////////////////////////////////
//
// SETUP
//
void setup() {
  Serial.begin(9600);
}

//////////////////////////////////////////////////////
//
// LOOP
//
void loop() {
 
  // Read input value on A0 and map it from 0 to 100
  iSensorValue = analogRead(A0);
  bySensorVal = map(iSensorValue, 0, 1023, 0, 100);
 
  // Display input value and mapped value
  sprintf(cMsg, "MQ-2 Sensor Value : %d (%d)", iSensorValue, bySensorVal);

  // Check for high value
  if (bySensorVal > 60) {
    Serial.print(cMsg);
    Serial.println(F(" *** DISTURBANCE IN THE FORCE! ***"));
  }
  else {
    Serial.println(cMsg);
  }
 
  // Loop 10 times per second
  delay(100);
}

Now I need to find some different gas samples to play around with to see how the sensor reacts ... but somehow without making myself sick at the same time.

Thank you ALL for your helpful and detailed replies. I am just at the beginnings of what I want this little device to do, and this is one of the simplest of the projects I have in my head, and I have already learned a TON here.


* MQ-2 Breadboard.png (400.05 KB, 1995x1626 - viewed 324 times.)
* MQ-2 Breadboard.fzz (3.68 KB - downloaded 47 times.)
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well done. Your wiring is okay now.

You have to do the burn-in time, see that MQ-Sensor page, http://playground.arduino.cc/Main/MQGasSensors
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sir can u help me on how to code mq2 to output in ppm..pls help tnx
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I am also using MQ 6 sensor. I interfaced it with ardunio uno 328 board. Its working fine as i done the same connections as given in that http://www.thaieasyelec.com/Sensors.

I want to connect temperature sensor also. i am using LM35. it is also working fine.

But both work when i connect them individually.

When i try to connect both simultaneously on A0 and A1, values from both sensor get disturbed.
Why?



 
Logged

Narvik, Norway
Offline Offline
God Member
*****
Karma: 22
Posts: 968
electronics engineer, teacher.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a graph in thedatasheet telling showin Rs/Ro.
So from your readings, you have to calculate the change in resistans - then map that value intto the logaritmic diagram
I'm sure there is a 'smart' funktin (formula) for this purpose..
Note that the datasheet assumes RL to be 5k (I dont know if this is important..)
Logged

Ny

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried with different value i.e. I connected  a pot their of 100K value. I am facing the same problem.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can  u plz show me code for that ur using for the MQ -6 sensor . i'm also working with the same sensor like MQ series and Temp sensor LIke lm and DTH11...
Logged

Pages: [1]   Go Up
Jump to: