How to test if an ultrasonic sensor is fine


#1

Some users may have the issue that the robot fails to avoid obstacle as it should be, then after checking firmware information, connection and other factors, it is necessary to check whether the ultrasonic sensor is still working fine. Here I’ll include three methods to test the ultrasonic sensors, with mBlock 3 software, mBlock 5 software and Arduino IDE. By the way, here I take mCore (mBot) as an example.

  1. Test with mBlock 3. You can download here and install this software:
    http://www.mblock.cc/mblock-software/



    Once installed, please upgrade firmware for the mBot first (refer to mBot FAQ1)
    Then run below online codes:

  2. Test with Arduino IDE. In mBlock 3, you can drag mBot program, the right click on it, choose “upload to arduino”:

Then it shows below picture, please choose edit with arduino ide:

Then go to files->examples->makeblockdrive->meultrasonicsensor->ultrasonic sensor test->open it:


Then choose board and port under tools:
image

If you have mBot, choose Arduino/genuino uno. Also change the codes as below:
image
Then press upload icon:
image

Once upload, choose the serial port monitor:
image

Then we’ll see below:

  1. Test with mBlock 5 the one that you installed.
    Connect USB from mbot to computer with USB cable, then update firmware:

Then code like below: (you need variable)

Or go to Sprite, code like this:



mBot Ultrasonic Sensor not working
#2

Hi, I am also having the issue that the ultrasonic sensor is not working properly. I uploaded the factory settings and in obstacle-avoidance mode the bot just goes straight bumping into the next obstacle.

I build the small program above to test the sensor and there it did show me the distance in cm quite accurately. So how come the sensor works when being tested and not when in operation?


#3

Hi mBotDaddy,

Since the distance values are accurate when tested online. The sensor should be okay.
For the issue that the obstacle avoidance mode doesn’t work in factory settings, could you reset default program for the robot again refer to this instruction.

If the obstacle avoidance mode still doesn’t work, I suspect the robot lacks of the power, please change totally brand new batteries or fully charged lithium battery for it have a try.