Advertisement
pleasedontcode

Car Automation rev_01

Apr 21st, 2024
103
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: Car Automation
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-21 06:56:58
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* give a Arduino code for robotic car...... the */
  21.     /* robotic car include motor driver, ultrasonic */
  22.     /* sensor for obstacle avoiding and rotate randomly, */
  23.     /* servo motor, 2 IR sensors for line follow, buzzer */
  24.     /* for horn and LDR sensor for light emitting. all */
  25.     /* sensors are */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <Ultrasonic.h>   //https://github.com/ErickSimoes/Ultrasonic
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs(void);
  35. void obstacleAvoidance(void);
  36. void lineFollowing(void);
  37. void randomRotation(void);
  38. void horn(void);
  39. void lightEmitting(void);
  40.  
  41. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  42. const uint8_t Ultrasonic_sensor_HC_SR04_Echo_PIN_D3 = 3;
  43.  
  44. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  45. const uint8_t Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2 = 2;
  46.  
  47. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  48. /***** used to store raw data *****/
  49. bool Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2_rawData = 0;
  50.  
  51. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  52. /***** used to store data after characteristic curve transformation *****/
  53. float Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2_phyData = 0.0;
  54.  
  55. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  56. Ultrasonic ultrasonic(Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2, Ultrasonic_sensor_HC_SR04_Echo_PIN_D3);
  57.  
  58. void setup(void)
  59. {
  60.   // put your setup code here, to run once:
  61.   pinMode(Ultrasonic_sensor_HC_SR04_Echo_PIN_D3, INPUT);
  62.   pinMode(Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2, OUTPUT);
  63. }
  64.  
  65. void loop(void)
  66. {
  67.   // put your main code here, to run repeatedly:
  68.   updateOutputs(); // Refresh output data
  69.   obstacleAvoidance(); // Perform obstacle avoidance
  70.   lineFollowing(); // Perform line following
  71.   randomRotation(); // Perform random rotation
  72.   horn(); // Activate the horn
  73.   lightEmitting(); // Adjust LED lights based on LDR sensor
  74.  
  75.   delay(100);
  76. }
  77.  
  78. void updateOutputs(void)
  79. {
  80.   digitalWrite(Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2, Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2_rawData);
  81. }
  82.  
  83. void obstacleAvoidance()
  84. {
  85.   // Code for obstacle avoidance using ultrasonic sensor
  86.   unsigned int distance = ultrasonic.read();
  87.   if (distance < 10)
  88.   {
  89.     // Stop the car and take evasive action
  90.     // (e.g., turn, reverse, etc.)
  91.   }
  92. }
  93.  
  94. void lineFollowing()
  95. {
  96.   // Code for line following using IR sensors
  97.   // Read IR sensor values and adjust the car's direction accordingly
  98. }
  99.  
  100. void randomRotation()
  101. {
  102.   // Code for random rotation
  103.   // Rotate the car randomly to change its direction
  104. }
  105.  
  106. void horn()
  107. {
  108.   // Code for horn using buzzer
  109.   // Activate the buzzer to produce sound
  110. }
  111.  
  112. void lightEmitting()
  113. {
  114.   // Code for light emitting using LDR sensor
  115.   // Read LDR sensor values and adjust the car's LED lights accordingly
  116. }
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement