
Getting it Working with Servotor32
You can connect the module to the Servotor32 board in a Hexy kit with the included 4-pin cable.
With the Servotor32 powered, take one end of the 4-wire cable and connect connect it to ultrasonic unit, and then the other end to the board. Note the labels on the board and the ultrasonic ‘vcc’ and ‘gnd’. Make sure the wires are connecting ‘vcc’ to ‘vcc’ and ‘gnd’ to ‘gnd’.
If the green light on the board starts to dim, unplug the ultrasonic immediately. This means the ultrasonic is plugged in backwards and is shorting out the board. Reverse the connection and try again.

This code is using the Servotor 2.0 firmware libraries, which is available
here:
#include "Servotor32.h"
Servotor32 hexy;
void setup(){
hexy.begin();
}
loop(){
float cm;
cm = hexy.ping();
Serial.print("CM: ");
Serial.println(cm);
hexy.delay_ms(200);
}
The code prints out a measurement from the module in centimeters every 200 milliseconds (5 times per second).
Basic Theory
The distance sensor works by sending out a pulse of ultrasonic sound and measuring the amount of time it takes for the sound to come back, know as the ‘time of flight’ method. This is the same method bats use to find things by sound.
The sound goes out in a cone pattern, so the best detection is done . However, objects on the side of the cone can still be detected. This is the cone pattern for this module:
Because it works with sound waves, it works best on objects that easily reflect sound. Flat, smooth services (like a wall) reflect work best. Fuzzy, soft, irregular surfaces (like a dog) reflect the worst.
Operational

A 10uS high pulse on the Trigger pin initiates an 8 cycle burst of 40khz ultrasonic pulses. The pulses return to the module, and it emits on the Echo pin a high pulse between 150uS and 25ms. The distance can be calculated from the formulas above. They are derived from:
Test distance = (high level time * velocity of sound (340M/S) / 2.
The pins are connected on the Servotor32 module as such:
Trigger – Pin 17 (PB0)
Echo – Pin 11 (PB6)
Specifications
- Working Voltage: DC 5 V
- Working Current: 15mA
- Working Frequency: 40Hz
- Max Range: 4m
- Min Range: 2cm
- Measuring Angle: 15 degree
- Trigger Input Signal 10uS TTL pulse
- Echo Output Signal Input TTL lever signal and the range in proportion
- Dimensions: 45*20*15mm
Files
Solidworks Model