pleasedontcode

Accelerometer Streaming rev_03

Nov 20th, 2025
404
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 Streaming
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-11-21 04:40: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.  
  27.  
  28. /* START CODE */
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <BluetoothSerial.h>
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36.  
  37. // Create a BluetoothSerial object
  38. BluetoothSerial SerialBT;
  39.  
  40. // Variables to hold accelerometer data
  41. int xAxis = 0;
  42. int yAxis = 0;
  43. int zAxis = 0;
  44.  
  45. // Pin definitions for ADXL335 (assuming Analog pins A0, A1, A2)
  46. const int xPin = 32; // GPIO32
  47. const int yPin = 33; // GPIO33
  48. const int zPin = 34; // GPIO34
  49.  
  50. // Function to initialize Bluetooth
  51. void initBluetooth() {
  52.   SerialBT.begin("ESP32_ACCEL"); // Name of the Bluetooth device
  53.   Serial.println("Bluetooth initialized. Device is ready to pair.");
  54. }
  55.  
  56. // Function to read sensor data
  57. void readSensorData() {
  58.   xAxis = analogRead(xPin);
  59.   yAxis = analogRead(yPin);
  60.   zAxis = analogRead(zPin);
  61. }
  62.  
  63. // Function to send data over Bluetooth
  64. void sendData() {
  65.   String data = "X:" + String(xAxis) + ",Y:" + String(yAxis) + ",Z:" + String(zAxis);
  66.   SerialBT.println(data);
  67. }
  68.  
  69. void setup(void) {
  70.   Serial.begin(115200); // Initialize serial communication
  71.   // Initialize sensor pins
  72.   pinMode(xPin, INPUT);
  73.   pinMode(yPin, INPUT);
  74.   pinMode(zPin, INPUT);
  75.   initBluetooth(); // Initialize Bluetooth
  76. }
  77.  
  78. void loop(void) {
  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