What is obstacle-avoiding robot? How does it work? Let’s try to make one

Code Explanation
 


Library for servo motor and ultrasonic sensor.


Define L298N motor driver control pins.


Define analog inputs of ultrasonic Trigger pin and Echo pin.


Setting the initial variable values.


Function calling for sensor and motor.


Enter into void setup. Setup the pin modes and servo motor pins.


In the void loop function, the robot will check if the detected distance is below 20. If it is, the robot will proceed to scan the left and right directions to determine the presence of any obstacles.
If the distance to the left is equal to or less than the distance to the right,the robot will make a right turn. Conversely, if the distance to the left is greater than the distance to the right, the robot will make a left turn.


Otherwise the robot will move in forward direction.


This is servo right and left check function.


The function here sends a ping signal and retrieves the distance in centimeters. It then proceeds to print the obtained result.


Function of stop moving.


Function of moving forward.


Function of moving backward.

 

Function of right turn.


Function of left turn.

 
Facebook
Twitter
LinkedIn

Table of Contents