Advertisement
pleasedontcode

Scanner rev_179

Nov 25th, 2023
60
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-25 23:48:58
  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 something in front of the ultrasonic sensor is detected,
  25.    the servo motor should rotate and move to a space 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 LIBRARIES CLASS INSTANCES*****/
  35. Servo myservo;
  36. Ultrasonic ultrasonic(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 = ultrasonic.read();
  49.  
  50.   // Check if an obstacle is detected
  51.   if (distance < 50) {
  52.     // Rotate the servo motor to a new position
  53.     myservo.write(90);
  54.     delay(1000);
  55.   } else {
  56.     // Move the servo motor to a different position
  57.     myservo.write(0);
  58.     delay(1000);
  59.   }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement