Advertisement
pleasedontcode

Bluetooth Communication rev_01

Aug 18th, 2024
121
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 Communication
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-08-18 07:23:03
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a setup function to initialize the HC-05 */
  21.     /* Bluetooth module for reliable data transmission */
  22.     /* and a loop function for continuous operation in an */
  23.     /* Arduino environment. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <SoftwareSerial.h> //https://github.com/plerup/espsoftwareserial
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF Software Serial *****/
  34. const uint8_t dd_HC05_mySerial_PIN_SERIAL_TX_A0 = A0; // Define TX pin for HC-05
  35. const uint8_t dd_HC05_mySerial_PIN_SERIAL_RX_A1 = A1; // Define RX pin for HC-05
  36. EspSoftwareSerial::UART dd_HC05_mySerial; // Create an instance of SoftwareSerial
  37.  
  38. void setup(void)
  39. {
  40.     // Initialize the serial communication for HC-05 Bluetooth module
  41.     dd_HC05_mySerial.begin(9600, SWSERIAL_8N1, dd_HC05_mySerial_PIN_SERIAL_RX_A1, dd_HC05_mySerial_PIN_SERIAL_TX_A0, false);
  42.    
  43.     // Optional: Start the Serial Monitor for debugging
  44.     Serial.begin(9600); // Start the hardware serial for debugging
  45.     Serial.println("HC-05 Bluetooth Module Initialized");
  46. }
  47.  
  48. void loop(void)
  49. {
  50.     // Continuously check if data is available from the HC-05
  51.     if (dd_HC05_mySerial.available()) {
  52.         char receivedChar = dd_HC05_mySerial.read(); // Read the incoming data
  53.         Serial.print("Received: "); // Print received data to Serial Monitor
  54.         Serial.println(receivedChar);
  55.     }
  56.  
  57.     // Optional: Send a test message to the HC-05
  58.     // Uncomment the following lines to send data periodically
  59.     /*
  60.     dd_HC05_mySerial.println("Hello from Arduino!"); // Send a test message
  61.     delay(1000); // Wait for 1 second before sending again
  62.     */
  63. }
  64.  
  65. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement