Driving two pins of a MAX232 complementary, it returns on the RS232 side a +12V, -12V. Using the enhanced PWM module of a PIC18F2431 instead of a 2620, it's very easy to have this kind of complementary driving.
Using the internal voltage reference and the analog comparator, can be achieved the same functionality of the digital potentiometer attached to external op-amp that adjusts the sensitivity of the system.
So, the PIC circuit and the software can be kept almost untouched and analog circuit can be personalized.
updated on 24-06-2012

Quad Sonar

Hacking a cheap parking sensor system to obtain
a quadruple, waterproof Sonar Range Finder
Se volete leggere lo stesso articolo in italiano, potete trovarlo su Fare Elettronica n.234 di giugno 2012

The circuit is based on the test schematic depicted in the US transducer data sheet.The transformer is tuned on 40kHz with the capacitance of the transducer, using the moving core. The voltage swing on the capsule is 100Vp-p. Of course the waveform applied is not sinusoidal but, with the narrow band-pass filter created by the ceramic resonator, that double filters out harmonics when used both as a speaker and as a microphone, the returning waveform is very close to sinusoidal. As explained in the data sheet the decay time of such a circuit is about 1ms. This limits the minimum distance that this system can measure.

Ok. At this point is easy to change the original MCU with a PIC, in order to achieve a customizable system with, for example, different communication protocols, different measuring rang, different measuring cycle time, etc.
A PIC18F2620 has the right peripherals to do everything I want:
-A PWM module to generate the 40kHz burst.
-A analog comparator module to reveal the echo.
-An internal adjustable voltage reference to select comparator sensitivity.
-Enough I/O pins to drive the multiplexer.
-I2C module to use the whole system as a slave sensor as a Sonar Range Finder robotic module do.
-Serial module to send out the values for a simpler debug.

In order to use slave I2C communication protocol, the MCU has to be fast to replay to the master. Using the MCU hardware peripherals, timers modules and interrupts, is easy to realize a Finite State Machine that does nothing most of the time, just waiting for interrupts.
Timer0 (as a 16 bit timer) is loaded with different values in the different states. A short pulse to drive the PWM module at 50% duty cycle 40kHz. A longer time to wait until the decay time of the capsule driver is over. The rest to wait the echo back before selecting another transducer.
Meanwhile the CCP capture module is activated associated to Timer1.
When the echo is back an analog comparator rises up an I/O pin, ordering to the capture module to get a snapshot of the Timer1 registers. That is the flying time of the ultrasonic burst, to the object and back. Dividing it by two and multiplying by the sound speed we have the distance of the object.
Adjusting the value of the internal Voltage Reference module, we can vary the sensitivity of the system, meaning the maximum range.

The board is very easy to work on. The schematic is simple to understand as well.
An Original 8051 based microcontroller in 20-pin PDIP case, even mounted on a socket. A Seven darlington arrays that supply the power to the resonating circuit instead of the transistor.
A Dual 4-channel analogue multiplexer/demultiplexer to select one out of four Ultrasonic Transducer. A Dual operational amplifier to amplify the returning echo.
The MCU generates the 40kHz burst and the amplified echo returns back to an analog port. Only the first echo is analyzed.

A simple pigtail board wired on a perfboard, is plugged on top of the socket instead of the original MCU.
I've added a pull-down resistor on the original board to avoid a continuous driving of the power section during the debug, i.e. when the input is steady high.

Eventually I got it, in a chinese shop. There are different models, starting at 25€ up to 120€. The cheapest one has 4 sensors, a numeric display and a buzzer. The most expensive one has a video camera and the display integrated in the rear mirror.

I've got the cheapest model. Four waterproof sensors, a wired display (there are with wireless display too) and also the drill bit to make the right size hole for the transducers. There also are models with 6 or 8 sensors. Always the same board, more or less components mounted on.

The display is connected with 3 wires: PWR +, GND and signal. Not a standard communication protocol, here I've found someone else that hacked a very similar system.
As clear described, the protocol allows only two kind of parameters: right and left, not any single sensor distance. The number is the nearest obstacle distance, the led bars show on which side it is.
Into the display box there is another MCU that decodes the protocol and drives numbers and bars.

The whole MPLAB X project
is available as an open source at
Google code repository

This video shows how the echo comes back after the amplification. We can see here the effect of the decay time described in the data sheet. The amplitude of the echo decreases down to zero when the object is closer than 30cm, and the time is under about 1ms.
This picture shows the scale of the scope
The two channels show the analog signal at the input of the comparator and the digital output of it.
Two echoes are detected. The software disable the interrupt after the first echo is received in order to get just the first one.

Sometimes it is useful to adjust the sensitivity of the sensor because of two reasons.
The cone of a 40kHz US transducer is large enough. Installing it at 10-15cm from the floor, the lower vertical edge meets it after less than 2.5m. I did a very rough simulation with a spreadsheet (at the right). Changing the parameters you can simulate the maximum allowable distance on changing height or inclination of the sensor. Rising the comparator threshold could help.

Another problem is the interference among the transducers. A far echo, related to US1, possibly reflected by more than a wall in a room, can return very late and received by US2, returning a false measurement.
There are some methods described by Borenstein in this document to avoid this. The simplest way is to wait for a long time before firing the other capsule but, in this way, a whole cycle time increases proportionally to the number of transducers. Also in this case a very high sensitivity is useless or dangerous.

This PIC solution, can be used as a substitution of the original MCU as in this specific case, or it could also be used for a brand new circuit, using different hardware solutions.
In my opinion a very good schematic is the SRF08 one (at the left).
Simple, efficient and with all the components available on the market.
They thought a smart solution to obtain the high, dual voltage needed to drive the ceramic transducers.

This movie shows the calibration phase.
The serial ouput is directed to a terminal program that shows the measures for each capsule.

Optimizing Range Finding