Programming the Ultrasonic sensor


#46

Sorry I am afraid there is no way to code and let it running in distance not time for mBot motors.


#47

So the only is to make the robot move for a period of time and check the distance covered and start to adjust time according to the distance i want?
Another question is how can i get a return value for the distance measured by the ultrasonic sensor.
I created 2 variables and set each variable to a distance measured by the ultrasonic … then i set it in motion to move the difference between these two values and it’s not working no matter what i do … any ideas to make it work??
Thanks in advance


#48

For better follow up, I created a ticket and please check your email box.


#49

Thank you it works, I been looking for a solution so that I can use a generic HC-SR04. I just solder Echo and Trig and connect to ME JR25. then use the mblock code. It works perfectly. I hope I can also contribute on this forum. Thanks again


#50

My Ultrasonic sensor is not working. However, it is connected on port 3. Any suggestions? .


#51

Hi dhanushx012,

Please chang the RJ25 cable between ultrasonic sensor and the mainboard have a try. You can use the cable for the line follower senser temporarily.

Then please reset factory firmware for mBot with mBlock 5 software and see if the obstacle avoidance mode works.


#52

I’ve found that when I have sensors acting up it is usually time to go through the Upgrade Firmware + Reset Default Program cycle to clear out anything that might be hanging around in memory


#53

Still waiting for someone to help me with my issue.

Thanks in advance.


#54

Hi oliverthom707,

5 months of waiting, phew … Can you explain the situation to me … I stopped reading this post … too long;)


#55

I’ve had the same issue when running through the mBlock environment.


#56

Hello there! This is one code you can use in mBlock 5 online (ide.mblock.cc):