This circuit is designed to create a gas detection system using an Arduino Uno microcontroller and an MQ-5 gas sensor. When the sensor detects gas, the system activates a buzzer and a red LED as a warning signal. Conversely, when no gas is detected, a green LED indicates that the environment is safe. The circuit includes resistors to limit current to the LEDs, ensuring they operate within safe parameters.
/*
* This Arduino Sketch controls a gas detection system using an MQ-5 sensor.
* When gas is detected, a buzzer and a red LED are activated.
* When no gas is detected, a green LED is activated.
*/
const int buzzerPin = 13; // Buzzer connected to pin 13 (SCK)
const int greenLEDPin = 8; // Green LED connected to pin 8
const int redLEDPin = 9; // Red LED connected to pin 9
const int gasSensorPin = A0; // MQ-5 gas sensor digital output connected to A0
void setup() {
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
pinMode(greenLEDPin, OUTPUT); // Set green LED pin as output
pinMode(redLEDPin, OUTPUT); // Set red LED pin as output
pinMode(gasSensorPin, INPUT); // Set gas sensor pin as input
}
void loop() {
int gasDetected = digitalRead(gasSensorPin); // Read gas sensor value
if (gasDetected == HIGH) { // If gas is detected
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
digitalWrite(redLEDPin, HIGH); // Turn on red LED
digitalWrite(greenLEDPin, LOW); // Turn off green LED
} else { // If no gas is detected
digitalWrite(buzzerPin, LOW); // Turn off buzzer
digitalWrite(redLEDPin, LOW); // Turn off red LED
digitalWrite(greenLEDPin, HIGH); // Turn on green LED
}
}
This code is designed to be uploaded to the Arduino Uno microcontroller. It initializes the pins connected to the buzzer and LEDs as outputs and the gas sensor pin as an input. In the main loop, it continuously checks the gas sensor's digital output. If gas is detected, it activates the buzzer and red LED while deactivating the green LED. If no gas is detected, it deactivates the buzzer and red LED while activating the green LED.