9. (rook) gassensor

MQ2 rooksensor icm Arduino: 



  1. Vcc = 5V (u can use the 5V on Arduino)
  2. GND = Ground (0V - also on Arduino)
  3. AOUT = Analog Output (which pin u want to use - A0 )

/* Sample Arduino for MQ2 Smoke Sensor Shield
   05/03/2011
**********************************************/
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
//const int analogOutPin = 9; // Analog output pin that the LED is attached to
 
int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)
float thickness;
int count,count1;
 
void setup() 
{
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
  //pinMode(7, OUTPUT);  
}
 
void loop() 
{
 
  count1++;
  // read the analog in value:
  sensorValue = analogRead(analogInPin);            
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 100);  
  // change the analog out value:
  //analogWrite(analogOutPin, outputValue);           
 
  if(count1==30)
  {
    count1=0;
    // print the results to the serial monitor:
    //Serial.print("sensor = " );                       
    //Serial.print(sensorValue);      
    Serial.print("\t output = ");      
    Serial.println(outputValue);
 
   /*
    thickness = 20000-(5000*(1023/(float)sensorValue)-1);         //This relationship is wrong,According to demand, own calculations relationship
 
    Serial.print("thicknes = ");
    Serial.println( thickness);
    */
    
  }
  count++;
  delay(100); 
  /*
  if(count>=(255-outputValue))
  {
    count=0;
  }
  if(count < (255-outputValue)/2)
  { 
    digitalWrite(7, HIGH);   // set the LED on
    delay(20);
  }
 // delay(1023-sensorValue);   
  else
  {
    digitalWrite(7, LOW);    // set the LED off
    delay(20);
  }
 */
 // delay(1023-sensorValue);                         
}