The script below (also avalable as codebender to run immediate) is used to read the analog value (A0) and the digital signal (connected to D12)
/* 2016 MQ-2 GAS Sensor JanJeronimus
Gets digital and analog value from gas sensor every second
Writes time [ uptime millis() ] ,
digital gas sensor and
analog gas sensor value to the serial port
*/
const int gasPinA = A0 ; //GAS sensor Analog output pin to Arduino analog A0 pin
const int gasPinD = 12; //GAS sensor Digital output pin to Arduino
int val = 0; // variable to store the Digital read value
void setup()
{
pinMode(gasPinD, INPUT);
Serial.begin(9600); //Initialize serial port - 9600 bps
}
void loop()
{
Serial.print( "Time " ) ;
Serial.print( millis() ) ;
Serial.print( " , Digital " ) ;
Serial.print( val ) ;
Serial.print( " , Analog " ) ;
Serial.println( analogRead(gasPinA) );
delay(1000); // Print value every 1 sec.
}
To get a reliable signal a burn-in time is needed.
When using the sensor for the first time (without burn-in time) the analog signal indicates a value of 130 and in a few minutes dropping to 80 and slowly dropping more.
If opening gas from a cigarette lighter near the sensor the signal rises to +/- 340.
This indicates that the sensor is working. After a few hours the analog signal has dropped to 27.
If spraying some aftershave on my hand and immediate putting my hand near the sensor the signal also rises to this value. In this case it takes more time before the signals drops down again.
No comments:
Post a Comment