Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

« Previous Version 3 Next »

Task

Create a program such that the rotation speed and direction of a motor is dependent on the distance from an obstacle as given in the table below. The motor has to be powered using a separate battery, and not from Arduino (Arduino only controls the motor, does not power it).

Distance from ObstacleMotor Rotation
Distance > 50 cmClockwise, full-speed
35 < Distance <= 50 cmClockwise, quarter-speed
30 < Distance <= 35 cmNo rotation
20 < Distance <= 30 cmAnticlockwise, quarter-speed
Distance <= 20 cmAnticlockwise, full-speed

Hints

  • Combine the codes and circuits in Ultrasonic Distance Sensor and DC Motors, and use multiple if conditions. You will need ifs to be nested, i.e., ifs within ifs.
  • analogWrite() with values 255,0 (dir1speed,dir2speed) and 64,0 respectively can be used for full-speed and quarter-speed clockwise rotation. 0,255 and 0,64 can be used for full-speed and quarter-speed anticlockwise rotation respectively. The speed is not perfectly linearly related to the value (duty cycle) in practice, and that is ok for this exercise.
  • No labels