Close

Crash Alert Up and Running

A project log for DriveSense

A Raspberry Pi used to make a system that would alert a drowsy driver that he is falling asleep using OpenCV image recognition.

aryanAryan 07/12/2019 at 01:110 Comments

I wired up the Pi to the ADXL345 and tested it and tested the code. It seemed to work fine. The Pi needed the I2C interface to be on preceding a reboot. After that I made a few modifications

import time

# Import the ADXL345 module.
import Adafruit_ADXL345


# Create an ADXL345 instance.
accel = Adafruit_ADXL345.ADXL345()

I used the above modules.

while True:
    # Read the X, Y, Z axis acceleration values
        x, y, z = accel.read()
        if x > 500 or y > 500 or z > 500: #500 is the number that the values go above in all my crash tests
                print('crash alert')
    # Wait half a second and repeat.
        time.sleep(0.25)

This is the code I used.

The output was the words "crash alert" showing up when I shake the ADXL345 module.

This was detected because after testing I found that in which ever angle you shake it, the X, Y, or Z value went above 500. When an actual crash happens, the entire thing would shake the same way. So I used this method to get the crash alert. 

Discussions