Skip to content
Snippets Groups Projects
Commit da65577a authored by Syed Muhammad Shahzeb Hassan's avatar Syed Muhammad Shahzeb Hassan
Browse files

Upload New File

parent 735ea182
Branches main
No related tags found
No related merge requests found
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
// Create an instance of the ADXL345 accelerometer
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
void setup() {
Serial.begin(9600);
// Initialize accelerometer
if (!accel.begin()) {
Serial.println("Could not find a valid ADXL345 sensor, check wiring!");
while (1);
}
accel.setRange(ADXL345_RANGE_2_G); // Set range to ±2G
// Print CSV header
Serial.println("Time(ms),Z-Value");
}
void loop() {
sensors_event_t event;
accel.getEvent(&event);
// Get current time in milliseconds
unsigned long currentTime = millis();
// Print time and Z-axis value in CSV format
Serial.print(currentTime);
Serial.print(",");
Serial.println(event.acceleration.z, 4); // Z value with 4 decimal places
delay(100); // Adjust sampling rate as needed
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment