Advertisement
pleasedontcode

Scanner rev_176

Nov 20th, 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: Scanner
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-20 12:12:33
  15.     - Source Code generated by: AlexWind
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <Servo.h>
  21. #include <Ultrasonic.h>
  22.  
  23. /****** SYSTEM REQUIREMENT 1 *****/
  24. /* When an obstacle is detected by the ultrasonic sensor, */
  25. /* the servo motor rotates to a position where no obstacle is present */
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF PWM OUTPUT PINS *****/
  32. const uint8_t servo_Servomotor_PWMSignal_PIN_D3 = 3;
  33.  
  34. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  35. Servo myservo;
  36. Ultrasonic ultrasonicSensor(12, 11); // Trig pin: 12, Echo pin: 11
  37.  
  38. void setup(void)
  39. {
  40.   // Put your setup code here, to run once:
  41.   pinMode(servo_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  42.   myservo.attach(servo_Servomotor_PWMSignal_PIN_D3);
  43. }
  44.  
  45. void loop(void)
  46. {
  47.   // Put your main code here, to run repeatedly:
  48.   int distance = ultrasonicSensor.read();
  49.  
  50.   if (distance > 0 && distance < 20)
  51.   {
  52.     myservo.write(90); // Rotate servo to 90 degrees
  53.   }
  54.   else
  55.   {
  56.     myservo.write(0); // Rotate servo to 0 degrees
  57.   }
  58.  
  59.   delay(100);
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement