Arduino-Controlled Firefighting Robot with Ultrasonic Obstacle Detection and Bluetooth Interface
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
The circuit in question appears to be a robotic system equipped with various sensors, actuators, and control modules. It includes flame sensors for fire detection, an ultrasonic sensor for distance measurement, motors for movement, a water pump for extinguishing fires, and an Arduino UNO microcontroller for processing and control. The system also features a Bluetooth module for wireless communication, a motor driver for controlling the motors, a relay for switching the water pump, and power management components such as a battery case and a buck converter. The robot is designed to navigate, detect flames, and take action to extinguish fires, with the capability to be controlled remotely via Bluetooth.
Component List
Sensors
- KY-026 Flame Sensor: Detects the presence of a flame or fire.
- Ultrasonic Sensor: Measures distance to objects by emitting ultrasonic waves.
Actuators
- Motor and Wheels: Provides mobility to the robot.
- Water Pump: Used to pump water for extinguishing fires.
- Servo Motor: Precision rotary actuator used for positioning.
Control Modules
- Arduino UNO: The main microcontroller board for processing and control logic.
- HC-05 Bluetooth Module: Enables wireless communication for remote control.
- L298N DC Motor Driver: Controls the direction and speed of the motors.
- Relay 5V Single Connection: Electrically operated switch for controlling the water pump.
Power Management
- My Battery Case: Holds batteries to power the circuit.
- LM2596 Buck Converter: Steps down voltage to a lower level.
Switches
- Rocker Switch: A simple on/off switch.
- Toggle Switch SPST: Single Pole Single Throw switch for controlling circuit connectivity.
Wiring Details
KY-026 Flame Sensor
- A0: Analog output connected to the Arduino for flame intensity.
- GND: Ground connection.
- VCC: Power supply input.
- D0: Digital output connected to the Arduino for flame detection.
Ultrasonic Sensor
- Vcc: Power supply input.
- Trigger: Trigger pin connected to the Arduino for sending ultrasonic pulses.
- Echo: Echo pin connected to the Arduino for receiving the reflected pulses.
- Gnd: Ground connection.
Motor and Wheels
- vcc: Power supply input for the motor.
- GND: Ground connection for the motor.
Water Pump
- Positive: Positive power supply input.
- Negative: Ground connection.
Servo Motor
- Ground: Ground connection.
- Power: Power supply input.
- Signal: Control signal input from the Arduino.
Arduino UNO
- Digital and Analog Pins: Various I/O pins used for interfacing with sensors, actuators, and communication modules.
- 5V and GND: Power supply and ground connections for the board and connected components.
- Vin: Voltage input from the power source.
HC-05 Bluetooth Module
- Key: Used to enter AT command mode.
- VCC: Power supply input.
- TXD: Transmit pin connected to the Arduino's receive pin.
- RXD: Receive pin connected to the Arduino's transmit pin.
- State: Indicates the connection status.
- GND: Ground connection.
L298N DC Motor Driver
- OUT1, OUT2, OUT3, OUT4: Outputs to the motors.
- 12V: Power supply input for the motors.
- GND: Ground connection.
- 5V: Power supply input for the logic circuit.
- ENA, ENB: Enable pins for controlling motor speed.
- IN1, IN2, IN3, IN4: Input pins for controlling motor direction.
Relay 5V Single Connection
- VCC: Power supply input.
- GND: Ground connection.
- IN: Input signal from the Arduino to control the relay.
- NO, COMM, NC: Normally open, common, and normally closed contacts for switching.
LM2596 Buck Converter
- IN +, IN -: Voltage input.
- OUT +, OUT -: Voltage output.
Rocker Switch
- 1, 2: Pins for switching the circuit on and off.
Toggle Switch SPST
- L1, COM: Pins for controlling circuit connectivity.
Documented Code
Arduino UNO (Main Controller)
#include <Wire.h>
#include <Servo.h>
#include <Adafruit_MLX90614.h>
#include <SoftwareSerial.h>
// Define Ultrasonic Sensor Pins
#define TRIG_PIN A3
#define ECHO_PIN A2
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
// Define pins for flame sensors
#define FLAME_SENSOR_LEFT 4
#define FLAME_SENSOR_RIGHT 13
#define FLAME_SENSOR_FRONT 11
#define LM1 6 // Left motor forward
#define LM2 7 // Left motor backward
#define RM1 8 // Right motor forward
#define RM2 9 // Right motor backward
#define PUMP_PIN A1 // Water pump
#define enA 5 // Enable pin for left motor
#define enB 10 // Enable pin for right motor
#define BUZZER_PIN 3 // Buzzer pin
#define BLUETOOTH_RX 12
#define BLUETOOTH_TX 2
// Distance threshold to stop the robot (in cm)
#define DISTANCE_THRESHOLD 20
// Create SoftwareSerial object for Bluetooth communication
SoftwareSerial bluetooth(BLUETOOTH_TX, BLUETOOTH_RX);
void setup() {
// Initialize serial communication for Bluetooth
bluetooth.begin(9600);
Serial.begin(9600);
// Motor pins setup
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
// Sensors and actuators setup
pinMode(FLAME_SENSOR_LEFT, INPUT);
pinMode(FLAME_SENSOR_RIGHT, INPUT);
pinMode(FLAME_SENSOR_FRONT, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(PUMP_PIN, OUTPUT);
// Ultrasonic sensor setup
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
// Initialize actuators to be off
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(PUMP_PIN, LOW);
// Initialize MLX90614 sensor
mlx.begin();
}
void loop() {
// Read flame sensor values (digital)
bool leftFlame = digitalRead(FLAME_SENSOR_LEFT);
bool rightFlame = digitalRead(FLAME_SENSOR_RIGHT);
bool frontFlame = digitalRead(FLAME_SENSOR_FRONT);
// Measure distance using the ultrasonic sensor
long distance = measureDistance(); // This will also print the distance to the Serial Monitor
// Robot movement logic
if (distance <= DISTANCE_THRESHOLD) { // Obstacle detected within threshold
stopRobot();
if (!frontFlame) { // Flame detected in front after stopping
extinguishFire();
}
} else if (!frontFlame) { // Flame detected in front
moveForward();
} else if (!leftFlame) { // Flame detected on the left
moveRight();
} else if (!rightFlame) { // Flame detected on the right
moveLeft();
} else { // No flame detected
stopRobot();
}
// Bluetooth control
if (bluetooth.available()) {
char command = bluetooth.read();
controlRobotViaBluetooth(command);
}
}
void moveForward() {
Serial.println("Moving Forward");
analogWrite(enA, 120); // Write The Duty Cycle 0 to 255 Enable Pin A for Motor1 Speed
analogWrite(enB, 120);
digitalWrite(LM1, LOW);
digitalWrite(LM2, HIGH);
digitalWrite(RM1, LOW);
digitalWrite(RM2, HIGH);
}
void moveLeft() {
Serial.println("Turning Left");
analogWrite(enA, 200); // Write The Duty Cycle 0 to 255 Enable Pin A for Motor1 Speed
analogWrite(enB, 200);
digitalWrite(LM1, LOW); // Left Motor backward Pin
digitalWrite(LM2, LOW); // Left Motor forward Pin
digitalWrite(RM1, LOW); // Right Motor forward Pin
digitalWrite(RM2, HIGH); // Right Motor backward Pin
}
void moveRight() {
Serial.println("Turning Right");
analogWrite(enA, 200); // Reduce speed for turning
analogWrite(enB, 200);
digitalWrite(LM1, LOW); // Left Motor backward Pin
digitalWrite(LM2, HIGH); // Left Motor forward Pin
digitalWrite(RM1, LOW); // Right Motor forward Pin
digitalWrite(RM2, LOW); // Right Motor backward Pin
}
void stopRobot() {
Serial.println("Stopping Robot");
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
}
void extinguishFire() {
Serial.println("Extinguishing Fire");
// Activate buzzer and pump for fire extinguishing
digitalWrite(BUZZER_PIN, HIGH);
digitalWrite(PUMP_PIN, HIGH);
// Run pump for a certain period (adjust time as needed)
delay(5000