Advertisement
DjKammo

idk

Oct 20th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. /*
  2.  * The circuit:
  3.  * * Module HR-SC04 (four pins) or PING))) (and other with
  4.  *   three pins), attached to digital pins as follows:
  5.  * ---------------------    ---------------------
  6.  * | HC-SC04 | Arduino |    | 3 pins  | Arduino |
  7.  * ---------------------    ---------------------
  8.  * |   Vcc   |   5V    |    |   Vcc   |   5V    |
  9.  * |   Trig  |   7    | OR |   SIG   |   13    |
  10.  * |   Echo  |   8    |    |   Gnd   |   GND   |
  11.  |   Gnd   |   GND   |    ---------------------
  12.   ---------------------
  13.  
  14. */
  15. #include <Ultrasonic.h>
  16.  
  17. /*
  18.  * Pass as a parameter the trigger and echo pin, respectively,
  19.  * or only the signal pin (for sensors 3 pins), like:
  20.   Ultrasonic ultrasonic(13); */
  21.  ////////////////////////you may need to switch the two numbers below////////////////////////
  22. Ultrasonic ultrasonic(7, 6);
  23.  
  24. void setup() {
  25.   Serial.begin(9600);
  26. }
  27.  
  28. void loop() {
  29.   Serial.print("Distance in CM: ");
  30.   // Pass INC as a parameter to get the distance in inches
  31.   Serial.println(ultrasonic.distanceRead());
  32.   delay(1000);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement