This circuit is designed to control a robotic vehicle with multiple functionalities including Bluetooth control, line following, obstacle avoidance, and remote control via an IR receiver. The core of the circuit is an Arduino UNO microcontroller which interfaces with an L298N DC motor driver for motor control, HC-05 Bluetooth Module for wireless communication, ultrasonic sensor for distance measurement, IR sensors for line following, and a micro servo for actuation. The circuit is powered by a 7.4V battery, and a rocker switch is used to turn the power on and off.
#include <SoftwareSerial.h>
SoftwareSerial BT_Serial(2, 3); // RX, TX
#include <IRremote.h>
const int RECV_PIN = A5;
IRrecv irrecv(RECV_PIN);
decode_results results;
#define enA 10 // Enable1 L298 Pin enA
#define in1 9 // Motor1 L298 Pin in1
#define in2 8 // Motor1 L298 Pin in2
#define in3 7 // Motor2 L298 Pin in3
#define in4 6 // Motor2 L298 Pin in4
#define enB 5 // Enable2 L298 Pin enB
#define servo A4
#define R_S A0 // IR sensor Right
#define L_S A1 // IR sensor Left
#define echo A2 // Echo pin
#define trigger A3 // Trigger pin
int distance_L, distance_F = 30, distance_R;
long distance;
int set = 20;
int bt_ir_data; // Variable to receive data from the serial port and IRremote
int Speed = 130;
int mode = 0;
int IR_data;
void setup() {
// Initialize pins as inputs or outputs
pinMode(R_S, INPUT);
pinMode(L_S, INPUT);
pinMode(echo, INPUT);
pinMode(trigger, OUTPUT);
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(servo, OUTPUT);
// Initialize IR receiver and serial communication
irrecv.enableIRIn();
irrecv.blink13(true);
Serial.begin(9600);
BT_Serial.begin(9600);
// Move servo to initial positions
for (int angle = 70; angle <= 140; angle += 5) {
servoPulse(servo, angle);
}
for (int angle = 140; angle >= 0; angle -= 5) {
servoPulse(servo, angle);
}
for (int angle = 0; angle <= 70; angle += 5) {
servoPulse(servo, angle);
}
delay(500);
}
void loop() {
// Read Bluetooth data
if (BT_Serial.available() > 0) {
bt_ir_data = BT_Serial.read();
Serial.println(bt_ir_data);
if (bt_ir_data > 20) {
Speed = bt_ir_data;
}
}
// Read IR remote data
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
bt_ir_data = IRremote_data();
Serial.println(bt_ir_data);
irrecv.resume(); // Receive the next value
delay(100);
}
// Process received data and control the robot
// ... (rest of the code)
}
// Additional functions for IR data processing, servo control, ultrasonic reading, and motor control
// ... (rest of the functions)
Note: The code provided above is a partial representation of the full code. It includes setup and loop functions, initialization of components, and reading of Bluetooth and IR data. The rest of the code, indicated by comments, would contain the logic for processing the received data and controlling the robot's movements, as well as additional functions for servo control, ultrasonic reading, and motor control.