Vehicle Accident Alert System Using Accelerometer
Vehicle Accident Alert Using Accelerometer GPS And GSM
Introduction
In This Article, we design a Vehicle Accident Alert System using an ADXL-335 Sensor, Measuring the Impact of the Accident And giving information on which side More Impact happened if crosses the threshold value and then sending an SMS with proper GPS coordinates.
Bill Of Materials
S.N | Component's | Quantity | Link To Buy |
1 | Arduino nano | 1 | |
2 | ADXL345 Module | 1 | |
3 | SIM800l GSM Module | 1 | |
4 | NEO-6m Module | 1 | |
5 | LM2596 Step Down Conveter | 1 | |
6 | Push Button | 1 | |
7 | 10k resister | 1 | |
8 | Zero PCB | 1 | |
9 | 3.7v lithium-Ion Battery | 2 |
Component’s
Arduino Nano
- The Arduino Nano is the open-source smallest Embedded Development board based on Atmega328 SMD Package Microcontroller.
- Arduino Nano is a low-cost microcontroller and so many GPIO Pin available.
ADXL335
This module can be used to sense motion (in the case of non-moving) in 3 axes. This is the latest in a long, proven line of Analog Sensors- the holy grail of accelerometers.
Features
- ADXL335: 3-axis sensing.
- Small, low-profile package.
- Low power: 350 μA.
- Single-supply operation: 1.8 V to 3.6 V.
- Excellent temperature stability.
- BW adjustment with a single capacitor per axis.
- RoHS/WEEE is lead-free compliant.
SIM800l GSM Module
You can communicate with the SIM800l module via the UART port, which supports the AT command.
Features
- Quad-band 850/900/1800/1900MHz – connect to any global GSM network.
- Make and receive voice calls using a headset or an external 8Ω speaker and electret microphone.
- AT command interface with “auto baud” detection.
- Send and receive SMS messages.
- Send and receive GPRS data (TCP/IP, HTTP, etc.).
LM2596 Step Down Conveter
LM2596 DC-DC Buck Converter Adjustable Step-Down Power Supply Module is this project we used the provide proper 3.7v to sim800l GSM Module.
NEO-6m Module
The GPS module is based on the NEO-6M. This unit uses the latest technology to give the best possible positioning information and includes a larger built-in 25 x 25mm active GPS antenna with a UART TTL socket.
Features
- 5Hz position update rate
- Operating temperature range: -40 TO 85°CUART TTL socket
- EEPROM to save configuration settings
- Rechargeable battery for Backup
- Supply voltage: 3.3 V to 5V.
- Configurable from 4800 Baud to 115200 Baud rates.
Circuit diagram
In this circuit, we show the proper pin where we connected the modules.
- Like, the GPS Module is connected to Pin Numbers D9, and D8 in Arduino nano microcontroller.
- Sim800l GSM Module is connected to the D2 And D3 Pin of Arduino Nano.
- ADXL-335 Sensor is connected to the PIN Numbers A0, A1, and A2.
- We used the One Push Button Which is connected to the Pin Number D11.
Code
Before you Upload the code install the TinyGPS library in your Arduino IDE Software.
AltSoftSerial
TinyGPS++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
#include <AltSoftSerial.h> #include <TinyGPS++.h> #include <SoftwareSerial.h> #include <math.h> #include <Wire.h> const String EMERGENCY_PHONE = "+9188305848xx"; //GSM Module Conected Pin D2 & D3 #define rxPin 2 #define txPin 3 SoftwareSerial sim800(rxPin, txPin); //GPS Modue Conected Pin D9 & D8 AltSoftSerial neogps; TinyGPSPlus gps; String sms_status, sender_number, received_date, msg; String latitude, longitude; #define BUZZER 12 #define BUTTON 11 #define xPin A0 #define yPin A1 #define zPin A2 byte updateflag; int xaxis = 0, yaxis = 0, zaxis = 0; int deltx = 0, delty = 0, deltz = 0; int vibration = 2, devibrate = 75; int magnitude = 0; int sensitivity = 20; double angle; boolean impact_detected = false; unsigned long time1; unsigned long impact_time; unsigned long alert_delay = 30000; void setup() { Serial.begin(9600); Serial.println("SIM800L serial initialize"); sim800.begin(9600); Serial.println("NEO6M serial initialize"); neogps.begin(9600); pinMode(BUZZER, OUTPUT); pinMode(BUTTON, INPUT_PULLUP); sms_status = ""; sender_number = ""; received_date = ""; msg = ""; sim800.println("AT"); delay(1000); sim800.println("ATE1"); delay(1000); sim800.println("AT+CPIN?"); delay(1000); sim800.println("AT+CMGF=1"); delay(1000); sim800.println("AT+CNMI=1,1,0,0,0"); delay(1000); time1 = micros(); xaxis = analogRead(xPin); yaxis = analogRead(yPin); zaxis = analogRead(zPin); } void loop() { if (micros() - time1 > 1999) Impact(); if (updateflag > 0) { updateflag = 0; Serial.println("Impact detected!!"); Serial.print("Magnitude:"); Serial.println(magnitude); getGps(); digitalWrite(BUZZER, HIGH); impact_detected = true; impact_time = millis(); } if (impact_detected == true) { if (millis() - impact_time >= alert_delay) { digitalWrite(BUZZER, LOW); makeCall(); delay(1000); sendAlert(); impact_detected = false; impact_time = 0; } } if (digitalRead(BUTTON) == LOW) { delay(200); digitalWrite(BUZZER, LOW); impact_detected = false; impact_time = 0; } while (sim800.available()) { parseData(sim800.readString()); } while (Serial.available()) { sim800.println(Serial.readString()); } } void Impact() { time1 = micros(); int oldx = xaxis; int oldy = yaxis; int oldz = zaxis; xaxis = analogRead(xPin); yaxis = analogRead(yPin); zaxis = analogRead(zPin); vibration--; if (vibration < 0) vibration = 0; if (vibration > 0) return; deltx = xaxis - oldx; delty = yaxis - oldy; deltz = zaxis - oldz; magnitude = sqrt(sq(deltx) + sq(delty) + sq(deltz)); if (magnitude >= sensitivity) { updateflag = 1; vibration = devibrate; } else { if (magnitude > 15) Serial.println(magnitude); magnitude = 0; } } void parseData(String buff) { Serial.println(buff); unsigned int len, index; index = buff.indexOf("\r"); buff.remove(0, index + 2); buff.trim(); if (buff != "OK") { index = buff.indexOf(":"); String cmd = buff.substring(0, index); cmd.trim(); buff.remove(0, index + 2); if (cmd == "+CMTI") { index = buff.indexOf(","); String temp = buff.substring(index + 1, buff.length()); temp = "AT+CMGR=" + temp + "\r"; sim800.println(temp); } else if (cmd == "+CMGR") { if (buff.indexOf(EMERGENCY_PHONE) > 1) { buff.toLowerCase(); if (buff.indexOf("get gps") > 1) { getGps(); String sms_data; sms_data = "GPS Location Data\r"; sms_data += "http://maps.google.com/maps?q=loc:"; sms_data += latitude + "," + longitude; sendSms(sms_data); } } } } else { } } void getGps() { boolean newData = false; for (unsigned long start = millis(); millis() - start < 2000;) { while (neogps.available()) { if (gps.encode(neogps.read())) { newData = true; break; } } } if (newData) { latitude = String(gps.location.lat(), 6); longitude = String(gps.location.lng(), 6); newData = false; } else { Serial.println("No GPS data is available"); latitude = ""; longitude = ""; } Serial.print("Latitude= "); Serial.println(latitude); Serial.print("Lngitude= "); Serial.println(longitude); } void sendAlert() { String sms_data; sms_data = "Accident Alert!!\r"; sms_data += "http://maps.google.com/maps?q=loc:"; sms_data += latitude + "," + longitude; sendSms(sms_data); } void makeCall() { Serial.println("calling...."); sim800.println("ATD" + EMERGENCY_PHONE + ";"); delay(20000); sim800.println("ATH"); delay(1000); } void sendSms(String text) { //return; sim800.print("AT+CMGF=1\r"); delay(1000); sim800.print("AT+CMGS=\"" + EMERGENCY_PHONE + "\"\r"); delay(1000); sim800.print(text); delay(100); sim800.write(0x1A); delay(1000); Serial.println("SMS Sent Successfully."); } boolean SendAT(String at_command, String expected_answer, unsigned int timeout) { uint8_t x = 0; boolean answer = 0; String response; unsigned long previous; //Clean the input buffer while (sim800.available() > 0) sim800.read(); sim800.println(at_command); x = 0; previous = millis(); do { if (sim800.available() != 0) { response += sim800.read(); x++; if (response.indexOf(expected_answer) > 0) { answer = 1; break; } } } while ((answer == 0) && ((millis() - previous) < timeout)); Serial.println(response); return answer; } |
With 16×2 LCD Display
LiquidCrystal_I2C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
//Prateek //https://justdoelectronics.com //https://www.youtube.com/@JustDoElectronics/videos #include <LiquidCrystal_I2C.h> #include <AltSoftSerial.h> #include <TinyGPS++.h> #include <SoftwareSerial.h> #include <math.h> #include <Wire.h> LiquidCrystal_I2C lcd(0x27, 16, 2); const String EMERGENCY_PHONE = "+9188305848xx"; //GSM Module Conected Pin D2 & D3 #define rxPin 2 #define txPin 3 SoftwareSerial sim800(rxPin, txPin); //GPS Modue Conected Pin D9 & D8 AltSoftSerial neogps; TinyGPSPlus gps; String sms_status, sender_number, received_date, msg; String latitude, longitude; #define BUZZER 12 #define BUTTON 11 #define xPin A0 #define yPin A1 #define zPin A2 byte updateflag; int xaxis = 0, yaxis = 0, zaxis = 0; int deltx = 0, delty = 0, deltz = 0; int vibration = 2, devibrate = 75; int magnitude = 0; int sensitivity = 20; double angle; boolean impact_detected = false; unsigned long time1; unsigned long impact_time; unsigned long alert_delay = 30000; void setup() { Serial.begin(9600); Serial.println("SIM800L serial initialize"); sim800.begin(9600); Serial.println("NEO6M serial initialize"); neogps.begin(9600); pinMode(BUZZER, OUTPUT); pinMode(BUTTON, INPUT_PULLUP); lcd.init(); lcd.backlight(); lcd.clear(); sms_status = ""; sender_number = ""; received_date = ""; msg = ""; sim800.println("AT"); delay(1000); sim800.println("ATE1"); delay(1000); sim800.println("AT+CPIN?"); delay(1000); sim800.println("AT+CMGF=1"); delay(1000); sim800.println("AT+CNMI=1,1,0,0,0"); delay(1000); time1 = micros(); xaxis = analogRead(xPin); yaxis = analogRead(yPin); zaxis = analogRead(zPin); } void loop() { if (micros() - time1 > 1999) Impact(); if (updateflag > 0) { updateflag = 0; Serial.println("Impact detected!!"); Serial.print("Magnitude:"); Serial.println(magnitude); getGps(); digitalWrite(BUZZER, HIGH); impact_detected = true; impact_time = millis(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Crash Detected"); lcd.setCursor(0, 1); lcd.print("Magnitude:" + String(magnitude)); } if (impact_detected == true) { if (millis() - impact_time >= alert_delay) { digitalWrite(BUZZER, LOW); makeCall(); delay(1000); sendAlert(); impact_detected = false; impact_time = 0; } } if (digitalRead(BUTTON) == LOW) { delay(200); digitalWrite(BUZZER, LOW); impact_detected = false; impact_time = 0; } while (sim800.available()) { parseData(sim800.readString()); } while (Serial.available()) { sim800.println(Serial.readString()); } } void Impact() { time1 = micros(); int oldx = xaxis; int oldy = yaxis; int oldz = zaxis; xaxis = analogRead(xPin); yaxis = analogRead(yPin); zaxis = analogRead(zPin); vibration--; if (vibration < 0) vibration = 0; if (vibration > 0) return; deltx = xaxis - oldx; delty = yaxis - oldy; deltz = zaxis - oldz; magnitude = sqrt(sq(deltx) + sq(delty) + sq(deltz)); if (magnitude >= sensitivity) { updateflag = 1; vibration = devibrate; } else { if (magnitude > 15) Serial.println(magnitude); magnitude = 0; } } void parseData(String buff) { Serial.println(buff); unsigned int len, index; index = buff.indexOf("\r"); buff.remove(0, index + 2); buff.trim(); if (buff != "OK") { index = buff.indexOf(":"); String cmd = buff.substring(0, index); cmd.trim(); buff.remove(0, index + 2); if (cmd == "+CMTI") { index = buff.indexOf(","); String temp = buff.substring(index + 1, buff.length()); temp = "AT+CMGR=" + temp + "\r"; sim800.println(temp); } else if (cmd == "+CMGR") { if (buff.indexOf(EMERGENCY_PHONE) > 1) { buff.toLowerCase(); if (buff.indexOf("get gps") > 1) { getGps(); String sms_data; sms_data = "Car Accident Alert at\r"; sms_data += "http://maps.google.com/maps?q=loc:"; sms_data += latitude + "," + longitude; sendSms(sms_data); } } } } else { } } void getGps() { boolean newData = false; for (unsigned long start = millis(); millis() - start < 2000;) { while (neogps.available()) { if (gps.encode(neogps.read())) { newData = true; break; } } } if (newData) { latitude = String(gps.location.lat(), 6); longitude = String(gps.location.lng(), 6); newData = false; } else { Serial.println("No GPS data is available"); latitude = ""; longitude = ""; } Serial.print("Latitude= "); Serial.println(latitude); Serial.print("Lngitude= "); Serial.println(longitude); } void sendAlert() { String sms_data; sms_data = "Emergency Alert at\r"; sms_data += "http://maps.google.com/maps?q=loc:"; sms_data += latitude + "," + longitude; sendSms(sms_data); } void makeCall() { Serial.println("calling...."); sim800.println("ATD" + EMERGENCY_PHONE + ";"); delay(20000); sim800.println("ATH"); delay(1000); } void sendSms(String text) { //return; sim800.print("AT+CMGF=1\r"); delay(1000); sim800.print("AT+CMGS=\"" + EMERGENCY_PHONE + "\"\r"); delay(1000); sim800.print(text); delay(100); sim800.write(0x1A); delay(1000); Serial.println("SMS Sent Successfully."); } boolean SendAT(String at_command, String expected_answer, unsigned int timeout) { uint8_t x = 0; boolean answer = 0; String response; unsigned long previous; //Clean the input buffer while (sim800.available() > 0) sim800.read(); sim800.println(at_command); x = 0; previous = millis(); do { if (sim800.available() != 0) { response += sim800.read(); x++; if (response.indexOf(expected_answer) > 0) { answer = 1; break; } } } while ((answer == 0) && ((millis() - previous) < timeout)); Serial.println(response); return answer; } |
Working Module
Here We Used The ADXL-345 Sensor if any impact is detected and crosses the set threshold value then it sends the proper GPS Location.
- If Any Emergency we press the push button and then also send the SMS “Emergency Alert” And Proper GPS Location.
- If We Click the location Link the Automatic Google MAP Software Is open is track where the Person is Available.
Video
Conclusion
- In this project, we designed the Vehicle Accident Alert System and it works fine But if you try to use another GSM Module then you also use it same case in the GPS Module. if you change it is not required to change the code.
- I hope you Like This project plz share it With your Friends and if you have any doubts then plz comment we try to solve the problem.