This circuit is designed to interface an Arduino UNO with various sensors and actuators, including IR sensors, an ultrasonic sensor (HC-SR04), a DC motor driver (L298N), hobby gearmotors, a servo motor (SG90), a rocker switch, and a Li-Ion battery (18650). The Arduino UNO controls the motors through the motor driver, reads distance measurements from the ultrasonic sensor, and detects object presence with IR sensors. The servo motor is controlled directly by the Arduino. Power management is handled through the battery, motor driver, and a rocker switch.
#include <Servo.h>
int pathLength = 0;
int irSensorPin1 = 2;
int irSensorPin2 = 3;
int irSensorPin3 = 4;
int irSensorPin4 = 5;
int irSensorPin5 = 6;
const int trigPin = 7;
const int echoPin = 8;
int ena = 9;
int enb = 10;
int in1 = A1;
int in2 = A2;
int in3 = A3;
int in4 = A4;
Servo myServo;
long duration;
int distance;
int irValue1 = 0;
int irValue2 = 0;
int irValue3 = 0;
int irValue4 = 0;
int irValue5 = 0;
int pos = 0;
char path[30]; // path storing
void setup() {
pinMode(irSensorPin1, INPUT);
pinMode(irSensorPin2, INPUT);
pinMode(irSensorPin3, INPUT);
pinMode(irSensorPin4, INPUT);
pinMode(irSensorPin5, INPUT);
myServo.attach(11);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
pinMode(ena,OUTPUT);
pinMode(enb,OUTPUT);
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
}
void loop() {
Serial.println("chal gya kutte");
irValue1 = digitalRead(irSensorPin1);
irValue2 = digitalRead(irSensorPin2);
irValue3 = digitalRead(irSensorPin3);
irValue4 = digitalRead(irSensorPin4);
irValue5 = digitalRead(irSensorPin5);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Trigger the sensor by setting the TRIG pin HIGH for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
// Calculate the distance in centimeters
distance = duration * 0.034 / 2;
// ... (Code continues with logic for motor control and path tracking)
}
// ... (Additional functions for motor control and path simplification)
Note: The code provided is a partial listing, focusing on setup and main loop structure. It includes pin assignments, sensor readings, and basic motor control logic. The full code would contain additional logic for path tracking, motor control functions, and path simplification algorithms.