Raspberry Pi2 Reading Distance From RhydoLabz “ECHO –PRO” Ultrasonic Distance Sensor

RhydoLabz “ECHO –PRO, 5in 1” Ultrasonic Distance Sensor is an amazing product that provides very short to long-range detection and ranging with a resolution of 1mm. The ECHO-PRO is a 5 in 1 sensor module which output the distance data as Serial ASCII, Pulse width and Analog output. The module has an onboard temperature sensor which outputs the ambient temperature via Serial ASCII. Apart from this the module is also equipped with Proximity sensing output, which will generate a high going signal if any object comes under the presented distance range (2-500cm). Since there are various interfacing options (ASCII, PWM and ANALOG) available on the module as a standard, it will be easy for a developer to select the optimum one based on the resources available on the micro controller.

Here Raspberry Pi2 is interfaced with this sensor to measure the obstacle’s distance. As the Raspberry pi could be used for high end applications, the interfacing with particular sensor will be very much useful to create an intelligent embedded system. Making of an advanced robot using Raspberry pi should meet these requirements in a proper manner, so that an intelligent robot will be developed. In this type of sensor there is an option for getting the distance in the form of serial ASCII, and we make use of this property to obtain data to the Raspberry Pi.Modules Needed

Make the connections as shown in the figure, the sensor module is powered with a power supply using 5V and the ground connection of the supply is provided to both sensor and Raspberry Pi (pin 6). The ASCII output pin is connected to the reception pin of the Raspberry Pi.  Now power on the Pi module and receive the data coming through the reception pin using Python. A sample code for this process is given below:

Sample Code to Interface Ultrasonic Distance Sensor with Raspberry Pi

By running this code the distance in centimeters is shown in the python shell. ASCII Serial Data output produces a TTL (Transistor Transistor Logic) output at a baud rate of 9600 including both distance and temperature sensor outputs in the format “DXXX.XTXXX” along with a ‘\r’ symbolizing the end of the string. For example “D145.6T030” where ‘D’ followed by distance in centimeters and ‘T’ followed temperature in degree Celsius. Here the user doesn’t need to calibrate the value read making it easier to interface. So as in the program, to get the distance the data in between the characters ‘D’ and ‘T’ should be extracted.

Shop With Us

  • Click here to buy Raspberry Pi 2 from rhydoLabz
  • Click here to buy ECHO-PRO ( 5 in 1 Distance Sensor Module)

Resources

Leave a Reply