Arduino Leonardo Gas Detection System with LCD Feedback and Buzzer Alert
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to interface an Arduino Leonardo with an LCD screen and an MQ-5 gas sensor, with the addition of a buzzer for alerting purposes. The Arduino Leonardo serves as the central processing unit, reading the analog output from the MQ-5 sensor to detect the presence of gases and displaying the sensor value on the LCD screen. If the gas concentration exceeds a certain threshold, the buzzer is activated as an alarm.
Component List
LCD Screen 16x2 I2C
- Description: A 16x2 character LCD display with an I2C interface for displaying text.
- Pins: SCL, SDA, VCC, GND
MQ-5 Gas Sensor
- Description: A gas sensor for detecting LPG, natural gas, and coal gas. Outputs both digital and analog signals.
- Pins: VCC, GND, Digi Out, Analog out
Buzzer
- Description: An audible signaling device that can be used to alert users to certain conditions.
- Pins: PIN, GND
Arduino Leonardo (Rev3b)
- Description: A microcontroller board based on the ATmega32u4, with digital and analog I/O pins.
- Pins: D0/RX, D1/TX, D2/SDA, D3 PWM/SCL, D4/A6, D5 PWM, D6 PWM/A7, D7, n.c., IOREF, RESET, 3V3, 5V, GND, VIN, A0, A1, A2, A3, A4, A5, D8/A8, D9 PWM/A9, D10 PWM/A10, D11 PWM, D12/A11, D13 PWM, AREF, SDA, SCL
Wiring Details
LCD Screen 16x2 I2C
- SCL: Connected to SCL on Arduino Leonardo
- SDA: Connected to SDA on Arduino Leonardo
- VCC: Connected to 5V on Arduino Leonardo
- GND: Connected to GND on Arduino Leonardo
MQ-5 Gas Sensor
- VCC: Connected to 5V on Arduino Leonardo
- GND: Connected to GND on Arduino Leonardo
- Analog out: Connected to A0 on Arduino Leonardo
Buzzer
- PIN: Connected to D3 PWM/SCL on Arduino Leonardo
- GND: Connected to GND on Arduino Leonardo
Documented Code
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define Buzzer 3
#define Sensor A0
void setup() {
Serial.begin(9200);
lcd.init();
lcd.backlight();
pinMode(Buzzer, OUTPUT);
Serial.println("MQ5 Heating Up!");
delay(20000);
}
void loop() {
int value = analogRead(Sensor);
lcd.setCursor(0, 0);
lcd.print("VALUE:");
lcd.print(value);
lcd.print(" ");
if (value > 400) {
digitalWrite(Buzzer, HIGH);
lcd.setCursor(0, 1);
lcd.print("GAS DETECTED!");
} else {
digitalWrite(Buzzer, LOW);
lcd.setCursor(0, 1);
lcd.print(" ");
}
}
Code Explanation
- The code begins by including the
LiquidCrystal_I2Clibrary, which is used to control the LCD screen via the I2C protocol. - Two preprocessor directives define the pins for the buzzer and the gas sensor.
- In the
setup()function, the serial communication is started, and the LCD screen is initialized with its backlight turned on. The buzzer pin is set as an output, and a delay is included to allow the MQ-5 sensor to heat up. - The
loop()function continuously reads the analog value from the MQ-5 sensor and displays it on the LCD. If the value exceeds 400, the buzzer is turned on, and a warning message is displayed on the LCD. If the value is below the threshold, the buzzer is turned off, and the warning message is cleared.