Advertisement
pleasedontcode

Obstacle Detection rev_185

Dec 7th, 2023
67
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: Obstacle Detection
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-07 15:11:36
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* when something in front ultrasonic sensor senses */
  21.     /* it and then the servo motor rotates and moves to */
  22.     /* space where no obstacle is present */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Servo.h>
  27. #include "Ultrasonic-distance-sensor-easyC-SOLDERED.h"
  28.  
  29. /****** SYSTEM REQUIREMENTS *****/
  30. /****** SYSTEM REQUIREMENT 1 *****/
  31. /* when something in front ultrasonic sensor senses */
  32. /* it and then the servo motor rotates and moves to */
  33. /* space where no obstacle is present */
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup(void);
  37. void loop(void);
  38.  
  39. /***** DEFINITION OF PWM OUTPUT PINS *****/
  40. const uint8_t servo_Servomotor_PWMSignal_PIN_D3 = 3;
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  43. Servo myservo;
  44. Ultrasonic_Sensor hc;
  45.  
  46. void setup(void)
  47. {
  48.   // Initialize the servo motor
  49.   myservo.attach(servo_Servomotor_PWMSignal_PIN_D3);
  50.  
  51.   // Initialize the ultrasonic sensor
  52.   hc.begin();
  53. }
  54.  
  55. void loop(void)
  56. {
  57.   // Check if an obstacle is detected by the ultrasonic sensor
  58.   if (hc.getDistance() <= 10) {
  59.     // Rotate the servo motor to a position where no obstacle is present
  60.     myservo.write(90);
  61.     delay(500); // Adjust the delay as needed
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement