Posted By

carmematas on 03/15/18


Tagged

arduino ultrasons llibreria practiques


Versions (?)

Detector d'objecte per ultrasons (II)


 / Published in: C++
 

Codi per detectar objectes amb una placa Arduino i sensor d'ultrasons

  1. #include <NewPing.h>
  2.  
  3. #define TRIGGER_PIN 8
  4. #define ECHO_PIN 9
  5. #define MAX_DISTANCE 200
  6.  
  7. NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
  8.  
  9. void setup() {
  10. Serial.begin(9600);
  11. }
  12.  
  13. void loop() {
  14. delay(50);
  15. int uS = sonar.ping();
  16. Serial.print("Ping: ");
  17. Serial.print(uS / US_ROUNDTRIP_CM);
  18. Serial.println("cm");
  19. }

Report this snippet  

You need to login to post a comment.