I've configured an ADXL345 connected to an ESP32 WROOM module to detect movements and count them via interrupt pin.
However, I've encountered a significant issue: despite no actual movements occurring, I'm receiving numerous false alarms.
In the last test, I received 67 interrupts within a 12-hour period.
Both the ADXL and WROOM32 are situated on a carbon steel electric scooter. Despite the scooter being stationary on the floor and untouched by anyone, I'm consistently getting false reports triggered by apparent movements. Any suggestions on how to resolve this issue would be greatly appreciated.
// adxl345
#include <Wire.h>
const int ADXL345_ADDRESS = 0x53; // I2C address of ADXL345
const byte GPIO_adxl345 = 23; //adxl_345 interrupt
int adxl345_motion_count = 0; // count
// adxl345
// SETUP
void setup() {
Wire.begin(); //i2c for adxl345 and PCF8574
Wire.setClock(100000); // Set I2C clock speed to 100 kHz
pinMode(GPIO_adxl345, INPUT);
Wire.beginTransmission(ADXL345_ADDRESS);
Wire.write(0x2D);
Wire.write(0x08); // Set to normal operation mode 00001000 (0x08)
Wire.endTransmission();
//DATA RATE HZ
Wire.beginTransmission(ADXL345_ADDRESS);
Wire.write(0x2C); // LOW/normal_power + data rate HZ
Wire.write(0x04); // Set data rate to 0.78 Hz. LOW/normal power (0000 0100) data rate
Wire.endTransmission();
// Wire.beginTransmission(ADXL345_ADDRESS);
// Wire.write(0x31); // g range
// Wire.write(0x01); // 4G=00000001(0x01)
// Wire.endTransmission();
//ACTIVITY: ac/dc,x,y,z inactivity: ac/dc,x,y,z
Wire.beginTransmission(ADXL345_ADDRESS);
Wire.write(0x27); // Axis enable control for activity and inactivity detection
Wire.write(0xF0); // 0xF0 = 11110000 AC,X,Y,,,,,
Wire.endTransmission();
// INT_1 / INT_2
Wire.beginTransmission(ADXL345_ADDRESS);
Wire.write(0x2F); // Interrupt mapping control INT1 or INT2 EF=INT1:activity others INT2
Wire.write(0x00);
Wire.endTransmission();
// Interrupt enable for ACTIVITY
Wire.beginTransmission(ADXL345_ADDRESS); // 0x10= activity ON (00010000) all off(freefall,inactivity,tap...)
Wire.write(0x2E);
Wire.write(0x10); // Enable just activity
Wire.endTransmission();
//Activity threshold
Wire.beginTransmission(ADXL345_ADDRESS);
Wire.write(0x24);
Wire.write(0x07); // 0-255 deimal 00000000-11111111 62.5mg * 255 =15,937mg(16g) 0x07=
Wire.endTransmission();
attachInterrupt(digitalPinToInterrupt(GPIO_adxl345), adxl345_new_motionISR, RISING);
}
void adxl345_new_motionISR() {
adxl345_motion_count++;
}
