# Airbag Protection and Alerting System for Elderly People
## 3 System Implementation
### Software Implementation  
The Arduino IDE 1.8.5 software for programming the Arduino Nano board was used in this project [27]. By using the Arduino IDE software, we devised a code for the system to recognize when a person falls. The Arduino is familiar with all the electrical components in our system except for the ADXL345 accelerometer, so we added a library called \"Adafruit\" that helps the Arduino connect with the ADXL345 accelerometer. The required libraries were called at the start of the code, where pin number D4 has been declared as the output of the Arduino to the transistor to open the solenoid air valve. Pin D2 and D3 on the Arduino for the TX and RX pins on the Bluetooth module, respectively, and four float variables have been declared \"at, xa, ya, and za\" which are, total acceleration, acceleration on the x-axis, acceleration on the y-axis, and acceleration on the z-axis, respectively. These are the initial steps to the code. In the setup section of the code [void setup()], the HC-06 Bluetooth module and the ADXL345 accelerometer were initialized by setting the haud rate to 9600 for the Bluetooth module and setting the ADXL345 accelerometer sensitivity to 16 G (from either 2 G, 4 G, 8 G, 16 G) which sets the sensitivity to the acceleration of the ADXL345 accelerometer. Pin D4 on the Arduino was set to zero to ensure that the valve does not get a signal until a fall occurs. In the loop section of the code [void loop()], \"xa, ya, and za\" were set to the acceleration of the x-axis, y-axis, and z-axis, respectively. The total acceleration \"at\" is set to the mean square root of \"xa, ya, and za\". Considering the value of \"at\", an \"if statement\" is written to determine if the person fell or not as follows: if the total acceleration is larger than the threshold, a string will be transmitted to the Bluetooth module to tell the mobile application that a fall has occurred, a signal will be sent to pin D4, and a signal will reach the MOSFET transistor that will send 12 volts to the solenoid valve to open and inflate the airbag. For developing the Android application, a graphical user interface, MIT App Inventor was used. It is an open-source online application for Android; it was first made available by Google and is currently maintained by the Massachusetts Institute of Technology (MIT). Everyone can create fully working apps for smartphones and tablets using the MIT App Inventor, which is a user-friendly, visual programming environment. The developed mobile application interface before connecting to the Bluetooth module is shown in Figure 12. It shows the mobile application connection status with the hardware via Bluetooth and some instruction messages for both before and after connecting the device. It also shows the field where the mobile number of the user's emergency contact should be entered. When the Arduino sends a signal to the mobile application (via the HC-06 Bluetooth module), the location of the user (latitude and longitude) will be determined using the mobile's built-in GPS and shown on the mobile application interface. After a mobile number is entered and the phone is linked to the Bluetooth module, the mobile application interface changes and shows the status of \"System is Active\" as given in Figure 12b, thus, saving energy. The system is ready to receive a signal from the Bluetooth module when a fall is detected. When this occurs, the Arduino transmits a signal to the Bluetooth module which is next transmitted to the mobile application. Figure 13a shows the mobile application interface when the fall is detected. After fifteen seconds (the cancellation period) with the SMS sent, the interface is shown in Figure 13b. If a fall occurs, the person has the option to cancel the SMS from being sent if they do not require attention.