Advertisement
pleasedontcode

Scanner rev_183

Dec 3rd, 2023
49
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:14:12
  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. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Arduino.h>
  27. #include <Servo.h>
  28. #include "Ultrasonic-distance-sensor-easyC-SOLDERED.h"
  29.  
  30. /****** Function Prototypes *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** Definition of PWM Output Pins *****/
  35. const uint8_t servo_Servomotor_PWMSignal_PIN_D3 = 3;
  36.  
  37. /****** Definition of Library Class Instances *****/
  38. Servo myservo;
  39. Ultrasonic_Sensor hc(2, 3); // Initialize Ultrasonic_Sensor object with trigger pin 2 and echo pin 3
  40.  
  41. void setup(void)
  42. {
  43.   // put your setup code here, to run once:
  44.  
  45.   pinMode(servo_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  46.   myservo.attach(servo_Servomotor_PWMSignal_PIN_D3);
  47.  
  48.   hc.begin(); // Initialize Ultrasonic_Sensor object
  49. }
  50.  
  51. void loop(void)
  52. {
  53.   // put your main code here, to run repeatedly:
  54.  
  55.   // Check if something in front of the ultrasonic sensor is sensed
  56.   if (hc.getDistance() < 50) { // Adjust the threshold value as per your requirement
  57.     // Rotate the servo motor
  58.     myservo.write(90);
  59.     delay(1000); // Delay for servo to rotate to the desired position
  60.  
  61.     // Move to a space where no obstacle is present
  62.    
  63.     // Rotate the servo motor back to initial position
  64.     myservo.write(0);
  65.     delay(1000); // Delay for servo to rotate back to initial position
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement