Advertisement
pleasedontcode

Ultrasonic Setup rev_01

Mar 5th, 2024
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Ultrasonic Setup
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-06 03:14:07
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Arduino for an automated feeding system. Here are */
  21.     /* the parts being used     UMC1    1       Arduino */
  22.     /* Uno R3  DISTSensor1     1       Ultrasonic */
  23.     /* Distance Sensor (4-pin)  SERVOServo1     1 */
  24.     /* Positional Micro Servo */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Ultrasonic.h> // https://github.com/ErickSimoes/Ultrasonic
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t Sensor1_HC_SR04_Echo_PIN_D3 = 3;
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t Sensor1_HC_SR04_Trigger_PIN_D2 = 2;
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. Ultrasonic ultrasonic(Sensor1_HC_SR04_Trigger_PIN_D2, Sensor1_HC_SR04_Echo_PIN_D3);
  42.  
  43. void setup(void)
  44. {
  45.     // put your setup code here, to run once:
  46.     pinMode(Sensor1_HC_SR04_Echo_PIN_D3, INPUT);
  47.     pinMode(Sensor1_HC_SR04_Trigger_PIN_D2, OUTPUT);
  48.  
  49.     Serial.begin(9600);
  50. }
  51.  
  52. void loop(void)
  53. {
  54.     // put your main code here, to run repeatedly:
  55.     unsigned int distance = ultrasonic.read();
  56.  
  57.     Serial.print("Distance in CM: ");
  58.     Serial.println(distance);
  59.  
  60.     delay(1000);
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement