Tutorial.UltrasoundSensor History

Hide minor edits - Show changes to markup

November 07, 2008, at 10:24 AM by David A. Mellis -
Added lines 1-2:
November 21, 2005, at 05:24 PM by 195.178.229.112 -
Added lines 1-12:

PING range finder

The PING range finder is an ultrasound sensor from Parallax able of detecting objects up to a 3 mts distance. The sensor counts with 3 pins, two are dedicated to power and ground, while the third one is used both as input and output.

The pin dedicated to make the readings has to be shifting configuration from input to output according to the PING specification sheet. First we have to send a pulse that will make the sensor send an ultrasound tone and wait for an echo. Once the tone is received back, the sensor will send a pulse over the same pin as earlier. The width of that pulse will determine the distance to the object.

The example shown here was mounted by Marcus Hannerstig, while the software was created by David Cuartielles. The board is connected as explained using only wires coming from an old computer.

http://static.flickr.com/31/65531405_fa57b9ff66.jpg

Ultrasound sensor connected to an Arduino USB v1.0

October 10, 2005, at 07:31 PM by 81.33.141.194 -
Added line 1:
 [=
Changed lines 12-13 from:

int ultraSoundSignal = 7; // Ultrasound signal pin

to:

int ultraSoundSignal = 7; // Ultrasound signal pin

Changed lines 15-21 from:

int ultrasoundValue = 0;

int timecount = 0; // Echo counter

int ledPin = 13; // LED connected to digital pin 13

to:

int ultrasoundValue = 0; int timecount = 0; // Echo counter int ledPin = 13; // LED connected to digital pin 13

Deleted line 19:
Deleted line 20:
Deleted line 21:
Changed lines 25-31 from:

timecount = 0;

val = 0;

pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

to:
 timecount = 0;
 val = 0;
 pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output
Deleted line 29:
Deleted line 30:
Changed lines 33-42 from:

digitalWrite(ultraSoundSignal, LOW); // Send low pulse

delayMicroseconds(2); // Wait for 2 microseconds

digitalWrite(ultraSoundSignal, HIGH); // Send high pulse

delayMicroseconds(5); // Wait for 5 microseconds

digitalWrite(ultraSoundSignal, LOW); // Holdoff

to:

digitalWrite(ultraSoundSignal, LOW); // Send low pulse delayMicroseconds(2); // Wait for 2 microseconds digitalWrite(ultraSoundSignal, HIGH); // Send high pulse delayMicroseconds(5); // Wait for 5 microseconds digitalWrite(ultraSoundSignal, LOW); // Holdoff

Deleted line 39:
Deleted line 40:
Changed lines 43-48 from:

pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input

val = digitalRead(ultraSoundSignal); // Append signal value to val

while(val == LOW) { // Loop until pin reads a high value

to:

pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input val = digitalRead(ultraSoundSignal); // Append signal value to val while(val == LOW) { // Loop until pin reads a high value

Deleted line 46:
Changed lines 49-50 from:

while(val == HIGH) { // Loop until pin reads a high value

to:

while(val == HIGH) { // Loop until pin reads a high value

Deleted line 50:
Deleted line 51:
Deleted line 54:
Deleted line 55:
Changed lines 58-61 from:

ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue

serialWrite('A'); // Example identifier for the sensor

to:

ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue

serialWrite('A'); // Example identifier for the sensor

Deleted line 61:
Deleted line 62:
Deleted line 65:
Deleted line 66:
Deleted line 69:
Changed lines 71-74 from:

}

to:

}

Deleted line 73:
Deleted line 74:
Changed lines 78-79 from:

}

to:

}

 =]

October 08, 2005, at 10:58 AM by 62.97.121.93 -
Added lines 1-114:

/* Ultrasound Sensor

 *------------------
 *
 * Reads values (00014-01199) from an ultrasound sensor (3m sensor)
 * and writes the values to the serialport.
 *
 * http://www.xlab.se | http://www.0j0.org
 * copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp
 *
 */

int ultraSoundSignal = 7; // Ultrasound signal pin

int val = 0;

int ultrasoundValue = 0;

int timecount = 0; // Echo counter

int ledPin = 13; // LED connected to digital pin 13

void setup() {

  beginSerial(9600);                  // Sets the baud rate to 9600

  pinMode(ledPin, OUTPUT);            // Sets the digital pin as output

}

void loop() {

timecount = 0;

val = 0;

pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

/* Send low-high-low pulse to activate the trigger pulse of the sensor

 * -------------------------------------------------------------------

 */

digitalWrite(ultraSoundSignal, LOW); // Send low pulse

delayMicroseconds(2); // Wait for 2 microseconds

digitalWrite(ultraSoundSignal, HIGH); // Send high pulse

delayMicroseconds(5); // Wait for 5 microseconds

digitalWrite(ultraSoundSignal, LOW); // Holdoff

/* Listening for echo pulse

 * -------------------------------------------------------------------

 */

pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input

val = digitalRead(ultraSoundSignal); // Append signal value to val

while(val == LOW) { // Loop until pin reads a high value

  val = digitalRead(ultraSoundSignal);

}

while(val == HIGH) { // Loop until pin reads a high value

  val = digitalRead(ultraSoundSignal);

  timecount = timecount +1;            // Count echo pulse time

}

/* Writing out values to the serial port

 * -------------------------------------------------------------------

 */

ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue

serialWrite('A'); // Example identifier for the sensor

printInteger(ultrasoundValue);

serialWrite(10);

serialWrite(13);

/* Lite up LED if any value is passed by the echo pulse

 * -------------------------------------------------------------------

 */

if(timecount > 0){

  digitalWrite(ledPin, HIGH);

}

/* Delay of program

 * -------------------------------------------------------------------

 */

delay(100);

}

Share