Robotics & Artificial Intelligence
Answer
Left Move:
To give left movement to the robot, its right wheels should be stopped, and left wheels should be in motion. For this purpose, LOW values are sent to pins 3 and 5, and HIGH values are sent to pins 6 and 9 using the digitalWrite() function. As a result, the right-side wheels stop moving, and only the left-side wheels move, giving the robot a left-hand move. The code for left turn is given below:
void turn_left()
{
digitalWrite(3, LOW);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(9, HIGH);
}
Right Move:
To give right movement to the robot, its left wheels should be stopped, and right wheels should be in motion. For this purpose, HIGH values are sent to pins 3 and 5, and LOW values are sent to pins 6 and 9. Consequently, the left-side wheels stop, and only the right-side wheels move, giving the robot a right-hand move. The code for right turn is given below:
void turn_right()
{
digitalWrite(3, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(9, LOW);
}