Arduino-Controlled Fire Fighting Robot with IR Sensors and Water Pump
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
The circuit is designed for a 4-wheeled fire-fighting robot equipped with 3 IR sensors, 4 DC motors, a servo motor, a water pump, and an Arduino UNO microcontroller. The robot navigates towards a fire detected by the IR sensors and activates the water pump to extinguish it. The servo motor is used to adjust the direction of the water stream, and the DC motors drive the wheels of the robot.
Component List
IR Sensor
- Description: Used to detect the presence of fire or heat sources.
- Pins:
out,gnd,vcc
DC Motor
- Description: Provides motion to the robot's wheels.
- Pins:
pin 1,pin 2
9V Battery
- Description: Powers the circuit.
- Pins:
-,+
Arduino UNO
- Description: The main microcontroller unit that controls the robot's operations.
- Pins:
UNUSED,IOREF,Reset,3.3V,5V,GND,Vin,A0toA5,SCL,SDA,AREF,D13toD0
Servo
- Description: Adjusts the direction of the water stream.
- Pins:
GND,VCC,PWM
L298N DC Motor Driver
- Description: Controls the direction and speed of the DC motors.
- 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
5V Mini Water Pump
- Description: Pumps water to extinguish the fire.
- Pins:
positive pin,negative pin
Wiring Details
IR Sensors
- VCC: Connected to the 5V output on the Arduino UNO.
- GND: Connected to the ground (GND) on the Arduino UNO.
- OUT: Each sensor's output is connected to a digital input pin on the Arduino UNO (D2, D3, D4).
DC Motors
- Pin 1 & Pin 2: Each motor's pins are connected to the L298N motor driver's output pins (OUT1, OUT2, OUT3, OUT4).
9V Battery
- +: Connected to the 12V input on the L298N motor driver.
- -: Connected to the ground (GND) on the L298N motor driver and Arduino UNO.
Arduino UNO
- 5V & GND: Provide power to the IR sensors and servo.
- Digital Pins (D2 to D13): Control the IR sensors, servo, water pump, and motor driver.
Servo
- VCC: Connected to the 5V output on the Arduino UNO.
- GND: Connected to the ground (GND) on the Arduino UNO.
- PWM: Connected to a digital pin on the Arduino UNO (D5).
L298N DC Motor Driver
- 5V: Connected to the Vin pin on the Arduino UNO.
- GND: Connected to the ground (GND) on the Arduino UNO.
- ENA & ENB: Connected to digital pins on the Arduino UNO (D11, D12).
- IN1 to IN4: Connected to digital pins on the Arduino UNO (D6 to D9).
5V Mini Water Pump
- Positive Pin: Connected to a digital pin on the Arduino UNO (D13).
- Negative Pin: Connected to the ground (GND) on the Arduino UNO.
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, motors, servo, and water pump, and contains logic to control the robot's movements and actions based on the IR sensor readings. The robot moves forward, turns left or right, stops, and activates the water pump as needed to navigate towards and extinguish fires.