I am using ADXL345 accelerometer with Adafruit_ADXL345 library for vibration measurement.
I am reading acceleration at X, Y, Z-axis of a sensor placed on a vibrating platform.And serially sending it to PC at a baud rate of 115200.
When vibration is low sensor shows vibrations but as i increase the vibrations serial transmission seems to be halted. As shown in figure:(x-axis=Samples y-axis=Values )
I thought it may be due to loose connections so I soldered its terminals but it behaved the same way at higher vibrations. Here is the code that I’m using.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12);
int i=0;
struct measure
{
int timestamp;
float x; // ACC in x direction
float y; //ACC in y direction
float z; //ACC in z direction
};
sensors_event_t event;
struct measure measurements;
int timestamp = 0;
void setup(){
Serial.begin(115200);
Serial.println("Accelerometer Test"); Serial.println("");
/* Initialise the sensor */
if(!accel.begin())
{
/* There was a problem detecting the ADXL345 ... check your connections */
Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
while(1);
}
accel.setDataRate(ADXL345_DATARATE_3200_HZ);
accel.setRange(ADXL345_RANGE_16_G);
pinMode(LED_BUILTIN, OUTPUT);
delay(2000);
}
void loop(){
accel.getEvent(&event);
measurements.timestamp = timestamp++;
measurements.x = event.acceleration.x;
measurements.y = event.acceleration.y;
measurements.z = event.acceleration.z;
if(measurements.timestamp%2==0)
digitalWrite(LED_BUILTIN, HIGH);
else
digitalWrite(LED_BUILTIN, LOW);
/* Sending the array with data through serial*/
Serial.print(measurements.timestamp);
Serial.print(",");
Serial.print(measurements.x+0.06);
Serial.print(",");
Serial.print(measurements.y+0.7);
Serial.print(",");
Serial.println(measurements.z-10.10);
}
Where does problem lie? How to resolve this issue?