18 Channel Ultrasonic Sensor Interface

in Blog

21 September 2008

A networked multi-channel synchronised distance sensor system to detect the movement of people around an architectural exhibit.

Built for an art gallery in Spain, this interface allows up to eighteen ‘trip-wire’ invisible sensors to detect the motion of visitors.

MaxSonar Interface In Use - Front Panel

Ultrasonic sensors use short pulses of inaudible, high frequency sound to detect obstacles in its path, much like a bat. A single sensor is easy to interface to a computer to link it to a sound file, or other effect. However, numerous sensors often interfere with each other when placed within ‘hearing’ distance of each other. This is because each sensor has no way of knowing which short pulse of sound came from which sensor and the data readings become very unpredictable. The solution is to synchronise the sensors to prevent one sensor listening, whilst another is clicking. Happily, MaxBotix produce a small, low power ultrasonic sensor with the option to synchronise.

MaxSonar Interface - Sensors

Once a suitable sensor was selected, the next step was to get its data into a computer. The computer then triggers sounds when a person crosses the ‘trip-wire’. MaxBotix sensors output digital and analog data simultaneously. Ideally, the digital output would have been used, since it would be potentially immune to the long cable runs. However, the sensors output RS232 which only allows shorter cables. The analog output was therefore used. However, the longer the cable run, the more noise in the signal. Since they are only to be used to detect whether or not the trip-wire has been crossed, rather than a range of values, we can live with some noise.

MaxSonar Interface In Use - Sensor Inputs

For quick and low cost prototyping, an Arduino Mini microcontroller was used to digitise the analog signals from the sensors. However, it only has eight analog inputs and we need eighteen. So, two 4051 multiplexer chips give access to 16 analog sensor outputs, and two more analog inputs on the Arduino make the total count up to eighteen. (Click on the photo below to view an annotated version.)

MaxSonar Interface - PCB
Homemade PCB made using the toner transfer method.

Getting the digital signals into the computer was now relatively simple. A miniature web server was implanted onto the Arduino. Ethernet has a very quick data rate for this application, and supports a long cable run. Hubs and switches allow this sensor interface to integrate seemlessly into an existing computer network.

The connectors used by existing sensor interfaces are usually a fatal weak point. The pin headers of one interface often become detached from the interface and the wires attached can break off after a while. The stereo mini jacks on another seem to fall out even when looked at! I chose locking RJ45 connectors. They are cheap, the plugs stay in the sockets, don’t require soldering so can be wired on the fly, and bulk Ethernet cable is extremely cheap. And Ethernet patch cords are widely available in any computer shop for a ready-made option.


A bespoke PCB was made to increase reliability and make the unit more robust. No moving parts, everything is firmly soldered into place. It also allowed the use of high density sockets so the board could be housed in a small enclosure. Although the PCB is not at all complicated, there was some very delicate soldering, especially beneath the connectors. This is a potential area for errors when making and populating the board. In the future, I will probably outsource the PCB fabrication for anything but the smallest and simplest boards. Whilst this would be much more expensive (more than ten times), I think it would be worth it since they would be error free, and would allow a more dense spacing of components, especially on double-sided boards. Drilling holes accurately using a cheap drill press is also quite difficult. Outsourcing would make each hole perfect. Holes would also be through-plated so tracks on one side of the board could be connected to tracks on the other side. This would be very tedious to manufacture at home.

The varying lengths of cable between the sensors and the interface would mean that there is a different amount of noise for each sensor, so they have to be treated individually in the computer. Digitising the data on the sensor PCB would therefore be desirable, removing the noise problem. RS485 would be a suitable protocol, but I have been warned by experienced engineers that this may be tricky to implement. I think the extra work to get things running smoothly is worth the effort it if it simplifies the use of the sensors later on.

Whilst the Arduino Mini is absolutely fantastic for quick prototyping, some of the complexity is intentionally hidden. It can be difficult to work out precise timings and also debug. They are also expensive. But worth every penny in my view for simple one-off projects. In future, given the time, I will move back to using Microchip PIC microcontrollers. They are not much more difficult to use, but provide a deeper level of control such as hardware timers, interrupts, multiple serial ports and in-circuit serial programming. They are also far cheaper.

More photographs on Flickr…

(Pictures taken with my new Canon Powershot G9.)

Back to Blog