Arduino-Controlled Fire Fighting Robot with IR Sensors and Water Pump
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary of the Circuit
This circuit is designed to control a 4-wheeled fire-fighting robot. It includes an Arduino UNO microcontroller, three IR sensors, a servo motor, a 5V mini water pump, four DC motors with wheels, and an L298N DC motor driver. The robot uses the IR sensors to detect fire and navigate towards it. Upon detection, the robot uses the water pump to extinguish the fire. The servo motor is used to adjust the direction of the water stream, and the DC motors are used for the robot's movement.
Component List
Arduino UNO
- Microcontroller board based on the ATmega328P
- It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.
IR Sensors
- Three sensors used to detect fire or heat sources.
- Each sensor has an output pin, a ground pin, and a VCC pin for power.
Servo
- A motor capable of precise control of angular position.
- It has a PWM input pin, a ground pin, and a VCC pin for power.
5V Mini Water Pump
- A small pump used for extinguishing the fire.
- It has a positive and a negative pin for power and control.
DC Motors and Wheels
- Four motors used for the robot's movement.
- Each motor has a VCC and a GND pin.
L298N DC Motor Driver
- A module used to control the speed and direction of the DC motors.
- It has output pins for motor connections, input pins for control signals, and power pins.
7.4V Battery
- Power source for the motor driver and motors.
Wiring Details
Arduino UNO
- 5V pin connected to VCC pins of all IR sensors and the servo motor.
- GND pin connected to GND pins of all IR sensors, the servo motor, and the 5V mini water pump.
- Vin pin connected to the 5V pin of the L298N motor driver.
- Digital pins D2, D3, D4 connected to the output pins of the IR sensors.
- Digital pin D5 connected to the PWM pin of the servo motor.
- Digital pin D6-D9 connected to IN1-IN4 pins of the L298N motor driver for motor control.
- Digital pin D11, D12 connected to ENA, ENB pins of the L298N motor driver for enabling the motors.
- Digital pin D13 connected to the positive pin of the 5V mini water pump.
IR Sensors
- VCC pins connected to the 5V output from the Arduino UNO.
- GND pins connected to the ground on the Arduino UNO.
- Output pins connected to digital pins D2, D3, D4 on the Arduino UNO.
Servo
- VCC pin connected to the 5V output from the Arduino UNO.
- GND pin connected to the ground on the Arduino UNO.
- PWM pin connected to digital pin D5 on the Arduino UNO.
5V Mini Water Pump
- Negative pin connected to the ground on the Arduino UNO.
- Positive pin connected to digital pin D13 on the Arduino UNO.
DC Motors and Wheels
- VCC and GND pins connected to the OUT1-OUT4 pins on the L298N motor driver.
L298N DC Motor Driver
- OUT1-OUT4 pins connected to the VCC and GND pins of the DC motors.
- 12V pin connected to the positive pin of the 7.4V battery.
- GND pin connected to the negative pin of the 7.4V battery and the ground on the Arduino UNO.
- 5V pin connected to the Vin pin on the Arduino UNO.
- IN1-IN4 pins connected to digital pins D6-D9 on the Arduino UNO.
- ENA, ENB pins connected to digital pins D11, D12 on the Arduino UNO.
7.4V Battery
- Positive pin connected to the 12V pin on the L298N motor driver.
- Negative pin connected to the GND pin on the L298N motor driver.
Documented Code
/*
* 4-Wheeled Fire Fighting Robot
* This code controls a fire fighting robot with 4 DC motors, 3 IR sensors,
* a servo motor, and a water pump. The robot moves towards the fire detected
* by the IR sensors and uses the water pump to extinguish it.
*/
// Pin definitions
#define IR_SENSOR_LEFT 2
#define IR_SENSOR_CENTER 3
#define IR_SENSOR_RIGHT 4
#define SERVO_PIN 5
#define WATER_PUMP_PIN 13
#define ENA 11
#define ENB 12
#define IN1 6
#define IN2 7
#define IN3 8
#define IN4 9
#include <Servo.h>
Servo servo;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize IR sensor pins
pinMode(IR_SENSOR_LEFT, INPUT);
pinMode(IR_SENSOR_CENTER, INPUT);
pinMode(IR_SENSOR_RIGHT, INPUT);
// Initialize motor driver pins
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
// Initialize water pump pin
pinMode(WATER_PUMP_PIN, OUTPUT);
// Attach servo to pin
servo.attach(SERVO_PIN);
// Set initial servo position
servo.write(90);
}
void loop() {
// Read IR sensor values
int irLeft = digitalRead(IR_SENSOR_LEFT);
int irCenter = digitalRead(IR_SENSOR_CENTER);
int irRight = digitalRead(IR_SENSOR_RIGHT);
// Print IR sensor values for debugging
Serial.print("IR Left: ");
Serial.print(irLeft);
Serial.print(" IR Center: ");
Serial.print(irCenter);
Serial.print(" IR Right: ");
Serial.println(irRight);
// Determine robot movement based on IR sensor values
if (irLeft == LOW && irCenter == LOW && irRight == LOW) {
// Move forward
moveForward();
} else if (irLeft == LOW && irCenter == HIGH && irRight == HIGH) {
// Turn left
turnLeft();
} else if (irLeft == HIGH && irCenter == HIGH && irRight == LOW) {
// Turn right
turnRight();
} else if (irLeft == HIGH && irCenter == HIGH && irRight == HIGH) {
// Fire detected, stop and activate water pump
stopRobot();
activateWaterPump();
} else {
// Default to stop
stopRobot();
}
delay(100);
}
void moveForward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
analogWrite(ENA, 160);
analogWrite(ENB, 160);
servo.write(90); // Rotate servo back to 90 degrees (center position)
}
void turnLeft() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
analogWrite(ENA, 160);
analogWrite(ENB, 160);
servo.write(45); // Rotate servo to 45 degrees
}
void turnRight() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
analogWrite(ENA, 160);
analogWrite(ENB, 160);
servo.write(135); // Rotate servo to 135 degrees
}
void stopRobot() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
analogWrite(ENA, 0);
analogWrite(ENB, 0);
}
void activateWaterPump() {
digitalWrite(WATER_PUMP_PIN, HIGH);
delay(5000); // Run the pump for 5 seconds
digitalWrite(WATER_PUMP_PIN, LOW);
}
This code is responsible for the operation of the fire-fighting robot. It initializes the IR sensors, motor driver, water pump, and servo motor in the setup() function. The loop() function continuously reads the IR sensor values to determine the robot's movement and activates the water pump when fire is detected. The functions moveForward(), turnLeft(), turnRight(), and stopRobot() control the robot's movement, while activateWaterPump() controls the water pump.