How to integrate ultrasonic sensor?


#1

Hello,
we (my daughter and I) are new to mBlock (got the Makeblock Starter Robot Bluetooth Kit for Christmas).
We have already created a few mBlock programs and are able to control the tank.

Now we would like to go to the next step and add sensor functionality to our code.

I would like to e.g. write a short code that will make the bot go forward while the distance reported by the sensor is greater than 10.

This is what I tried so far.

Test Sensor2.sb2 (74.6 KB)

What am I missing?

If I only read the value from the sensor (e.g. having the panda “say” the distance value), the sensor value is being reported correctly.

Thank you very much in advance for any hint.

Best regards,
N.Vi


#2

N.Vi

Try adding a forever loop around the if statement. Your current program will execute only once, and give you one reading. By adding the loop, it will give you many readings.

Mike


#3

Hi mddickey,
thank you very much!
That did the trick.
Best regards,
N.Vi


#4

I was working on this starter robot with my son and have tried to get the programming to work for avoiding obstacles. When I upload the program though the robot does not respond to the remote or do anything at all. any thoughts based on the code?


#5

So the code above will run forward if there is an obstacle closer than 10cm.
It will turn if the obstacle is closer than 5cm.

However, it will not listen to the IR remote unless you enhance your program. Reason is that when you upload the program to the bot, it replaces the default program which listens to the IR remote.