#include #include #include #define LED_PIN 1 // your LED pin TwoWire I2CBus = TwoWire(0); Adafruit_ADXL343 accel = Adafruit_ADXL343(12345, &I2CBus); // store previous readings float lastX = 0, lastY = 0, lastZ = 0; // movement sensitivity threshold const float threshold = 2.5; // adjust this value for sensitivity void setup() { pinMode(LED_PIN, OUTPUT); Serial.begin(115200); while (!Serial); I2CBus.begin(5, 6); // SDA = GPIO5, SCL = GPIO6 if (!accel.begin(0x1D)) { // your detected I2C address Serial.println("No ADXL343 detected. Check wiring!"); while(1); } // initialize last readings sensors_event_t event; accel.getEvent(&event); lastX = event.acceleration.x; lastY = event.acceleration.y; lastZ = event.acceleration.z; Serial.println("ADXL343 detected!"); } void loop() { sensors_event_t event; accel.getEvent(&event); // calculate total movement from previous readings float dx = abs(event.acceleration.x - lastX); float dy = abs(event.acceleration.y - lastY); float dz = abs(event.acceleration.z - lastZ); float movement = dx + dy + dz; if (movement > threshold) { digitalWrite(LED_PIN, HIGH); // turn LED on delay(50); // short blink digitalWrite(LED_PIN, LOW); // turn LED off } // update last readings lastX = event.acceleration.x; lastY = event.acceleration.y; lastZ = event.acceleration.z; delay(50); // small delay to avoid flooding }