-
Notifications
You must be signed in to change notification settings - Fork 41
Ultrasonic Distance Module
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.
You can connect the module to the Servotor32 board in a Hexy kit with the included 4-pin cable as such:
NOTE: Some Ultrasonic units have been reported as labeled backwards (i.e. VCC is GND and GND is VCC). If your Servotor32 fails to turn on or turns off when the ultrasonic is plugged in, immediately disconnect and reverse the wire connections. Leaving your ultrasonic plugged in like this for too long can damage your board.
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).
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)
- 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: 452015mm




