Advertisement
pleasedontcode

"Bluetooth Sensor" rev_04

May 26th, 2025
287
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 Sensor"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-05-26 15:41:48
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* generate the code for bluetooth sensor to send or */
  21.     /* receive the data of flex sensor when flex is more */
  22.     /* then high and low then bye and medium then nice to */
  23.     /* meet you */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <SoftwareSerial.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void sendFlexSensorData(int flexValue);
  35.  
  36. /***** DEFINITION OF Software Serial *****/
  37. const uint8_t piyush_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
  38. const uint8_t piyush_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
  39. SoftwareSerial piyush_HC05_mySerial(piyush_HC05_mySerial_PIN_SERIAL_RX_A1, piyush_HC05_mySerial_PIN_SERIAL_TX_A0);
  40.  
  41. void setup(void)
  42. {
  43.     // Initialize the Bluetooth serial communication
  44.     piyush_HC05_mySerial.begin(9600);
  45. }
  46.  
  47. void loop(void)
  48. {
  49.     // Simulated flex sensor value (replace this with actual sensor reading)
  50.     int flexValue = analogRead(A2); // Assuming the flex sensor is connected to A2
  51.  
  52.     // Send data based on the flex sensor value
  53.     sendFlexSensorData(flexValue);
  54.  
  55.     delay(1000); // Delay for readability
  56. }
  57.  
  58. void sendFlexSensorData(int flexValue)
  59. {
  60.     if (flexValue > 800) // High flex
  61.     {
  62.         piyush_HC05_mySerial.println("High: bye");
  63.     }
  64.     else if (flexValue < 400) // Low flex
  65.     {
  66.         piyush_HC05_mySerial.println("Low: nice to meet you");
  67.     }
  68.     else // Medium flex
  69.     {
  70.         piyush_HC05_mySerial.println("Medium: nice to meet you");
  71.     }
  72. }
  73.  
  74. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement