0% found this document useful (0 votes)
30 views2 pages

Sumobot: Anne Charis Magahin Nathaniel Lota

This document describes an Arduino code for using an ultrasonic sensor to measure distance. It connects an ultrasonic sensor to an Arduino board and prints the distance readings to the serial monitor. The code supports 4-pin and 3-pin ultrasonic sensors connected to digital pins on the Arduino. It measures distance in centimeters by default but can be configured to return inches.

Uploaded by

Abegail P.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Sumobot: Anne Charis Magahin Nathaniel Lota

This document describes an Arduino code for using an ultrasonic sensor to measure distance. It connects an ultrasonic sensor to an Arduino board and prints the distance readings to the serial monitor. The code supports 4-pin and 3-pin ultrasonic sensors connected to digital pins on the Arduino. It measures distance in centimeters by default but can be configured to return inches.

Uploaded by

Abegail P.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Sumobot

Anne Charis Magahin


Nathaniel Lota
________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

STEM 1A-Providence
1. /*
2. * Ultrasonic Simple
3. * Prints the distance read by an ultrasonic sensor in
  
4. * centimeters. They are supported to four pins ultrasound
5. * sensors (liek HC-SC04) and three pins (like PING)))
6. * and Seeed Studio sensors).
7. *
8. * The circuit:
9. * * Module HR-SC04 (four pins) or PING))) (and other with
10. * three pins), attached to digital pins as follows:
11. * --------------------- --------------------
12. * | HC-SC04 | Arduino | | 3 pins | Arduino |
13. * --------------------- --------------------
14. * | Vcc | 5V | | Vcc | 5V |
15. * | Trig | 12 | OR | SIG | 13 |
16. * | Echo | 13 | | Gnd | GND |
17. * | Gnd | GND | --------------------
18. * ---------------------
19. * Note: You do not obligatorily need to use the pins defined above
20. *
21. * By default, the distance returned by the read()
22. * method is in centimeters. To get the distance in inches,
23. * pass INC as a parameter.
24. * Example: ultrasonic.read(INC)
25. *
26. * created 3 Apr 2014
27. * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
28. * modified 23 Jan 2017
29. * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
30. * modified 03 Mar 2017
31. * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
32. * modified 11 Jun 2018
33. * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
34. *
35. * This example code is released into the MIT License.
36. */
37.

38. #include <Ultrasonic.h>


39.

40. /*
41. * Pass as a parameter the trigger and echo pin, respectively,
42. * or only the signal pin (for sensors 3 pins), like:
43. * Ultrasonic ultrasonic(13);
44. */
45. Ultrasonic ultrasonic(12, 13);
46. int distance;
47.

48. void setup() {


49. Serial.begin(9600);
50. }
51.

You might also like