March 2019
Intermediate to advanced
312 pages
7h 37m
English
In this program, we will first find out the distance of a nearby object using the ultrasonic sensor. Next, we will create an if condition that monitors the distance value. If the distance goes below a certain value, we will command the robot to take a turn. Otherwise, the robot will keep moving forward. You can download the complete code called ObstacleAvoiderRobot.cpp from Chapter04 in the GitHub repository:
int main(){...for(;;){...if(distance < 7){digitalWrite(0,LOW);digitalWrite(2,HIGH);digitalWrite(3,HIGH);digitalWrite(4,LOW);delay(500);moveCursor(firstrow);printmessage("Obstacle Status");moveCursor(secondrow);printmessage("Obstacle detected");clear();}else{digitalWrite(0,HIGH);digitalWrite(2,LOW); ...