int trigPin = 11; //TRIG is my green jumper
int echoPin = 12; //ECHO is my blue jumper
long duration, cm, inches;
void setup() {
//Serial Port begin
Serial.begin (9600);
//Define inputs and outputs
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
digitalWrite(trigPin, LOW); //LOW pulse beforehand to ensure the HIGH ones.
delayMicroseconds(5); //only 5 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); //only 10 microseconds
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT); //The ECHO PIN is an INPUT
duration = pulseIn(echoPin, HIGH); //Duration is the time (in microseconds) from the sending
cm = (duration/2) / 29.1;
inches = (duration/2) / 74;
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(300);
}