Advertisement
pleasedontcode

Bluetooth Alert rev_02

Dec 5th, 2024
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: Bluetooth Alert
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-05 09:45:44
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Establezca conexión Bluetooth con un módulo ESP32 */
  21.     /* utilizando SoftwareSerial; al perder la señal, */
  22.     /* active un buzzer conectado a un pin digital para */
  23.     /* alertar al usuario. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <SoftwareSerial.h>
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void checkBluetoothConnection(void);
  36.  
  37. /***** DEFINITION OF Software Serial *****/
  38. const uint8_t pedro_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
  39. const uint8_t pedro_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
  40. SoftwareSerial pedro_HC05_mySerial(pedro_HC05_mySerial_PIN_SERIAL_RX_A1, pedro_HC05_mySerial_PIN_SERIAL_TX_A0);
  41.  
  42. /***** DEFINITION OF BUZZER PIN *****/
  43. const uint8_t buzzerPin = 9; // Buzzer connected to digital pin 9
  44.  
  45. void setup(void)
  46. {
  47.     // Initialize serial communication with the Bluetooth module
  48.     pedro_HC05_mySerial.begin(9600);
  49.    
  50.     // Initialize the buzzer pin as an output
  51.     pinMode(buzzerPin, OUTPUT);
  52.    
  53.     // Ensure the buzzer is off initially
  54.     digitalWrite(buzzerPin, LOW);
  55. }
  56.  
  57. void loop(void)
  58. {
  59.     // Check Bluetooth connection status
  60.     checkBluetoothConnection();
  61.    
  62.     // Add any other main code here
  63. }
  64.  
  65. /***** FUNCTION TO CHECK BLUETOOTH CONNECTION *****/
  66. void checkBluetoothConnection(void)
  67. {
  68.     // If no data is available from the Bluetooth module
  69.     if (!pedro_HC05_mySerial.available())
  70.     {
  71.         // Activate the buzzer to alert the user
  72.         digitalWrite(buzzerPin, HIGH); // Turn on buzzer
  73.     }
  74.     else
  75.     {
  76.         // If data is available, turn off the buzzer
  77.         digitalWrite(buzzerPin, LOW); // Turn off buzzer
  78.     }
  79. }
  80.  
  81. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement