2011年3月10日 星期四

PING))) ultrasonic sensor + Arduino + Maxmsp

PING))) ultrasonic sensor的腳位為 SIG , 5V , GND
此種超聲波感測器的特殊點為使用的是Digital Pin
Arduino程式部分已有寫好的預設範本,還可實際的換算出距離(英吋或公分)
Specifications:


  • Range - 2cm to 3m (~.75" to 10')
  • Supply Voltage: 5V +/-10% (Absolute: Minimum 4.5V, Maximum 6V)
  • Supply Current: 25 mA typ; 30 mA max
  • 3-pin interface (power, ground, signal)
  • 20 mA power consumption
  • Narrow acceptance angle
  • Simple pulse in / pulse out communication
  • Indicator LED shows measurement in progress
  • Input Trigger - positive TTL pulse, 2 uS min, 5 uS typ.
  • Echo Pulse - positive TTL pulse, 115 uS to 18.5 mS
  • Echo Hold-off - 350 uS from fall of Trigger pulse
  • Burst Frequency - 40 kHz for 200 uS
  • Size - 22 mm H x 46 mm W x 16 mm D (0.85 in x 1.8 in x 0.6 in)


Arduino Sketch  (原始範本Examples>Sensors>Ping)


/* 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

   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;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
}

void loop()
{
  // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // 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
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);

//  Serial.print(inches);
  Serial.print(32, BYTE);// space in ascii
  Serial.print(cm);
//  Serial.print("cm");
  Serial.println();
  
  delay(100);
}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

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;
}

Maxmsp Patch


----------begin_max5_patcher----------
1405.3oc0Z00aihCE84jeEV7bZks4qv7VWsuMZVMRqztOLZTkC3l3s.NBLcZ
6n4+9hsIDbBP.RZZmWBEav9bO9du12C8mymYsh+LM2B7Iv2.yl8y4yloZR1v
rp6mYkPdNLljqdLqDZdNYM0ZgtOA8YgpcDxAfCr209C7TQJIgp56tLFIdWO7
BQLUHdYKUOsVVfu23kxYup5.guEV07VhHbCKc88YzPg9kvt1kcCbfNxKHnm5
xxag0iEKRM07U+2MtN6l6zhDVZ4rqLE79F0XR0JR13ulOW9yhAxIozeTNOGQ
IaAgYThf9EZZQq7x+PyhHojQxLA8QLNXeIUfQP4EerhW7amWPdsxKn14klyI
MqhMpniR.xhoOQyxY7zFO8Lq8HyEEn.CxQCP0Bnsm8drURyqi4gORUPDtqwH
5CiaT3aoo6eCEQX7i4SxR2lQyooBhnB7MmYRQr3918KM6+ARHsyWtiU7Y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