Tuesday, June 12, 2012

Ping Sensor Test


I modified some ping sensor code to make this.  It is for a 4 pin ping sensor and used on the Arduino Board.


// Ping Sensor Test
//by Philip Leete

#define trigPin 2  //I am putting the sensor onpins 2 and 3
#define echoPin 3

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  int sensor_value;
    digitalWrite(trigPin, LOW)                
    delayMicroseconds (2)                      //This is to insure that the sensor is off
    digitalWrite(trigPin, HIGH);
    delayMicroseconds (5);                      //This is to insure that it gets a reading
    digitalWrite(trigPin, LOW);
  sensor_value = pulseIn(echoPin, HIGH);
    Serial.println(sensor_value);       //Will print out raw data.  Appears to be in range of 0 to 1700
   
 delay (1000);                            //This is so we can get a reading each second and see what is happening
  }


No comments:

Post a Comment