pleasedontcode

Motion Transmitter rev_04

Nov 20th, 2025
419
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: Motion Transmitter
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-11-21 04:56:21
  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 Bluetooth to the ESP32. The ESP32 */
  22.     /* will then pass the data read by LabVIEW. This code */
  23.     /* will only be used by an ESP32 to function. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /* START CODE */
  28.  
  29. // Includes for Bluetooth and sensor communication
  30. #include <BluetoothSerial.h>
  31.  
  32. // Create a Bluetooth Serial object
  33. BluetoothSerial SerialBT;
  34.  
  35. // Variables for ADC readings from ADXL335
  36. int xAxisPin = 34; // GPIO pin for X-axis
  37. int yAxisPin = 35; // GPIO pin for Y-axis
  38. int zAxisPin = 32; // GPIO pin for Z-axis
  39.  
  40. // Variables to store sensor data
  41. float xAxisVoltage, yAxisVoltage, zAxisVoltage;
  42.  
  43. // Variable declarations for Bluetooth data
  44. String receivedData = "";
  45.  
  46. // Setup function
  47. void setup() {
  48.   Serial.begin(115200); // Start serial communication at 115200 baud rate
  49.   SerialBT.begin("ESP32_ADXL335_BT"); // Bluetooth device name
  50.   // Initialize ADC pins
  51.   pinMode(xAxisPin, INPUT);
  52.   pinMode(yAxisPin, INPUT);
  53.   pinMode(zAxisPin, INPUT);
  54. }
  55.  
  56. // Loop function
  57. void loop() {
  58.   // Read ADC values
  59.   int xValue = analogRead(xAxisPin);
  60.   int yValue = analogRead(yAxisPin);
  61.   int zValue = analogRead(zAxisPin);
  62.  
  63.   // Convert ADC values to voltages (assuming 3.3V ADC reference)
  64.   xAxisVoltage = xValue * 3.3 / 4095.0;
  65.   yAxisVoltage = yValue * 3.3 / 4095.0;
  66.   zAxisVoltage = zValue * 3.3 / 4095.0;
  67.  
  68.   // Create a JSON-like string to send
  69.   String sensorData = String("{\"X\":") + String(xAxisVoltage, 2) + ",\"Y\":" + String(yAxisVoltage, 2) + ",\"Z\":" + String(zAxisVoltage, 2) + "}";
  70.  
  71.   // Send data via Bluetooth
  72.   SerialBT.println(sensorData);
  73.  
  74.   // Check for incoming Bluetooth data
  75.   if (SerialBT.available()) {
  76.     receivedData = SerialBT.readStringUntil('\n');
  77.     // Process received data if needed
  78.   }
  79.  
  80.   delay(100); // Delay of 100ms
  81. }
  82.  
  83. /* END CODE */
  84.  
Advertisement
Add Comment
Please, Sign In to add comment