Advertisement
pleasedontcode

Scanner rev_172

Nov 20th, 2023
65
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 10:55:52
  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 is sensed by the ultrasonic sensor in front,
  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 LIBRARY CLASS INSTANCES*****/
  35. Servo myservo;
  36. Ultrasonic_Sensor hc(2, 3); // Replace with the correct pins for the Ultrasonic Sensor
  37.  
  38. void setup(void)
  39. {
  40.   // Initialize the servo motor
  41.   myservo.attach(servo_Servomotor_PWMSignal_PIN_D3);
  42.  
  43.   // Initialize the ultrasonic sensor
  44.   hc.begin();
  45.  
  46.   // Add any additional setup code here
  47. }
  48.  
  49. void loop(void)
  50. {
  51.   // Add your main code here
  52.  
  53.   // Check if an obstacle is detected by the ultrasonic sensor
  54.   if (hc.getDistance() < 20) // Replace 20 with the desired distance threshold
  55.   {
  56.     // Move the servo motor to a space where no obstacle is present
  57.     myservo.write(90); // Replace 90 with the desired angle to move the servo motor
  58.     delay(1000); // Adjust the delay time as needed
  59.   }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement