Measuring Distance with Ultrasonic Sensors

Recently I purchased a Grove Ultrasonic Ranger v1.0 (SEN10737P) which is a sensor that can be used to measure distance by sending a ping and measuring the time it takes for the response to come back.

I've integrated the sensor into a Tessel.io development board which is currently my favorite embedded development platform. This is all part of a larger demonstration of embedded devices talking to cloud backends but I managed to write the code for the Tessel and the sensor in such a way that others using a Tessel could also easily use it. I've published the tessel-sen10737p module for the Tessel up on GitHub and you can integrate it into your project using the following command:

npm install tessel-sen10737p --save  

Wiring the ultrasonic sensor up to the Tessel is very simple. Simply wire-up the SIG pin on the sensor to the G3 pin on the Tessel's GPIO port. Then plug the VCC and GND pins accordingly (note, the sensor can work with 5V but if you use a 5V power source you'll need to step down the voltage with a resistor.

Once you've got it all wired up you can try it out quickly by invoking one of the samples from the /examples directory:

tessel run continuous.js  

This will continually send out an ultrasonic pulse and then output the calculated distance to the screen. Using the API in your own code is as simple as:

var tessel = require('tessel');  
var gpio = tessel.port['GPIO'];  
var pin = gpio.pin['G3'];

var sen10737p = require('tessel-sen10737p');  
var ranger = sen10737p.use(pin);

ranger.getDistance(function(err, distance) {  
    if (err) {
        console.log(err);
        return;
    }

    console.log(distance);
});

As you can see the usage is pretty straight-forward and its a good example of how easy it is modularise code that works for particular sensors on various embedded devices.

I was very excited about the announcement about the Raspberry Pi 2 and the fact that it will actually be able to run a specially designed build of Windows 10. I've already picked up my Pi2 but for this particular project I found that the Tessel was a better way to go because of its ability to read a PWM pulse directly on the G3 pin without a specialised shield.

In the long term I'm hoping to see a good range of shields that work with the Pi2 which also include some kind of driver support for Windows 10.