ACCIDENT DETECTION DEVICE
Alejandro Mata
Antonio López Cruz
Oscar Sanchez Quintero
César Augusto Cortez
SUMMARY
The propose of this project is to build a device that can detect hits in the moto riders in order to reduce action timer, that is the time between a person call emergency and emergency answer. This was implemented using GSM, GPS and vibration technology. The functionality of this device is: when the IMU detects a vibration/g-force passing a certain threshold it will activate a flag in order to wake-up the GSM and start sending the messages with the actual position to their relatives and once this, will make a call to the same numbers.
OBJECTIVE
Develop an Accident Detection Device able to send SMS messages and make calls sequentially asking for medical assistance after 10 seconds the accident occurs.
Conditions:
-
SMS message must contains user´s name, which is the situation and also GPS coordinates where medical assitance is required.
-
Call must transmit an audio message advertising about the situation.
-
A cancel button must be added to prevent unnecessary assistance.
-
A led that turns on when an accident is detected.
-
A box that will contain all the modules inside to place on helmet.
INTRODUCTION
Road accidents have become in one of the main causes of death. In 2015 there was a record of 380 thousand accidents with 16 thousands deaths were 622 motorcycles were involved. In 2016 numbers didn´t get better since there is a record of 360 thoundsand accidents with 4 thousands deaths were 539 motorcycles were involved.
It is common to see how motorcyclists are exposed to suffer big damage during a road accident since they don´t have airbags or seat belt. This means they require immediate help when an accident occurs and sometimes motorcyclists are not able for asking help by themselves. The porpuse of this device is to reduce the time for medical assitance which means vital time that could be a factor to save user´s life. Also people close to the user will be notify about the events which increase the posibility of getting assitance and reduce the posibility of death or several damage.
MODULES
-
SIM900
How this module works?
SIM900 module allows you to send SMS, MMS, GPRS and Audio via UART using AT commands. In this way we use UART protocol to send data from FRDM K64 microcontroller.
Characteristics
- 5V 2A power source
- Control via AT commands (Serial)
- SIM card holder
- Microphone and Headphone jacks
- Power select switch
- Power key
- 19200 baudrate

Testing AT commands
we can test AT commands since the terminal emulator (TeraTerm) using an FTDI programer

Connect the FTDI to the SIM900 module as shows in the figure bellow

Open your terminal emulator and check if AT commands are working properly
To get more info plis check AT commands manual
-
ISD1820
How this module works?
This module is very simple to use since you can controled by push buttons. We can save an audio record message and reproduced it as much as we want as long as Rec button is not pressed again. As you can imagine to save an audio record we need to press Rec button then speak to the microphone with a time limit of 10 sec also is important to know that this module has a no‐volatile storage.
Characteristics
- Push‐button interface, playback can be edge or level activated
- Automatic power‐dwon mode
- Signal 3V Power Supply
- Can be controlled both manually or by MCU
- Dimensions: 37 x 54 mm
- REC: The REC input is an active‐HIGH record signal. The module starts recording whenever REC is HIGH.
- PLAYE : Playback, Edge‐activated: When a HIGH‐going transition is detected on continues until an End‐of‐Message (EOM) marker is encountered or the end of the memory space is reached.
- PLAYL : Playback, Level‐activated, when this input pin level transits for LOW to HIGH, a playback cycle is initiated. (NOT used for our porpuse)
- Speaker Outputs : The SP+ and SP‐ pins provide direct drive for loudspeakers with impedances as low as 8Ω

-
GPS NEO-6M V2
How this module works?
This module have 4 pins VCC, GND, Tx, Rx it is only to connect the module to VCC and once the module captures more or equal than 3 satellites will start to send the data in the Tx pin.
Characteristics
- Power Supply Range: 3 V to 5 V
- Model: GY-GPS6MV2
- Ceramic antenna
- EEPROM for saving the configuration data when powered off
- Backup battery
- LED signal indicator
- Antenna Size: 25 x 25 mm
- Module Size: 25 x 35 mm
- Mounting Hole Diameter: 3 mm
- Default Baud Rate: 9600 bps
-
IMU GY-85

How this module works?
This module has multiple pins but we used VCC, GND, SDA, SCL. The imu has 3 sensors integrated, accelerometer, gyroscope and magnetometer. Each one has a different address and to acquire the data we have to make read cycles via I2C protocol and given some data we have to apply some equations to obtain the g-forces and/or the angles in the X,Y or Z position. In order to execute the proper equations, we referenced by a tutorial made by ToC [1].
Characteristics
POWER SUPPLY
For this project we will feed the circuit with DC 5V / 2.0A power bank, it is important to know that 2A are necessary since GSM module has a 2A of current peak.

-- Power Supply Range: 3 V
- Model: GY-85
-Communication: I2C
-Gyroscope:ITG3205
-3 axis, 16 bits resolution
-Accelerometer: ADXL345
-3 axis, 10 bits resolution
-Magnetometer: HMC5883L
-3 axis, 12 bits resolution
- LED signal indicator

