Advertisement
pleasedontcode

**Motor Control** rev_01

Feb 16th, 2025
165
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: **Motor Control**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-02-16 13:00:23
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* basically the components we used are rain sensor, */
  21.     /* arduino uno r3 micro controller, motor driver */
  22.     /* L293D, dc motors of 5v. motor driver vss pin and */
  23.     /* vs pin ,motor driver enable pins have external */
  24.     /* voltage supply .   the circuit connections are as */
  25.     /* follows */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /* START CODE */
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <L293D.h>
  32. #include <RainSensor.h>
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. // Motor and sensor pin definitions
  39. const int motorA = 3; // Motor A pin
  40. const int motorB = 4; // Motor B pin
  41. const int enablePin = 5; // Enable pin for the motor driver
  42. const int rainSensorPin = 6; // Rain sensor pin
  43.  
  44. // Create instances of the motor driver and rain sensor
  45. L293D motor(motorA, motorB, enablePin);
  46. RainSensor rainSensor(rainSensorPin);
  47.  
  48. void setup(void)
  49. {
  50.     // Initialize the motor driver
  51.     motor.begin();
  52.    
  53.     // Initialize the rain sensor
  54.     pinMode(rainSensorPin, INPUT);
  55. }
  56.  
  57. void loop(void)
  58. {
  59.     // Check the rain sensor
  60.     if (rainSensor.isRaining()) {
  61.         // If it is raining, stop the motors
  62.         motor.Stop();
  63.     } else {
  64.         // If it is not raining, set the motor speed (example: 255 for full speed)
  65.         motor.SetMotorSpeed(255);
  66.     }
  67. }
  68.  
  69. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement