Hello folks! Today I would like to show you a simple project for ultrasonic distance measurement using the RL78 and a HC-SR04 ultrasonic ranging module.

The sensor module itself is a small PCB with two ultrasonic transducers (one for transmitting and one for receiving) along with some circuitry for signal generation and reception. The sensor module is pictured below.

HC-SR04 ultrasonic module

It can be easily purchased at any electronics store and online at DealExtreme, eBay, WayEngineer, Goodluckbuy, etc.

Its usage is fairly simple: all you have to do it is to supply its power supply pins (VCC and GND pins) with 5V and then trigger a measurement by applying a pulse (minimum period is 10µs) on Trig pin. The sensor will transmit 5 ultrasonic pulses and when the echo is received the ECHO pin outputs a pulse proportional to the time elapsed between the pulse trigger and the echo receiving.

One can easily calculate the distance between the sensor and the target by using the following equation (written in Portuguese, pulso_retorno = ECHO output pulse width)

distance_f1

Note that the equation considers a constant value for the sound speed. In real life applications that speed varies with temperature, so it is better account for it too.

So, if the measured pulse has a 1000µs width, the target is located about 0,17m far from the sensor. In order to get the distance in centimeters one could use the following equation:

distance_f2

Please note that, for calculation purposes, the measured pulse should always use 1µs time base! The code listing is shown below. The TRIG pin must be wired to RL78/G13’s P4.1 pin and ECHO must me wired to RL78/G13’s P4.2 pin (TI04 input). The application was tested on the RL78/G13 RSK board.

RL78 RSK with the ultrasonic module mounted

Ultrasonic distance measurement with RL78 and HC-SR04 module
Tagged on:                     

Leave a Reply