An analog distance sensors is to be connected to an Arduino Uno R3. The sensor requires 5V and GND to operate and gives a single analog output (Dout) in the range 0à5V. The voltage is related to (not as cousins) the distance according to the equation: Distance (in cm) = 11 x V + 4. Write a C function to keep the robot away from objects by at least 8 cm. Use the function setMotors(LeftMspeed, RightMspeed) to set the speed of left and right motors. The speed a number between -100 to 100. When both motor speeds are positive (robot moves forward) and when both motor speeds are negative (robot moves backward). Assume sensor is positioned such that it detects objects in front of the robot.
I am providing the general algorithm to achive the above task .
It says that
Analog Sensor is connected
Sensor requires 5V and GND
Output of sensor (Dout) 0-5V
(Distance)D=11*V+4
function C(To keep robot 8cm away from object)
setMotors(LeftMspeed,RightMspeed)
-100 to 100
Step 1:
C(int D)
{
D=11*V+4 //V is output of sensor
if(D<=8)
{
setMotors(-100,-100); //To move the Bot in backward direction
delay(2 ms);
setMotors(50,0); //To make the robot rotate in reverse direction
delay(1 ms);
setMotors(50,50) ; //Continue moving bot in forward direction
}
else
setMotors(50,50);
}
Get Answers For Free
Most questions answered within 1 hours.