MQ-7 CARBON MONOXIDE GAS SENSOR

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:

// 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:

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

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?

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.

I take a ready every second for 90 seconds

Why?

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.

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

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:

  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

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.

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?

[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!!

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

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.

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

can u send me a working program for mq135 , mq 7 and arduino project using i2c serial lcd pls

Did MQ sensors used in out door ?

good evening, do you mind to share the schematic of how you connect the MQ7 to arduino, I have problem generating alternating voltage (5v and 1.4v) for the sensor, and i have no idea of components needed

Thx