Advertisement
pleasedontcode

Scanner rev_184

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