Advertisement
pleasedontcode

"Bluetooth Servo Control" rev_01

Apr 14th, 2024
104
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: "Bluetooth Servo Control"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-14 23:07:35
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The mobile app shall communicate with the HC05 */
  21.     /* module to control the robotic arm. The code shall */
  22.     /* define the arm's initial position. When the button */
  23.     /* is pressed, the arm shall move towards the */
  24.     /* specified item, perform pick and place operation. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <SoftwareSerial.h>
  29. #include <Servo.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void moveArm(int position);
  35.  
  36. /***** DEFINITION OF PWM OUTPUT PINS *****/
  37. const uint8_t servo1_Servomotor_PWMSignal_PIN_D3 = 3;
  38. const uint8_t servo2_Servomotor_PWMSignal_PIN_D5 = 5;
  39. const uint8_t servo3_Servomotor_PWMSignal_PIN_D6 = 6;
  40. const uint8_t servo6_Servomotor_PWMSignal_PIN_D9 = 9;
  41.  
  42. /***** DEFINITION OF Software Serial *****/
  43. const uint8_t serial_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
  44. const uint8_t serial_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
  45. SoftwareSerial serial_HC05_mySerial(serial_HC05_mySerial_PIN_SERIAL_RX_A1, serial_HC05_mySerial_PIN_SERIAL_TX_A0);
  46.  
  47. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  48. /***** used to store raw data *****/
  49. uint8_t servo1_Servomotor_PWMSignal_PIN_D3_rawData = 0;
  50. uint8_t servo2_Servomotor_PWMSignal_PIN_D5_rawData = 0;
  51. uint8_t servo3_Servomotor_PWMSignal_PIN_D6_rawData = 0;
  52. uint8_t servo6_Servomotor_PWMSignal_PIN_D9_rawData = 0;
  53.  
  54. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  55. /***** used to store data after characteristic curve transformation *****/
  56. float servo1_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
  57. float servo2_Servomotor_PWMSignal_PIN_D5_phyData = 0.0;
  58. float servo3_Servomotor_PWMSignal_PIN_D6_phyData = 0.0;
  59. float servo6_Servomotor_PWMSignal_PIN_D9_phyData = 0.0;
  60.  
  61. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  62. Servo servo1;
  63. Servo servo2;
  64. Servo servo3;
  65. Servo servo6;
  66.  
  67. void setup(void)
  68. {
  69.     // Attach the servo motors to their respective pins
  70.     servo1.attach(servo1_Servomotor_PWMSignal_PIN_D3);
  71.     servo2.attach(servo2_Servomotor_PWMSignal_PIN_D5);
  72.     servo3.attach(servo3_Servomotor_PWMSignal_PIN_D6);
  73.     servo6.attach(servo6_Servomotor_PWMSignal_PIN_D9);
  74.  
  75.     // Initialize the serial communication
  76.     serial_HC05_mySerial.begin(9600);
  77. }
  78.  
  79. void loop(void)
  80. {
  81.     // Check if there is data available from the HC05 module
  82.     if (serial_HC05_mySerial.available())
  83.     {
  84.         // Read the position value from the serial communication
  85.         int position = serial_HC05_mySerial.read();
  86.         moveArm(position);
  87.     }
  88. }
  89.  
  90. void moveArm(int position)
  91. {
  92.     // Set the position for all the servo motors
  93.     servo1.write(position);
  94.     servo2.write(position);
  95.     servo3.write(position);
  96.     servo6.write(position);
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement