Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * The circuit:
- * * Module HR-SC04 (four pins) or PING))) (and other with
- * three pins), attached to digital pins as follows:
- * --------------------- ---------------------
- * | HC-SC04 | Arduino | | 3 pins | Arduino |
- * --------------------- ---------------------
- * | Vcc | 5V | | Vcc | 5V |
- * | Trig | 7 | OR | SIG | 13 |
- * | Echo | 8 | | Gnd | GND |
- | Gnd | GND | ---------------------
- ---------------------
- */
- #include <Ultrasonic.h>
- /*
- * Pass as a parameter the trigger and echo pin, respectively,
- * or only the signal pin (for sensors 3 pins), like:
- Ultrasonic ultrasonic(13); */
- ////////////////////////you may need to switch the two numbers below////////////////////////
- Ultrasonic ultrasonic(7, 6);
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- Serial.print("Distance in CM: ");
- // Pass INC as a parameter to get the distance in inches
- Serial.println(ultrasonic.distanceRead());
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement