An Ultrasonic sensor is a device that can measure the distance to an object by using sound waves.

  • Ultrasonic sensors emit short, high-frequency sound pulses at regular intervals.
  • These propagate in the air at the velocity of sound. If they strike an object, then they are reflected back as echo signals to the sensor, which itself computes the distance to the target based on the time-span between emitting the signal and receiving the echo.
  • As the distance to an object is determined by measuring the time of flight and not by the intensity of the sound, ultrasonic sensors are excellent at suppressing background interference.

  • It can be used for level indication, detection of obstacle, for distance measurement. Goto mblock software and open it. Goto edit menu and select Arduino mode.

  • Playme Robot Program is a Header file for Robot programming.
  • It makes programming simple. By using this we can access all blocks easily and smoothly.
  • If we are not using this then it may give us errors in program. So put this at start of program.

  • Here we are using loop. Loop is area which will be repeated for certain times depending upon its type.
  • If we write anything inside loop then it will be repeated along with loop. Forever loop means program will run continuously.
  • For example: If we write a program to run motor in forward direction with forever loop then it will run until we remove power applied to it.
  • Select block Send to Computer and drag it in programming window.

  • Put it in forever loop.

 

 

  • To get distance of obstacle from playme select Ultrasonic sensor distance block.

  • Connect that block to Send to computer .

  • Connect wait statement of 1second below this.

  • Now save program.

  • Give name to program.

  • Select COM port and upload the program
  • Again go to Serial port and select COM port

  • And see output of your program

  • You can see this response which is not distance. To get proper message select Char mode for both send encode mode, recv encode mode.

 

 

  • And see distance on your screen. It will be displayed on screen after every one second.
  • You can put any obstacle like your hand in front of sensor you can see change in distance value.