Questions about Ultrasonic sensor + speed


#1

I can use the ultrasonic sensor to define the speed of the mbot, so that every time the mbot approaches an obstacle it slows down until it stops completely???Has anyone done it yet?

Thank you


#2

Yes, can be done with less than 10 lines.

Do you want to figure it out yourself?


#3

I accept some tips … hehehehe


#4

Ok some tips

  1. Ultrasonic sensor can detect up to 200 cm (value is 200 then). Anything beyond that is usually returned as 400.

  2. Highest speed setting for motor is 255, lowest value which will work is 75 - below that the mBot will usually stop anyway

  3. It is a good idea to stop 10 cm before the obstacle

More tips?

Which software are you using? mBlock on PC?

PS: just tried it myself, works in 9 lines


#5

I’m using mblock on the pc, but I still can not solve it yet hehehe, the only thing I can do is mbot stop having a value less than 10


#6

You will need to adjust the 1st “run forward” block. Calculate the speed there depending on the distance. I gave you some hints for that above.


#7

I can not understand, if possible you can explain to me…


#8

Your project is to have the mBot slow down when it approaches an obstacle, correct?

So have it run with full speed (255) for a distance of 200 cm. And have it slow down to 75 (minimum speed) when it approaches 10 cm. You need to use the operators tab in mBlock to set up the formula which gives you the desired speed setting.


#9

I gave up and could not do it, you can show it to me. :disappointed:


#10

Hey when I was giving up I tried for the last time and I guess this result needs some adjustments, but I got the result I wanted. The mbot stopping when he comes close to an obstacle. Thank you for all the help you gave me.


#11

check this out!


#12

for sure i will, look simpler


#13

i ve made an edit, check again, be sure for the right port for ultrasonic! good luck hope i helped…
i also put some lights for every speed so i can check all the time for the distance


#14