pleasedontcode

Accelerometer Transmission rev_01

Nov 20th, 2025
344
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: Accelerometer Transmission
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-11-21 04:36:50
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The sensor is an ADXL335 which will send its */
  21.     /* information via the Bluetooth of the ESP32, which */
  22.     /* will then pass the data read by LabVIEW. */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <BluetoothSerial.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. // Create a BluetoothSerial object
  36. BluetoothSerial SerialBT;
  37.  
  38. // Variables to hold accelerometer data
  39. int xAxis = 0;
  40. int yAxis = 0;
  41. int zAxis = 0;
  42.  
  43. // Pin definitions for ADXL335 (assuming Analog pins A0, A1, A2)
  44. const int xPin = 32; // GPIO32
  45. const int yPin = 33; // GPIO33
  46. const int zPin = 34; // GPIO34
  47.  
  48. // Function to initialize Bluetooth
  49. void initBluetooth() {
  50.   SerialBT.begin("ESP32_ACCEL") ; // Name of the Bluetooth device
  51.   Serial.println("Bluetooth initialized. Device is ready to pair.");
  52. }
  53.  
  54. // Function to read sensor data
  55. void readSensorData() {
  56.   xAxis = analogRead(xPin);
  57.   yAxis = analogRead(yPin);
  58.   zAxis = analogRead(zPin);
  59. }
  60.  
  61. // Function to send data over Bluetooth
  62. void sendData() {
  63.   String data = "X:" + String(xAxis) + ",Y:" + String(yAxis) + ",Z:" + String(zAxis);
  64.   SerialBT.println(data);
  65. }
  66.  
  67. void setup(void)
  68. {
  69.   Serial.begin(115200); // Initialize serial communication
  70.   // Initialize sensor pins
  71.   pinMode(xPin, INPUT);
  72.   pinMode(yPin, INPUT);
  73.   pinMode(zPin, INPUT);
  74.   initBluetooth(); // Initialize Bluetooth
  75. }
  76.  
  77. void loop(void)
  78. {
  79.   readSensorData(); // Read accelerometer data
  80.   sendData(); // Send data via Bluetooth
  81.   delay(100); // Delay for stability
  82. }
  83.  
  84. /* END CODE */
  85.  
Advertisement
Add Comment
Please, Sign In to add comment