Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: Accelerometer Broadcast
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-11-21 04:37:40
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The sensor is an ADXL335 which will send its */
- /* information via the Bluetooth of the ESP32, which */
- /* will then pass the data read by LabVIEW. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <BluetoothSerial.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Create a BluetoothSerial object
- BluetoothSerial SerialBT;
- // Variables to hold accelerometer data
- int xAxis = 0;
- int yAxis = 0;
- int zAxis = 0;
- // Pin definitions for ADXL335 (assuming Analog pins A0, A1, A2)
- const int xPin = 32; // GPIO32
- const int yPin = 33; // GPIO33
- const int zPin = 34; // GPIO34
- // Function to initialize Bluetooth
- void initBluetooth() {
- SerialBT.begin("ESP32_ACCEL"); // Name of the Bluetooth device
- Serial.println("Bluetooth initialized. Device is ready to pair.");
- }
- // Function to read sensor data
- void readSensorData() {
- xAxis = analogRead(xPin);
- yAxis = analogRead(yPin);
- zAxis = analogRead(zPin);
- }
- // Function to send data over Bluetooth
- void sendData() {
- String data = "X:" + String(xAxis) + ",Y:" + String(yAxis) + ",Z:" + String(zAxis);
- SerialBT.println(data);
- }
- void setup(void) {
- Serial.begin(115200); // Initialize serial communication
- // Initialize sensor pins
- pinMode(xPin, INPUT);
- pinMode(yPin, INPUT);
- pinMode(zPin, INPUT);
- initBluetooth(); // Initialize Bluetooth
- }
- void loop(void) {
- readSensorData(); // Read accelerometer data
- sendData(); // Send data via Bluetooth
- delay(100); // Delay for stability
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment