This circuit is designed to monitor environmental conditions, specifically the presence of gas and flames. It utilizes an MQ6 gas sensor and a KY-026 flame sensor to detect hazardous conditions. The circuit provides visual indicators through red and green LEDs and audible alarms using buzzers. The Arduino UNO microcontroller is the central processing unit that reads sensor inputs, controls the LEDs, and activates the buzzers based on predefined threshold values.
int redLed1 = 3;
int redLed2 = 4;
int greenLed = 8;
int buzzer1 = 5; //PWM (~) pin
int buzzer2 = 6; //PWM (~) pin
int gasPin = A0;
int flamePin = 2;
// Your threshold value
int gasSensorThres = 400;
void setup() {
pinMode(redLed1, OUTPUT);
pinMode(redLed2, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer1, OUTPUT);
pinMode(buzzer2, OUTPUT);
pinMode(gasPin, INPUT);
pinMode(flamePin, INPUT);
Serial.begin(9600);
}
void loop() {
int gasSensor = analogRead(gasPin);
int flameSensor = digitalRead(flamePin);
Serial.print("gasPin Value: ");
Serial.println(gasSensor);
Serial.print("flamePin Value: ");
Serial.println(flameSensor);
delay(1000);
if (gasSensor > gasSensorThres && flameSensor==LOW){
digitalWrite(redLed1, HIGH);
tone(buzzer1, 5000); //the buzzer sound frequency at 5000 Hz
digitalWrite(redLed2, HIGH);
tone(buzzer2, 5000); //the buzzer sound frequency at 5000 Hz
digitalWrite(greenLed, LOW);
}
else if (gasSensor > gasSensorThres)
{
digitalWrite(redLed1, HIGH);
tone(buzzer1, 5000); //the buzzer sound frequency at 5000 Hz
digitalWrite(redLed2, LOW);
noTone(buzzer2);
digitalWrite(greenLed, LOW);
}
else if (flameSensor==LOW){ // HIGH MEANS NO FLAME
digitalWrite(redLed1, LOW);
noTone(buzzer1);
digitalWrite(redLed2, HIGH);
tone(buzzer2, 5000); //the buzzer sound frequency at 5000 Hz
digitalWrite(greenLed, LOW);
}
else
{
digitalWrite(redLed1, LOW);
digitalWrite(redLed2, LOW);
noTone(buzzer1);
noTone(buzzer2);
digitalWrite(greenLed, HIGH);
}
}
The code is written for the Arduino UNO microcontroller. It initializes the pins connected to the LEDs and buzzers as outputs and the sensor pins as inputs. In the main loop, it reads the gas sensor value and the flame sensor state. Depending on these readings, it turns on the appropriate LEDs and buzzers to alert the user to the presence of gas or flames.