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:
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 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.
[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.
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