Advertisement
pleasedontcode

Scanner rev_178

Nov 20th, 2023
58
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:22:01
  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-distance-sensor-easyC-SOLDERED.h"
  22.  
  23. /****** SYSTEM REQUIREMENT 1 *****/
  24. /* when something in front ultrasonic sensor senses */
  25. /* it and then the servo motor rotates and moves to */
  26. /* space where no obstacle is present */
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF PWM OUTPUT PINS *****/
  33. const uint8_t servo_Servomotor_PWMSignal_PIN_D3 = 3;
  34.  
  35. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  36. Servo myservo;
  37. Ultrasonic_Sensor ultrasonicSensor(2, 3); // Replace TRIGPIN and ECHOPIN with the appropriate pin numbers
  38.  
  39. void setup(void)
  40. {
  41.   // Initialize servo object and set initial position
  42.   myservo.attach(servo_Servomotor_PWMSignal_PIN_D3);
  43.   myservo.write(0); // Set initial position to 0 degrees (starting position)
  44.  
  45.   // Add any other necessary setup code here
  46. }
  47.  
  48. void loop(void)
  49. {
  50.   // Measure distance from ultrasonic sensor
  51.   int distance = ultrasonicSensor.takeMeasure();
  52.  
  53.   // Check if an obstacle is detected in front
  54.   if (distance < 30)
  55.   {
  56.     // Rotate servo to move to a space with no obstacle
  57.     myservo.write(90); // Rotate servo to 90 degrees
  58.     delay(1000); // Wait for servo to reach desired position
  59.     myservo.write(0); // Return servo to the starting position
  60.     delay(1000); // Wait for servo to return to starting position
  61.   }
  62.  
  63.   // Add the rest of your main code here
  64.  
  65.   // Delay before next iteration
  66.   delay(100);
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement