document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. int trigPin = 11; //TRIG is my green jumper
  2. int echoPin = 12; //ECHO is my blue jumper
  3. long duration, cm, inches;
  4.  
  5. void setup() {
  6. //Serial Port begin
  7. Serial.begin (9600);
  8. //Define inputs and outputs
  9. pinMode(trigPin, OUTPUT);
  10. pinMode(echoPin, INPUT);
  11. }
  12.  
  13. void loop()
  14. {
  15.  
  16. digitalWrite(trigPin, LOW); //LOW pulse beforehand to ensure the HIGH ones.
  17. delayMicroseconds(5); //only 5 microseconds
  18. digitalWrite(trigPin, HIGH);
  19. delayMicroseconds(10); //only 10 microseconds
  20. digitalWrite(trigPin, LOW);
  21.  
  22. pinMode(echoPin, INPUT); //The ECHO PIN is an INPUT
  23. duration = pulseIn(echoPin, HIGH); //Duration is the time (in microseconds) from the sending
  24.  
  25. cm = (duration/2) / 29.1;
  26. inches = (duration/2) / 74;
  27.  
  28. Serial.print(inches);
  29. Serial.print("in, ");
  30. Serial.print(cm);
  31. Serial.print("cm");
  32. Serial.println();
  33.  
  34. delay(300);
  35. }
');