Advertisement
pleasedontcode

"Sensor Messaging" rev_05

May 26th, 2025
289
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: "Sensor Messaging"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-05-26 16:06:05
  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 YD_HC05_mySerial_PIN_SERIAL_TX_A2 = A2;
  38. const uint8_t YD_HC05_mySerial_PIN_SERIAL_RX_A3 = A3;
  39. SoftwareSerial YD_HC05_mySerial(YD_HC05_mySerial_PIN_SERIAL_RX_A3, YD_HC05_mySerial_PIN_SERIAL_TX_A2);
  40.  
  41. void setup(void)
  42. {
  43.     // Initialize the Bluetooth serial communication
  44.     YD_HC05_mySerial.begin(9600);
  45. }
  46.  
  47. void loop(void)
  48. {
  49.     // Simulated flex sensor value for demonstration
  50.     int flexSensorValue = analogRead(A0); // Read from an analog pin
  51.  
  52.     // Check the flex sensor value and send corresponding messages
  53.     if (flexSensorValue > 700) { // High flex
  54.         sendFlexSensorData(1); // Send "bye"
  55.     } else if (flexSensorValue < 300) { // Low flex
  56.         sendFlexSensorData(2); // Send "high"
  57.     } else { // Medium flex
  58.         sendFlexSensorData(3); // Send "nice to meet you"
  59.     }
  60.  
  61.     delay(1000); // Delay for a second before the next reading
  62. }
  63.  
  64. void sendFlexSensorData(int flexValue)
  65. {
  66.     // Send messages based on flex value
  67.     if (flexValue == 1) {
  68.         YD_HC05_mySerial.println("bye");
  69.     } else if (flexValue == 2) {
  70.         YD_HC05_mySerial.println("high");
  71.     } else if (flexValue == 3) {
  72.         YD_HC05_mySerial.println("nice to meet you");
  73.     }
  74. }
  75.  
  76. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement