Arduino Mega 2560 Fire Detection and Water Pump System with LCD Display
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to detect fire using a KY-026 Flame Sensor and respond by activating a water pump and a buzzer. The system is controlled by an Arduino Mega 2560 microcontroller, which also interfaces with a 16x2 I2C LCD to display the status of the system. The L293D motor driver is used to control the water pump, and the entire system is powered by two 18650 Li-ion batteries.
Component List
Arduino Mega 2560
- Description: A microcontroller board based on the ATmega2560.
- Pins: IOREF, RESET, 3V3, 5V, GND, VIN, A0-A15, D0-D53, AREF, SDA, SCL
L293D
- Description: A quadruple high-current half-H driver designed to drive inductive loads such as relays, solenoids, DC and bipolar stepping motors.
- Pins: 5V, GND, +, Servo1, Servo2, RX/DO, TX/D1, 9V, A0-A5, VIN, 3.3V, RESET, D2-D13
18650 Li-ion Battery x 2
- Description: Rechargeable lithium-ion batteries.
- Pins: +, -
Water Pump
- Description: A small DC water pump.
- Pins: positive, negative
KY-026 Flame Sensor
- Description: A flame sensor module that can detect fire or other light sources in the wavelength range of 760nm to 1100nm.
- Pins: AO, GND, VCC, DO
16x2 I2C LCD
- Description: A 16x2 character LCD display with I2C interface.
- Pins: GND, VCC, SDA, SCL
Buzzer
- Description: A small piezoelectric buzzer.
- Pins: PIN, GND
Resistor
- Description: A 100 Ohm resistor.
- Pins: pin1, pin2
Rocker Switch
- Description: A simple on/off switch.
- Pins: output, input
Wiring Details
Arduino Mega 2560
- A8: Connected to AO of KY-026 Flame Sensor
- D21/SCL: Connected to SCL of 16x2 I2C LCD
- D20/SDA: Connected to SDA of 16x2 I2C LCD
- GND: Connected to GND of KY-026 Flame Sensor, GND of Buzzer, GND of 16x2 I2C LCD
- D22: Connected to pin2 of Resistor
- 5V: Connected to VCC of 16x2 I2C LCD, VCC of KY-026 Flame Sensor
L293D
- GND: Connected to - of 18650 Li-ion Battery x 2, negative of Water Pump
- +: Connected to output of Rocker Switch, positive of Water Pump
18650 Li-ion Battery x 2
- +: Connected to input of Rocker Switch
- -: Connected to GND of L293D
Water Pump
- positive: Connected to + of L293D
- negative: Connected to GND of L293D
KY-026 Flame Sensor
- AO: Connected to A8 of Arduino Mega 2560
- GND: Connected to GND of Arduino Mega 2560
- VCC: Connected to 5V of Arduino Mega 2560
16x2 I2C LCD
- SCL: Connected to D21/SCL of Arduino Mega 2560
- SDA: Connected to D20/SDA of Arduino Mega 2560
- VCC: Connected to 5V of Arduino Mega 2560
- GND: Connected to GND of Arduino Mega 2560
Buzzer
- PIN: Connected to D22 of Arduino Mega 2560
- GND: Connected to GND of Arduino Mega 2560
Resistor
- pin2: Connected to D22 of Arduino Mega 2560
Rocker Switch
- output: Connected to + of L293D
- input: Connected to + of 18650 Li-ion Battery x 2
Code Documentation
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int sensorMin = 0; // sensor minimum
const int sensorMax = 1024; // sensor maximum
#include <AFMotor.h>
AF_DCMotor motor1(1);
const int buzzer = 22;
void setup()
{
Serial.begin(9600);
lcd.begin();
lcd.backlight();
lcd.setCursor(1, 0);
lcd.println("Reading Sensor ");
motor1.setSpeed(255);
motor1.run(RELEASE);
delay(2000);
}
void loop()
{
int sensorReading = analogRead(A8);
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
switch (range) {
case 0: // A fire closer than 1.5 feet away.
motor1.run(FORWARD);
lcd.backlight();
lcd.setCursor(1, 0);
//lcd.print("** Close Fire **");
lcd.print(" Water Flow ON ");
tone(buzzer, 3000);
delay(1000);
noTone(buzzer);
delay(1000);
break;
case 1: // A fire between 1-3 feet away.
motor1.run(RELEASE);
lcd.backlight();
lcd.setCursor(1, 0);
//lcd.print("* Distant Fire *");
lcd.print(" Water Flow OFF ");
break;
case 2: // No fire detected.
motor1.run(RELEASE);
lcd.backlight();
lcd.setCursor(1, 0);
//lcd.print("*** No Fire ***");
lcd.print(" Water Flow OFF ");
break;
}
delay(1);
}
This code initializes the LCD and motor, reads the flame sensor value, and controls the water pump and buzzer based on the sensor reading. The LCD displays the status of the water flow, and the buzzer sounds an alarm if a fire is detected.