PING))) Ultrasonic Distance Sensor + controller
Hello!
I am new to PING))) so I would like to get an advice for choosing the best controller for the sensor. I need to detect people from 0.5-4 meters outputing an array of distances via USB. The final array would be "date&time - distance". Sensor will be used indoors. The controller will be powered by PC PSU or optional adapter.
Best,
Martti
I am new to PING))) so I would like to get an advice for choosing the best controller for the sensor. I need to detect people from 0.5-4 meters outputing an array of distances via USB. The final array would be "date&time - distance". Sensor will be used indoors. The controller will be powered by PC PSU or optional adapter.
Best,
Martti

Comments
If you haven't used a controller before, I think the Propeller it the most useful.
Here's code I wrote for a QuickStart board using a Ping and 4 digit 7-segment LED display.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 PING_Pin = 0 ' I/O Pin For PING))) _DebugBaud = 9600 ' Debug Baud Rate VAR long range, rangeOld OBJ Debug : "FullDuplexSerial" ping : "ping" PUB Start Debug.Start(-1, 1, 0, _DebugBaud) 'Debug.str(string("PING))) Demo")) waitcnt(clkfreq / 10 + cnt) Debug.tx("z") Debug.tx(0) repeat ' Repeat Forever rangeOld := range range := ping.Millimeters(PING_Pin) ' Get Range In Millimeters if rangeOld <> range Debug.tx("v") Debug.dec(range) waitcnt(clkfreq / 10 + cnt) ' Pause 1/10 SecondThe objects used a freely available and I'll post the code as an archive if you'd like.
Duane
For my initial experiments I am using a Freetronics Eleven controller board (an Arduino clone). Wether I stick with that will depend on how sophisticated the controller software ends up needing to be, but for now it is working fine and I had an Arduino sketch up and running in about 5 min. (Mostly because there was already an example using a PING))) sensor that I could modify.)
So far I have found the PING))) to be fairly noisy, so I will need some sort of filter on the output. I haven't collected any data yet but I am hoping to when I get back from holiday in a couple of weeks.
/* Ping))) Sensor This sketch reads a PING))) ultrasonic rangefinder and returns the distance to the closest object in range. To do this, it sends a pulse to the sensor to initiate a reading, then listens for a pulse to return. The length of the returning pulse is proportional to the distance of the object from the sensor. The circuit: * +V connection of the PING))) attached to +5V * GND connection of the PING))) attached to ground * SIG connection of the PING))) attached to digital pin 7 http://www.arduino.cc/en/Tutorial/Ping created 3 Nov 2008 by David A. Mellis modified 30 Jun 2009 by Tom Igoe modified 19 Nov 2011 by Kaelin Colclasure This example code is in the public domain. */ // this constant won't change. It's the pin number // of the sensor's output: const int pingPin = 7; const long maxDistance = 300; // Max range 3m per data sheet long lastDistance = 0; void setup() { // initialize serial communication: Serial.begin(9600); pinMode(13, OUTPUT); } void loop() { // establish variables for duration of the ping, // and the distance result in inches and centimeters: long duration, distance; // The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(5); digitalWrite(pingPin, LOW); // The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH); // convert the time into a distance distance = microsecondsToCentimeters(duration); if (distance > maxDistance) distance = -1; if (distance != lastDistance) { Serial.print(distance); Serial.print("cm"); Serial.println(); lastDistance = distance; if (distance == -1) digitalWrite(13, LOW); // set the LED off else digitalWrite(13, HIGH); // set the LED on } delay(300); } long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2; }If, by noisy, you mean that the readings vary widely, remember that the PING))) responds to the first echo received. If you have a complex environment out there, there may be secondary echoes that, depending on the air temperature, air currents, object movement, etc., may return with sufficient amplitude to trigger the PING))) and give you what effectively looks like noise. In that case, some filtering of the distance measurements would indeed be in order. You could exclude values outside of the range you expect, maybe adjust the acceptable range based on relatively long-term trends.