FRDM K64 MICROCONTROLLER
As we said before we used a FRDM K64 microcontroller to create the communications between GPS, GSM, IMU and voice recorder.
We required two protocols from this microcontroller, I2C for IMU, and UART for GPS and GSM modules also we need GPIO configurations for cancel button and Led.

-
UART PROTOCOL
-
UART PROTOCOL

Universal Asynchronous Receiver/Transmitter protocol is a very common protocol between modules As GPS and GSM. As you can see in the image there is an idle state before everything happens, once that we send and start bit begins the data bits trama which is transmitting or receiving. We can add a bit parity, but in this case we didn´t , so we just wait for stop bit to indicate that trama bits were successful complete (Transmitted it or received).


As you can see in the image there are two pins for UART3 which were used for GSM module

for more info about UART protocol please check FRDM K64 manual
-
I2C PROTOCOL


This image shows how I2C (Inter-Integrated Circuit) protocol works, As you can see there are two signals SDA and SCL.
SCL signal indicates when the data bits transmission begins and also when a bit from the trama byte is transmitted. First, we start whit the data byte direction if ACK bit is 0 that means that data byte direction was recognized then we can start to send the data byte. Stop bit indicates that transmission was completed.

As in UART protocol there are 2 pins for I2C protocol too SCL and SDA
NOTE: It is important to know that not every module works in the same way, for example wee need to check GY-85 datasheet to see how I2C protocol works when I´m writting to the module or reading from the module.
Single-Byte Write Sequence for IMU

Single-Byte read Sequence for IMU

HARDWARE
HIGH LEVEL DESIGN
The next figure shows all the peripherals interconnected to the K64F and with which protocol interacts with them such as I2C, UART, digital inputs and outputs.

BOX DESIGN AND PERFBOARD
The design of the box was a little complex because the design should be small, but at the same time, all the modules have to fit inside the box, so we did a curved box in order to adjust properly to the helmet. All the interconnection inside the box was hard to perform because the wires should be perfectly soldered and we had to ensure that any disconnection could happen so we screwed some modules so they couldn't move. Also we used a perf board in order to move all the power to one place and to take from them because some devices required more current than the microcontroller can give so we directly supplied from the power bank.



SOFTWARE DESIGN
GSM
To implement the GSM we found that a state machine is the best option as the microcontroller runs much faster than the GSM module so we had to wait until the GSM answer with an OK, ERROR, NO CARRIER or ' >' . In the next figure shows the implementation to send a message by one side is the method that the user can call from the main and the other shows the state machine. The other picture shows the header file from the GSM and all the AT commands we used. To make the call we had to take several considerations such as the gain of the microphone so the audio could hear well.




GPS
To implement the GPS we only received the commands via serial, so we only had to compare the command we wanted: "$GPRMC", once we validated the command we also have to take care if it was an invalid or valid position so we also had to compare another string: "A" or "V" if it was A the measure was correct. Then we only had to save in a buffer the 4 fields and adjust properly to have an accurate measure. The next two figures show how we recovered the data sent by the GPS


The way we implemented the timer was very basic since we only had to count 10 seconds when the IMU detect any hit or vibration passed a threshold and then wake up the GSM to send the messages and make calls. We configured the timer to make a certain amount of counts and passed this count we change the state of a flag to 1. The figures shows the initialization of the module and the procedure inside the interruption.
TIMER


IMU & Vibration Sensor
This sensor was one of the most important since is the one that is monitoring what is happening in the environment. This sensor uses the I2C protocol, so firstly we did some configuration in the microcontroller module to manage properly. We realize that the IMU has new information every 8ms and firstly you must initialize the IMU correctly otherwise it will give you wrong data. Also we implemented a very, very small delay between each start and stop so the SDA line can have enough time to change properly, the next two figures show it.


Once we initialized the IMU properly we made read cycles to obtain the data, we send to the IMU which registers we want to read and then only have to wait for the data, we saved the data in a buffer and once we acquired the data we had to concatenate because the IMU send the data split in 2 registers of 8 bits each one. The raw data have to be transformed with some equations so we can obtain values that make sense with our environment. How we obtain these equations and the explanation of this ones are in the list of references. By one side we can see the read cycle and in the other the header file of the accelerometer and the respective equations. We


ISD
To manage this module by software it was easy since we only had to set a GPIO pin as output and put a logic 1 of 200ms more less in the P-E pin to start the audio previously recorded, the next image shows when we were in call state, firstly begin the communication with the MAKE_CALL_STATE_MACHINE and when the call was answered it writes a logic one to that pin, then returns to zero.

RESULTS
The next figure shows the SMS message sent by the GSM, in the message is requesting medical assistance, and in the next one the GPS position in decimal format. It was a little variation from the real position and from the GPS give us, around 5-7 meters. Once the message is sent, the GSM module starts making calls from a list previously added to the code. When we answer the call it started to reproduce the message saved in the ISD module.


The next figure shows all the components interconnected in the final box, it was very hard to made tests since the box had to receive a hit to detect big g-forces, so we put the threshold of IMU a little low so it can detect any variation from the environment.


REFERENCES
The next links were used to develop the project, are open sources and provides excellent explanation from the modules we used