nertechgate
Published

LANE TECH PCL - DoorForce Tracker

DoorForce Tracker detects every slam, measures its impact, and sends an instant email alert with force and direction data!

IntermediateFull instructions provided1
LANE TECH PCL - DoorForce Tracker

Things used in this project

Hardware components

Photon
Particle Photon
×1
SparkFun Triple Axis Accelerometer and Gyro Breakout - MPU-6050
SparkFun Triple Axis Accelerometer and Gyro Breakout - MPU-6050
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Code

DoorForce Tracker

C/C++
#include "Particle.h"
#include <Wire.h>
#include <MPU6050.h>

SYSTEM_MODE(AUTOMATIC);

MPU6050 mpu;
int16_t ax, ay, az;
float ax_offset = -2350;
float ay_offset = 14000;
float az_offset = 2000;
const float SENS = 2048.0;
const float THRESHOLD = 3.0;
const unsigned long COOLDOWN = 1000;
unsigned long lastEvent = 0;

void setup() {
    Serial.begin(9600);
    Wire.begin();
    mpu.initialize();

    if (!mpu.testConnection()) {
        Serial.println("MPU6050 connection failed!");
        while (1);
    }

    Serial.println("MPU6050 ready.");
}

void loop() {
    mpu.getAcceleration(&ax, &ay, &az);

    float x = ((float)ax - ax_offset) / SENS;
    float y = ((float)ay - ay_offset) / SENS;
    float z = ((float)az - az_offset) / SENS;

    Serial.printf("X=%.1f  Y=%.1f  Z=%.1f\n", x, y, z);

    if ((fabs(x) >= THRESHOLD || fabs(z) >= THRESHOLD) &&
        (millis() - lastEvent > COOLDOWN)) {

        String direction;
        float value;

        if (fabs(x) >= THRESHOLD) {
            direction = "X";
            value = x;
        } else {
            direction = "Z";
            value = z;
        }

        String data = String::format("{\"direction\":\"%s\",\"value\":%.2f}", direction.c_str(), value);

        Particle.publish("door_slam_event", data, PRIVATE);
        Serial.println("⚠️ Event published: " + data);

        lastEvent = millis();
    }

    delay(250);
}

Google Script

JSON
function doPost(e) {
  var eventData = JSON.parse(e.postData.contents);
  var payload = JSON.parse(eventData.data);
  var direction = payload.direction;
  var value = payload.value;
  var subject = "🚪 Door Slam Alert";
  var body = "Direction: " + direction + "\nValue: " + value.toFixed(2) + " g";
  MailApp.sendEmail("ntzgonena@cps.edu", subject, body);
  return ContentService.createTextOutput("OK");
}

Credits

nertechgate
1 project • 0 followers

Comments