exp 4
exp 4
Algorithm:
Step 1: Start
Step 2: Include required libraries
• AFMotor (for controlling motors with Adafruit Motor Shield)
• NewPing (for ultrasonic distance measurement)
• Servo (for rotating the ultrasonic sensor)
Step 6: Sub-functions
• readPing() → Measures distance using ultrasonic sensor. If
reading is 0, assume it’s 250 cm (no object).
• moveForward() → Starts motors in forward direction and
gradually increases speed.
• moveBackward() → Moves robot backward with gradual speed
increase.
• moveStop() → Stops all motors.
• turnRight() / turnLeft() → Spins wheels in opposite directions to
rotate the robot.
Output: