Skip to content

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.

Notifications You must be signed in to change notification settings

KD-27/Obstacle-Avoiding-robot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

  1. The Servo and NewPing libraries are included for controlling the servo motor and ultrasonic sensor, respectively.

  2. The control pins for the motor driver (L298N) are defined.

  3. Sensor pins are assigned to the trig_pin and echo_pin for the ultrasonic sensor.

  4. The maximum distance is set to 200.

  5. The setup() function is used to configure pin modes and initialize the servo motor.

  6. The servo motor is attached to pin 10 and positioned at 115 degrees.

  7. Distance measurements are taken by the ultrasonic sensor to calibrate and stabilize the readings.

  8. The loop() function is the main program loop that executes continuously.

  9. Inside the loop() function, the robot's movement is controlled based on the distance readings.

  10. 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.

  11. If the distance is greater than 20, the robot moves forward.

  12. The lookRight() function positions the servo motor to look right, takes a distance measurement, and then returns the distance.

  13. The lookLeft() function positions the servo motor to look left, takes a distance measurement, and then returns the distance.

  14. The readPing() function is used to read the distance from the ultrasonic sensor and handle any measurement errors.

  15. The moveStop(), moveForward(), moveBackward(), turnRight(), and turnLeft() functions are defined to control the robot's movement in different directions based on the motor driver pin configurations.

  16. The delay() function is used to introduce specific time delays for smooth operation and to allow the robot to complete movements.

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

No packages published

Languages