Back to Parent

int sensor = A4;
int ledPin = D2;
int interrupt = D1;
int buzzer = D0;
int flame;

unsigned long button_time = 0;
unsigned long last_button_time = 0;

void setup() {
  pinMode(sensor, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(buzzer, OUTPUT);
  Particle.variable("flame", &flame, INT);//cloud variable for IFTTT
  attachInterrupt(interrupt, restart, FALLING);
}

void loop() {
  flame = analogRead(sensor);//<190 when fire
  if (flame <= 190){
    digitalWrite(buzzer, HIGH);
    digitalWrite(ledPin, HIGH);
    delay(100);
    digitalWrite(ledPin, LOW);
    delay(100);
  }else{
    for(int fadeValue = 0; fadeValue <= 50; fadeValue +=2) {
      analogWrite(ledPin, fadeValue);
      delay(100);
    }
    for(int fadeValue = 50; fadeValue >= 0; fadeValue -=2) {
      analogWrite(ledPin, fadeValue);
      delay(100);
    }
  }
}

void restart(){
  button_time = millis();
  if (button_time - last_button_time > 1000){
    digitalWrite(buzzer, LOW);
    last_button_time = button_time;
  }
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0