-
Notifications
You must be signed in to change notification settings - Fork 3
Sonar
MarcG edited this page Feb 22, 2015
·
1 revision
//Adapted from David A. Mellis' code for Ping sensor
const int trigPin = 7;
const int echoPin = 8;
void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
}
void loop()
{
long duration, inches, cm;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(5);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
Serial.println(duration);
delay(100);
}