-
The
Servo
andNewPing
libraries are included for controlling the servo motor and ultrasonic sensor, respectively. -
The control pins for the motor driver (L298N) are defined.
-
Sensor pins are assigned to the trig_pin and echo_pin for the ultrasonic sensor.
-
The maximum distance is set to 200.
-
The
setup()
function is used to configure pin modes and initialize the servo motor. -
The servo motor is attached to pin 10 and positioned at 115 degrees.
-
Distance measurements are taken by the ultrasonic sensor to calibrate and stabilize the readings.
-
The
loop()
function is the main program loop that executes continuously. -
Inside the
loop()
function, the robot's movement is controlled based on the distance readings. -
If the distance is less than or equal to 20, the robot stops, moves backward, and then turns either right or left based on the further distance sensed by looking right and left.
-
If the distance is greater than 20, the robot moves forward.
-
The
lookRight()
function positions the servo motor to look right, takes a distance measurement, and then returns the distance. -
The
lookLeft()
function positions the servo motor to look left, takes a distance measurement, and then returns the distance. -
The
readPing()
function is used to read the distance from the ultrasonic sensor and handle any measurement errors. -
The
moveStop()
,moveForward()
,moveBackward()
,turnRight()
, andturnLeft()
functions are defined to control the robot's movement in different directions based on the motor driver pin configurations. -
The
delay()
function is used to introduce specific time delays for smooth operation and to allow the robot to complete movements.
-
Notifications
You must be signed in to change notification settings - Fork 0
The code implements a robot that uses an ultrasonic sensor for obstacle detection and performs obstacle avoidance by stopping, moving backward, and looking in different directions using a servo motor.
KD-27/Obstacle-Avoiding-robot
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
The code implements a robot that uses an ultrasonic sensor for obstacle detection and performs obstacle avoidance by stopping, moving backward, and looking in different directions using a servo motor.
Topics
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published