/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: Motion Transmitter
- Source Code NOT compiled for: ESP32 DevKit V1
- Source Code created on: 2025-11-21 04:56:21
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* The sensor is an ADXL335, which will send its */
/* information via Bluetooth to the ESP32. The ESP32 */
/* will then pass the data read by LabVIEW. This code */
/* will only be used by an ESP32 to function. */
/****** END SYSTEM REQUIREMENTS *****/
/* START CODE */
// Includes for Bluetooth and sensor communication
#include
// Create a Bluetooth Serial object
BluetoothSerial SerialBT;
// Variables for ADC readings from ADXL335
int xAxisPin = 34; // GPIO pin for X-axis
int yAxisPin = 35; // GPIO pin for Y-axis
int zAxisPin = 32; // GPIO pin for Z-axis
// Variables to store sensor data
float xAxisVoltage, yAxisVoltage, zAxisVoltage;
// Variable declarations for Bluetooth data
String receivedData = "";
// Setup function
void setup() {
Serial.begin(115200); // Start serial communication at 115200 baud rate
SerialBT.begin("ESP32_ADXL335_BT"); // Bluetooth device name
// Initialize ADC pins
pinMode(xAxisPin, INPUT);
pinMode(yAxisPin, INPUT);
pinMode(zAxisPin, INPUT);
}
// Loop function
void loop() {
// Read ADC values
int xValue = analogRead(xAxisPin);
int yValue = analogRead(yAxisPin);
int zValue = analogRead(zAxisPin);
// Convert ADC values to voltages (assuming 3.3V ADC reference)
xAxisVoltage = xValue * 3.3 / 4095.0;
yAxisVoltage = yValue * 3.3 / 4095.0;
zAxisVoltage = zValue * 3.3 / 4095.0;
// Create a JSON-like string to send
String sensorData = String("{\"X\":") + String(xAxisVoltage, 2) + ",\"Y\":" + String(yAxisVoltage, 2) + ",\"Z\":" + String(zAxisVoltage, 2) + "}";
// Send data via Bluetooth
SerialBT.println(sensorData);
// Check for incoming Bluetooth data
if (SerialBT.available()) {
receivedData = SerialBT.readStringUntil('\n');
// Process received data if needed
}
delay(100); // Delay of 100ms
}
/* END CODE */