Pages: [1]   Go Down
Author Topic: MQ-7 CARBON MONOXIDE GAS SENSOR  (Read 3834 times)
0 Members and 2 Guests are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to get readings from the CARBON MONOXIDE GAS SENSOR - MQ7.

According to the datasheet the heater needs to be on for 60s with 5v and then 90s with 1.4v.

Here is my code:

Code:
// to the pins used:
const int triggerPin = 12;
const int sensorPin = 0;
int val = 0;
int counter = 0;

void setup() {
  pinMode(triggerPin, OUTPUT);
  Serial.begin( 9600 );
}

void loop() {
  // 60s high voltage 5.0v
  Serial.println( "Heating Sensor" );
  analogWrite(triggerPin, 255); 
  delay(60000);
  // 90s low voltage 1.4v
  analogWrite(triggerPin, 67);
  val = analogRead( sensorPin ); 
 
  for ( counter = 0; counter < 90; counter++ )
  {
    Serial.print("Sensor Value: ");
    Serial.println(val);
    delay(1000);
  }
 
}

I hooked it up to the arduino using a 2n2222 transistor on pin12 (with a 1k resistor). When the sensor is not connected the transistor switches fine between 1.4v and 5v, with the sensor connected the transistor is also switching fine, but when I measure the vcc on the sensor then it always measures just a little bit less than 5v and my sensor out is always 1023 on my analog input?

Any ideas? I'm using this sensor and breakout board:

https://www.sparkfun.com/products/9403
http://www.pololu.com/catalog/product/1479

I'm using a 10k resistor for the sensitivity.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 618
Posts: 33948
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't see where the 90 second delay is before you the the reading.
For the 60 second delay mark the variable unsigned long 60000UL.

Where are you taking the measurements of voltage on the sensor?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

After the 60s delay I take a ready every second for 90 seconds (in the loop). All the readings are consistently 1023. I measure the voltage right after the transistor, without the sensor I get 1.4V and 5V which is right, but when I add the sensor I measure it almost close to 5v. I measure it at the VCC of the sensor which is triggered by the transistor.

Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 618
Posts: 33948
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I take a ready every second for 90 seconds
Why?
Quote
According to the datasheet the heater needs to be on for 60s with 5v and then 90s with 1.4v
Yes and then you measure it.

Quote
I measure the voltage right after the transistor,
I don't understand what you mean, have you got a schematic of your wiring?

Have you see this page?
http://playground.arduino.cc/Main/MQGasSensors

Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I just wanted to see if the reading would change over time. Would it affect anything if I only read it at the end of the 90s ?

I have attached a crude schematic.

I changed my code to this:

Code:
  Serial.println( "Heating Sensor - 5.0V - 60s" );
  analogWrite(triggerPin, 255); 
  delay(60000UL);
  // 90s low voltage 1.4v
  Serial.println( "Heating Sensor - 1.4V - 90s" );
  analogWrite(triggerPin, 67);
  delay(90000UL);
  val = analogRead( sensorPin );   
  Serial.print("Sensor Value: ");
  Serial.println(val);

Most of the values are still stuck at 1023, although now and again I seem to get something along the lines of 788.

T


* gas_sensor.png (65.45 KB, 596x897 - viewed 345 times.)
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 618
Posts: 33948
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't think that is wired up correctly. The sensor's ground should be connected to ground. The transistor has its collector wired up to ground.
The transistor's emitter should be connected to ground with the heater connected to the collector.
So as itis you're not heating it at all.
The sensor should not be connected to Vin, it should be 5V. So Asti is you are supplying goo much voltage to the analogue input pin, you might have damaged it.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I only used Vin on the schematic as it didn't have a 5V, but it was using the 5v. I changed it around as you specified it.

Sensor GND - > GND
Transistor Emitter -> GND
Transistor Collector -> VCC on Heater
Transistor Base from the Arduino output pin with resistor

But now it seems that it's not switching it all. Measuring the voltage before the resistor shows correctly 5v and 1.4v respectively.

Maybe I'm not understanding how a transistor works but where is it getting it's 5v from now? The arduino itself?
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 618
Posts: 33948
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

[quoteI only used Vin on the schematic as it didn't have a 5V, but it was using the 5v.][/quote]
And you didn't think to actually say anything about it!!

Quote
Maybe I'm not understanding how a transistor work
Yes that is your problem. Measurements on the transistor's base mean nothing you need to measure the heater. Did you look at that link on sensors? Did you look at the data sheet. You need to supply that voltage to the heater's Vcc at the moment you are not.

Try reading this
http://arduinotronics.blogspot.co.uk/2012/03/gas-sensor-tutorial.html
« Last Edit: July 21, 2013, 02:07:09 pm by Grumpy_Mike » Logged

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

Got this sensor working nicely using an adjustable voltage regulator and a solid state relay. More on my blog at http://davidhoulding.blogspot.com/2014/03/co-carbon-monoxide-gas-sensor-using.html.
Logged

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

I need sketch MQ7 sensor with indicator LED. can you show me tahts sketch, im from indonesia.thanks
Logged

Pages: [1]   Go Up
Jump to: