Ad Code

Responsive Advertisement

Code and schematic Gas Sensor



int redLed = 5;

int yellowled = 6;

int greenLed = 7;

int buzzer = 4;

int smokeA0 = A1;

// Your threshold value

int sensorThres = 50;


void setup() {

  pinMode(redLed, OUTPUT);

  pinMode(greenLed, OUTPUT);

  pinMode(yellowled, OUTPUT);

  pinMode(buzzer, OUTPUT);

  pinMode(smokeA0, INPUT);

  Serial.begin(9600);

}


void loop() {

  int analogSensor = analogRead(smokeA0);


  Serial.print("Pin A0: ");

  Serial.println(analogSensor);

  // Checks if it has reached the threshold value

  if (analogSensor > sensorThres)

  {

    digitalWrite(redLed, HIGH);

    digitalWrite(greenLed, LOW);

    digitalWrite(yellowled, HIGH);

    digitalWrite(buzzer,HIGH);

  }

  else

  {

    digitalWrite(redLed, LOW);

    digitalWrite(greenLed, HIGH);

    digitalWrite(yellowled, LOW);

    digitalWrite(buzzer,LOW);

  }

  delay(100);

}

Post a Comment

0 Comments

Ad Code

Responsive Advertisement