Arduino-Controlled Obstacle Avoidance Robot with Bluetooth Interface
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
The circuit in question is a complex system designed to control various components including motors, sensors, and actuators through an Arduino UNO microcontroller. The system is capable of driving motors, sensing distances, and communicating via Bluetooth. It includes a relay module for controlling power to a water pump and a peristaltic pump, as well as IR sensors for object detection. LEDs and a buzzer provide visual and auditory feedback, respectively. The circuit is powered by a combination of a Li-ion battery and a polymer lithium-ion battery.
Component List
- 1 Channel 5V Relay Module: A relay module for controlling high power devices.
- 5v Mini Water Pump: A small pump for moving water.
- Arduino UNO: A microcontroller board based on the ATmega328P.
- HC-SR04 Ultrasonic Sensor: A sensor for measuring distances using ultrasonic waves.
- 1-Channel Relay (5V 10A): Another relay module for controlling devices.
- HC-05 Bluetooth Module: A Bluetooth module for wireless communication.
- LED (Red and White): Light-emitting diodes for visual indicators.
- L298N DC Motor Driver: A motor driver module for controlling DC motors.
- Buzzer: An electronic buzzer for auditory signals.
- Peristaltic Pump: A type of pump used for precise fluid movement.
- Polymer Lithium Ion Battery - Generic: A rechargeable battery for power supply.
- Li-ion Battery, 2200 mAh 11.1 V: Another rechargeable battery for power supply.
- Hobby Gearmotor with 48:1 Gearbox: Motors for driving mechanical parts.
- IR Sensors: Infrared sensors for object detection.
- Rocker Switch (SPST): A single-pole single-throw switch for controlling power.
- LED: Four Pin: A multi-color LED with separate pins for different colors.
Wiring Details
1 Channel 5V Relay Module
- VCC+ to +5V power supply
- VCC- (GND) to ground
- IN connected to Arduino UNO (D4)
- N.O. connected to Peristaltic Pump (Coil1)
- COM connected to Polymer Lithium Ion Battery (VCC)
5v Mini Water Pump
- Positive pin connected to 1-Channel Relay (5V 10A) (C)
- Negative pin to ground
Arduino UNO
- Vin connected to various VCC pins of other components
- GND connected to various GND pins of other components
- 3.3V connected to LED: Four Pin (common anode)
- Digital pins (D0-D13) connected to various components for control signals
- Analog pins (A0-A5) connected to IR sensors and HC-SR04 Ultrasonic Sensor
HC-SR04 Ultrasonic Sensor
- VCC to +5V power supply
- TRIG connected to Arduino UNO (D9)
- ECHO connected to Arduino UNO (A4)
- GND to ground
1-Channel Relay (5V 10A)
- NC not connected
- Signal connected to Arduino UNO (D12)
- C connected to 5v Mini Water Pump (positive pin)
- Power connected to 1 Channel 5V Relay Module (VCC+)
- NO not connected
- Ground connected to 1 Channel 5V Relay Module (VCC- (GND))
HC-05 Bluetooth Module
- EN not connected
- VCC to +5V power supply
- GND to ground
- TXD connected to Arduino UNO (D0)
- RXD connected to Arduino UNO (D1)
- STATE not connected
LEDs (Red and White)
- Cathode to ground
- Anode (Red) connected to Arduino UNO (D13)
- Anode (White) connected to Arduino UNO (D13)
L298N DC Motor Driver
- OUT1/OUT2 connected to Hobby Gearmotors
- 12V connected to Rocker Switch (SPST)
- GND to ground
- 5V to +5V power supply
- IN1-IN4 connected to Arduino UNO (D5-D11)
Buzzer
- PIN connected to Arduino UNO (D7)
- GND to ground
Peristaltic Pump
- Coil1 connected to 1 Channel 5V Relay Module (N.O.)
- Coil2 connected to Polymer Lithium Ion Battery (GND)
Polymer Lithium Ion Battery - Generic
- VCC connected to 1 Channel 5V Relay Module (COM)
- GND connected to Peristaltic Pump (Coil2)
Li-ion Battery, 2200 mAh 11.1 V
-
- connected to Rocker Switch (SPST) (2)
-
- to ground
Hobby Gearmotors
- Pin 1 of each motor connected to L298N DC Motor Driver (OUT1/OUT3)
- Pin 2 of each motor connected to L298N DC Motor Driver (OUT2/OUT4)
IR Sensors
- Out connected to Arduino UNO (A0-A3)
- GND to ground
- VCC to +5V power supply
Rocker Switch (SPST)
- Pin 1 connected to L298N DC Motor Driver (12V)
- Pin 2 connected to Li-ion Battery, 2200 mAh 11.1 V (+)
LED: Four Pin
- Common anode connected to Arduino UNO (3.3V)
- Red cathode connected to Arduino UNO (D8)
- Green cathode connected to Arduino UNO (D3)
- Blue cathode connected to Arduino UNO (D2)
Documented Code
#define in1 5 //L298n Motor Driver pins.
#define in2 6
#define in3 10
#define in4 11
#define EXTRA 4
const int trigPin = 9;
const int echoPin = 18;
long duration;
int distance;
#define light_FR 13 //LED Front Right pin A0 for Arduino Uno
//#define light_FL 15 //LED Front Left pin A1 for Arduino Uno
#define light_BR 12 //LED Back Right pin A2 for Arduino Uno
//#define light_BL 17 //LED Back Left pin A3 for Arduino Uno
#define horn_Buzz 7 //Horn Buzzer pin A4 for Arduino Uno
int command; //Int to store app command state.
int Speed = 204; // 0 - 255.
int Speedsec;
int buttonState = 0;
int lastButtonState = 0;
int Turnradius = 0; //Set the radius of a turn, 0 - 255 Note:the robot will malfunction if this is higher than int Speed.
int brakeTime = 45;
int brkonoff = 1; //1 for the electronic braking system, 0 for normal.
boolean lightFront = false;
boolean lightBack = false;
boolean horn = false;
boolean extra = false;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT);
pinMode(EXTRA,OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(14,INPUT);
pinMode(light_FR, OUTPUT);
// pinMode(light_FL, OUTPUT);
pinMode(light_BR, OUTPUT);
// pinMode(light_BL, OUTPUT);
pinMode(horn_Buzz, OUTPUT);
Serial.begin(9600); //Set the baud rate to your Bluetooth module.
}
void loop() {
// Ultrasonic distance measurement
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.println(distance);
// Obstacle detection and buzzer alert
if(distance < 25){
Stop();
delay(100);
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
delay(500);
Stop();
buzzerAlert();
}
// IR sensor detection and response
if (digitalRead(14) == HIGH){
Stop();
delay(100);
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
delay(300);
Stop();
buzzerAlert();
}
// Additional IR sensor detection and response
// Code for IR sensors connected to pins A1, A2, A3 (15, 16, 17) is similar to above
// Bluetooth command processing
if (Serial.available() > 0) {
command = Serial.read();
Stop(); //Initialize with motors stopped.
updateLights();
updateHorn();
updateExtra();
processCommand();
}
}
// Function definitions for motor control, light and horn updates, command processing, etc.
// ... (omitted for brevity)
void buzzerAlert(){
for(int i = 0;