Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <NewPing.h>
  2. /*Aqui se configuran los pines donde debemos conectar el sensor*/
  3. #define TRIGGER_PIN 12
  4. #define ECHO_PIN 11
  5. #define MAX_DISTANCE 200
  6.  
  7. /*Crear el objeto de la clase NewPing*/
  8. NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
  9. void setup() {
  10. Serial.begin(115200);
  11. }
  12. void loop() {
  13. // Esperar 1 segundo entre mediciones
  14. delay(500);
  15. // Obtener medicion de tiempo de viaje del sonido y guardar en variable uS
  16. int uS = sonar.ping_median();
  17. // Imprimir la distancia medida a la consola serial
  18. Serial.print("Distancia: ");
  19. // Calcular la distancia con base en una constante
  20. Serial.print(uS / US_ROUNDTRIP_CM);
  21. Serial.println("cm");
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement