Detectair

images

video

description

const int sensorMin = 550;      // sensor minimum, discovered through experiment
const int sensorMax = 800;    // sensor maximum, discovered through experiment
int ledPin = 10;    // LED connected to digital 10
int ledPinTwo = 9;    // LED connected to digital 9
int ledPinThree = 11;  //LED connected to digital 11
int vibePin = 13;                 // LED connected to digital pin 13

void setup() {
  // initialize serial communication:
  Serial.begin(9600);  
  pinMode(vibePin, OUTPUT);      // sets the digital pin as output
}

void loop() {
  // read the sensor:
  int gasSensor = analogRead(0);
  // map the sensor range to a range of four options:
  int range = map(gasSensor, sensorMin, sensorMax, 0, 3);
Serial.println( gasSensor );
delay(500);

  // do something different depending on the
  // range value:
  switch (range) {
    
    
  case 0:    // ambient air environment 500-632
 
  Serial.println( "Ambient" );
  // fade in from min to max in increments of 5 points:
   for(int fadeValue = 5 ; fadeValue <= 100; fadeValue +=1) {
     // sets the value (range from 0 to 255):
     analogWrite(ledPin, fadeValue);         
     analogWrite(ledPinTwo, fadeValue);
     analogWrite(ledPinThree, fadeValue);   
     // wait for 30 milliseconds to see the dimming effect    
     delay(30);
     
   }

   // fade out from max to min in increments of 5 points:
   for(int fadeValue = 100 ; fadeValue >= 5; fadeValue -=1) {
     // sets the value (range from 0 to 255):
     analogWrite(ledPin, fadeValue);
     analogWrite(ledPinTwo, fadeValue);  
     analogWrite(ledPinThree, fadeValue);     
     // wait for 30 milliseconds to see the dimming effect    
     delay(30);  
   }    
     
    break;
    
    
  case 1:    // urban air environment 633-700
    
    
   Serial.println( "Urban" );
// fade in from min to max in increments of 5 points:
   for(int fadeValue = 5 ; fadeValue <= 255; fadeValue +=8) {
     // sets the value (range from 0 to 255):
     analogWrite(ledPin, fadeValue);         
     analogWrite(ledPinTwo, fadeValue);
     analogWrite(ledPinThree, fadeValue);   
     // wait for 30 milliseconds to see the dimming effect    
     delay(30);
   }

   // fade out from max to min in increments of 5 points:
   for(int fadeValue = 255 ; fadeValue >= 5; fadeValue -=8) {
     // sets the value (range from 0 to 255):
     analogWrite(ledPin, fadeValue);
     analogWrite(ledPinTwo, fadeValue);  
     analogWrite(ledPinThree, fadeValue);     
     // wait for 30 milliseconds to see the dimming effect    
     delay(30);  
   }
   
    break;
 
 
  case 2:    // dirty air environment 700-800
 

   Serial.println( "Dirty" );  
// fade in from min to max in increments of 5 points:
   for(int fadeValue = 5 ; fadeValue <= 255; fadeValue +=20) {
     // sets the value (range from 0 to 255):
     analogWrite(ledPin, fadeValue);         
     analogWrite(ledPinTwo, fadeValue);
     analogWrite(ledPinThree, fadeValue);   
     // wait for 30 milliseconds to see the dimming effect    
     delay(30);
   }

   // fade out from max to min in increments of 5 points:
   for(int fadeValue = 255 ; fadeValue >= 5; fadeValue -=20) {
     // sets the value (range from 0 to 255):
     analogWrite(ledPin, fadeValue);
     analogWrite(ledPinTwo, fadeValue);  
     analogWrite(ledPinThree, fadeValue);     
     // wait for 30 milliseconds to see the dimming effect    
     delay(30);  
   }
 
 
    digitalWrite(vibePin, HIGH);   // sets the vibrator on
    delay(1000);                  // waits for a second
    digitalWrite(vibePin, LOW);    // sets the vibrator off
    delay(10);                  // waits for a second

    break;
 
 
  case 3:    // toxic air environment 800-900
 
   digitalWrite(vibePin, HIGH);   // sets the vibrator on
   Serial.println( "Toxic" );    
// fade in from min to max in increments of 5 points:
   for(int fadeValue = 5 ; fadeValue <= 255; fadeValue +=50) {
     // sets the value (range from 0 to 255):
     analogWrite(ledPin, fadeValue);         
     analogWrite(ledPinTwo, fadeValue);
     analogWrite(ledPinThree, fadeValue);   
     // wait for 30 milliseconds to see the dimming effect    
     delay(30);
   }

   // fade out from max to min in increments of 5 points:
   for(int fadeValue = 255 ; fadeValue >= 5; fadeValue -=50) {
     // sets the value (range from 0 to 255):
     analogWrite(ledPin, fadeValue);
     analogWrite(ledPinTwo, fadeValue);  
     analogWrite(ledPinThree, fadeValue);     
     // wait for 30 milliseconds to see the dimming effect    
     delay(30);  
   }
 
    break;
  }

}

Report abuse

10x's