Arduino UNO-Based Fire and Gas Detection Robot with Water Pump and Motor Control
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control a robotic system using an Arduino UNO microcontroller. The system includes various sensors, actuators, and a motor driver to perform tasks such as detecting gas and flame, controlling motors and a water pump, and activating a buzzer for alerts. The Arduino UNO serves as the central controller, interfacing with all the components and executing the embedded code to manage the system's operations.
Component List
Arduino UNO
- Description: Microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
1 Channel 5V Relay Module
- Description: Relay module for switching high-power devices.
- Pins: VCC+, VCC- (GND), IN, N.O., COM, N.C.
5V Mini Water Pump
- Description: Small water pump powered by 5V.
- Pins: positive pin, negative pin
MQ-5 Gas Sensor
- Description: Gas sensor for detecting LPG, natural gas, and coal gas.
- Pins: VCC, GND, Digi Out, Analog out
Rocker Switch
- Description: On/Off switch.
- Pins: output, input
Motor and Wheels
- Description: DC motor with attached wheels.
- Pins: vcc, GND
L298N DC Motor Driver
- Description: Dual H-Bridge motor driver.
- Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
Micro Servo 9G
- Description: Small servo motor.
- Pins: GND, +5V, PWM
Battery 12V
- Description: 12V battery for powering the circuit.
- Pins: +, -
KY-026 Flame Sensor
- Description: Flame sensor for detecting fire.
- Pins: AO, GND, VCC, DO
Buzzer
- Description: Small buzzer for sound alerts.
- Pins: GND, IN
Wiring Details
Arduino UNO
- 5V: Connected to Micro Servo 9G (+5V), 1 Channel 5V Relay Module (VCC+), 1 Channel 5V Relay Module (COM), KY-026 Flame Sensor (VCC), MQ-5 Gas Sensor (VCC)
- GND: Connected to Buzzer (GND), Micro Servo 9G (GND), 1 Channel 5V Relay Module (VCC- (GND)), 5V Mini Water Pump (negative pin), MQ-5 Gas Sensor (GND), KY-026 Flame Sensor (GND), Battery 12V (-), L298N DC Motor Driver (GND)
- Vin: Connected to L298N DC Motor Driver (5V)
- D13: Connected to 1 Channel 5V Relay Module (IN)
- D11: Connected to L298N DC Motor Driver (ENB)
- D10: Connected to MQ-5 Gas Sensor (Digi Out)
- D9: Connected to L298N DC Motor Driver (ENA)
- D8: Connected to Buzzer (IN)
- D7: Connected to Micro Servo 9G (PWM)
- D6: Connected to KY-026 Flame Sensor (DO)
- D5: Connected to L298N DC Motor Driver (IN3)
- D4: Connected to L298N DC Motor Driver (IN4)
- D3: Connected to L298N DC Motor Driver (IN2)
- D2: Connected to L298N DC Motor Driver (IN1)
1 Channel 5V Relay Module
- VCC+: Connected to Arduino UNO (5V)
- VCC- (GND): Connected to Arduino UNO (GND)
- IN: Connected to Arduino UNO (D13)
- N.O.: Connected to 5V Mini Water Pump (positive pin)
- COM: Connected to Arduino UNO (5V)
5V Mini Water Pump
- positive pin: Connected to 1 Channel 5V Relay Module (N.O.)
- negative pin: Connected to Arduino UNO (GND)
MQ-5 Gas Sensor
- VCC: Connected to Arduino UNO (5V)
- GND: Connected to Arduino UNO (GND)
- Digi Out: Connected to Arduino UNO (D10)
Rocker Switch
- output: Connected to Battery 12V (+)
- input: Connected to L298N DC Motor Driver (12V)
Motor and Wheels
- vcc: Connected to L298N DC Motor Driver (OUT2), L298N DC Motor Driver (OUT4)
- GND: Connected to L298N DC Motor Driver (OUT1), L298N DC Motor Driver (OUT3)
L298N DC Motor Driver
- OUT1: Connected to Motor and Wheels (GND)
- OUT2: Connected to Motor and Wheels (vcc)
- 12V: Connected to Rocker Switch (input)
- GND: Connected to Battery 12V (-), Arduino UNO (GND)
- 5V: Connected to Arduino UNO (Vin)
- OUT3: Connected to Motor and Wheels (GND)
- OUT4: Connected to Motor and Wheels (vcc)
- ENA: Connected to Arduino UNO (D9)
- IN1: Connected to Arduino UNO (D2)
- IN2: Connected to Arduino UNO (D3)
- IN3: Connected to Arduino UNO (D5)
- IN4: Connected to Arduino UNO (D4)
- ENB: Connected to Arduino UNO (D11)
Micro Servo 9G
- GND: Connected to Arduino UNO (GND)
- +5V: Connected to Arduino UNO (5V)
- PWM: Connected to Arduino UNO (D7)
Battery 12V
- +: Connected to Rocker Switch (output)
- -: Connected to Arduino UNO (GND), L298N DC Motor Driver (GND)
KY-026 Flame Sensor
- AO: Not connected
- GND: Connected to Arduino UNO (GND)
- VCC: Connected to Arduino UNO (5V)
- DO: Connected to Arduino UNO (D6)
Buzzer
- GND: Connected to Arduino UNO (GND)
- IN: Connected to Arduino UNO (D8)
Code Documentation
#include <Servo.h>
const int flameSensorPin = 6;
const int gasSensorPin = 10;
const int relayPin = 13;
const int servoPin = 7;
const int buzzerPin = 8;
const int flameThreshold = 500;
const int gasThreshold = 400;
const int motorA1 = 2;
const int motorA2 = 3;
const int motorB1 = 5;
const int motorB2 = 4;
const int motorAspeed = 9;
const int motorBspeed = 11;
class Buzzer {
private:
int buzzerPin; // Motor control pins
public:
Buzzer(int buzzerPin) {
this->buzzerPin = buzzerPin;
pinMode(buzzerPin, OUTPUT);
this->stop();
}
void start(){
digitalWrite(this->buzzerPin, HIGH);
}
void stop(){
digitalWrite(this->buzzerPin, LOW);
}
};
class Observer {
private:
int flameSensorPin;
int gasSensorPin;
public:
Observer(int flameSensorPin, int gasSensorPin){
this->flameSensorPin = flameSensorPin;
this->gasSensorPin = gasSensorPin;
pinMode(flameSensorPin, INPUT);
pinMode(gasSensorPin, INPUT);
}
bool is_fire() {
return !digitalRead(this->flameSensorPin);
}
bool is_gas() {
return !digitalRead(this->gasSensorPin);
}
};
class WaterBump {
private:
int relayPin;
int servoPin;
int dir = 1;
int servoValue = 90;
int stepValue = 3;
public:
Servo waterServo;
WaterBump(int relayPin, int servoPin) {
this