Accident Prevention, Identification and Alert System
To prevent the accident in advance and if accident occurs then there will be a prevention system to notify emergency services before time.
Components and supplies
2
5 mm LED: Red
2
Buzzer, Piezo
1
Gboard Pro 800 SIM800 GSM / GPRS Module 3.3v ATmega2560 Mainboard For Arduino Starter
2
Breadboard (generic)
1
Dual H-Bridge motor drivers L293D
1
Analog Accelerometer: ADXL335
2
9V battery (generic)
4
DC Motor, 12 V
2
Arduino UNO
1
Alphanumeric LCD, 16 x 2
2
Ultrasonic Sensor - HC-SR04 (Generic)
Tools and machines
1
Soldering iron (generic)
1
Mastech MS8217 Autorange Digital Multimeter
Apps and platforms
1
Arduino IDE
Project description
Code
Accident Detection
c_cpp
1////Collision Warning System//// 2 3const int trigPin = 7; 4 5const int echoPin = 8; 6 7int buzz = 10; 8int led = 13; 9 10long duration; 11 12int distance; 13 14// the setup function runs once when you press reset or power the board 15 16//********wheels************ 17const int leftForward = 2; 18const int leftBackward = 3; 19const int rightForward = 4; 20const int rightBackward = 5; 21//*************************** 22 23void setup() { 24 25// initialize digital pin 13 as an output. 26 27pinMode(trigPin, OUTPUT); 28 29pinMode(echoPin, INPUT); 30 31pinMode(13, OUTPUT); //led 32 33pinMode(10, OUTPUT); //buzzer 34 35Serial.begin(9600); 36 37//************wheels************ 38 pinMode(leftForward , OUTPUT); 39 pinMode(leftBackward , OUTPUT); 40 pinMode(rightForward , OUTPUT); 41 pinMode(rightBackward , OUTPUT); 42 // ******************************** 43} 44 45// the loop function runs over and over again forever 46 47void loop() 48 49{ 50 51 //************//wheels*********** 52 digitalWrite(leftForward , HIGH); 53 digitalWrite(leftBackward , LOW); 54 digitalWrite(rightForward , HIGH); 55 digitalWrite(rightBackward , LOW); 56 //****************************** 57 58 59 60// Clears the trigPin 61 62digitalWrite(trigPin, LOW); 63 64delayMicroseconds(2); 65 66// Sets the trigPin on HIGH state for 10 micro seconds 67 68digitalWrite(trigPin, HIGH); 69 70delayMicroseconds(10); 71 72digitalWrite(trigPin, LOW); 73 74// Reads the echoPin, returns the sound wave travel time in microseconds 75 76duration = pulseIn(echoPin, HIGH); 77 78// Calculating the distance 79 80distance= duration*0.034/2; 81 82// Prints the distance on the Serial Monitor 83 84if(distance <= 50 && distance >= 20) 85 86{ 87 88digitalWrite(13, HIGH); 89 90 91 92// turn the LED on (HIGH is the voltage level) 93 94} 95 96else 97 98{ 99 100digitalWrite(13, LOW); // turn the LED off by making the voltage LOW 101 102// wait for a second 103 104} 105 106if(distance <= 20) 107 108{digitalWrite(13,HIGH); 109 110 111 digitalWrite(leftForward , LOW); 112 digitalWrite(leftBackward , LOW); 113 digitalWrite(rightForward , LOW); 114 digitalWrite(rightBackward , LOW); 115 116 117 118digitalWrite(10, HIGH); 119 120tone(buzz, 2000); 121 122delay(100); 123 124noTone(buzz); 125 126delay(100); 127 128tone(buzz, 2000); 129 130delay(100); 131 132noTone(buzz); 133 134delay(100); 135 136tone(buzz, 2000); 137 138delay(100); 139 140noTone(buzz); 141 142tone(buzz, 2000); 143 144delay(100); 145 146noTone(buzz); 147 148delay(100); 149 150} 151 152else 153 154{ 155 156digitalWrite(13, LOW); // turn the LED off by making the voltage LOW 157 158// wait for a second 159 160} 161 162} 163 164
Accident Prevention
c_cpp
1#include<LiquidCrystal.h> 2LiquidCrystal lcd(8,9,10,11,12,13); 3#include<SoftwareSerial.h> 4SoftwareSerial GSM(2,3); 5 6int led=6; 7int buzz=4; 8 9unsigned int MEMSX; 10unsigned int MEMSY; 11void initModule(String cmd,char *res,int t) 12{ 13 while(1) 14 { 15 Serial.println(cmd); 16 delay(100); 17 while(Serial.available()>0) 18 { 19 if(Serial.find(res)) 20 { 21 Serial.println(res); 22 delay(t); 23 return; 24 } 25 else 26 27 { 28 Serial.println("error"); 29 } 30 } 31 delay(t); 32 33 } 34} 35void send() 36{ 37 38 Serial.begin(9600); 39 GSM.begin(9600); 40 GSM.println("AT+CMGF=1"); 41 delay(1000); 42 GSM.println("AT+CMGS=\\"+919079800458\\"\ "); 43 delay(1000); 44 GSM.println("help accident happened"); 45 delay(100); 46 GSM.println((char)26); 47 delay(1000); 48} 49 50void setup() { 51 // put your setup code here, to run once: 52 53 54 //************** 55 String cmd; 56 char *res; 57 int t; 58 //************ 59 60 61lcd.begin(16,2); 62Serial.begin(9600); 63 64pinMode(buzz,OUTPUT); 65pinMode(led,OUTPUT); 66 67lcd.begin(16,2); 68lcd.setCursor(0,0); 69lcd.print("vehicle accident"); 70lcd.setCursor(0,1); 71lcd.print("DETECTION USING"); 72delay(5000); 73lcd.clear(); 74lcd.setCursor(0,0); 75lcd.print("MEMS,GSM"); 76lcd.setCursor(0,1); 77lcd.print("AND ARDUINO UNO"); 78delay(5000); 79lcd.clear(); 80lcd.print("initializing"); 81lcd.setCursor(0,1); 82lcd.print("GSM MODEM"); 83delay(1000); 84 85 86/*initModule("AT","OK",1000); 87initModule("ATE1","OK",1000); 88initModule("AT+CPIN?","READY",1000); 89initModule("AT+CMGF=1","OK",1000); 90initModule("AT+CNMI=2,2,0,0,0","OK",1000);*/ 91 92 93lcd.clear(); 94lcd.print("initialized"); 95lcd.setCursor(0,1); 96lcd.print("Successfully"); 97delay(2000); 98lcd.clear(); 99} 100 101void loop() { 102 // put your main code here, to run repeatedly: 103st: 104lcd.clear(); 105MEMSX=analogRead(0);MEMSX=MEMSX/2; 106lcd.setCursor(0,0);lcd.print("X:");lcd.setCursor(3,0);lcd.print(MEMSX);delay(1000); 107MEMSY = analogRead(1); 108MEMSY =MEMSY/2; 109lcd.setCursor(0,1);lcd.print("Y:");lcd.setCursor(3,1);lcd.print(MEMSY);delay(1000); 110if((MEMSX >= 160 ) & (MEMSX <= 175) & ((MEMSY >=160) &(MEMSY<=175))) 111{ 112 lcd.setCursor(8,0); 113 lcd.print("NORMAL"); 114 delay(500); 115 digitalWrite(buzz,LOW); 116 digitalWrite(led,LOW); 117} 118if(((MEMSX >=130) & (MEMSX<=150)) & ((MEMSY>=160) & (MEMSY<=175))) 119 120{ 121 122 lcd.setCursor(8,0);lcd.print("RIGHT ");lcd.setCursor(8,1);lcd.print("ACCIDENT "); 123 digitalWrite(buzz,HIGH);digitalWrite(led,HIGH);delay(2000); 124 lcd.clear();lcd.setCursor(6,0);lcd.print("PRESS RST");lcd.setCursor(6,1);lcd.print("SWITCH"); 125 delay(5000);delay(5000); 126 lcd.clear();lcd.setCursor(8,0);lcd.print("RIGHT ");lcd.setCursor(8,1);lcd.print("ACCIDENT"); 127 delay(2000);lcd.clear();lcd.print("Sending SMS");delay(2000); 128 129 send();delay(2000);goto st; 130 131} 132if(((MEMSX>=185)&(MEMSX<=200))&((MEMSY>=160)&(MEMSY<=175))) 133{ 134 lcd.setCursor(8,0);lcd.print("LEFT"); 135 lcd.setCursor(8,1); 136 lcd.print("ACCIDENT"); 137 digitalWrite(buzz,HIGH);digitalWrite(led,HIGH);delay(2000); 138 lcd.clear();lcd.setCursor(6,0);lcd.print("PRESS RST");lcd.setCursor(6,1);lcd.print("SWITCH"); 139 delay(5000);delay(5000); 140 lcd.clear();lcd.setCursor(8,0);lcd.print("left");lcd.setCursor(8,1);lcd.print("accident"); 141 delay(2000);lcd.clear();lcd.print("SENDING SMS"); 142 delay(2000);send();delay(2000);goto st; 143} 144if(((MEMSX>=160)&(MEMSX<=175))&((MEMSY>=130)&(MEMSY<=150))) 145 146{ 147 lcd.setCursor(8,0);lcd.print("FRONT");lcd.setCursor(8,1);lcd.print("ACCIDENT"); 148 digitalWrite(buzz,HIGH);digitalWrite(led,HIGH);delay(2000); 149 lcd.clear();lcd.setCursor(6,0);lcd.print("PRESS RST");lcd.setCursor(6,1);lcd.print("SWITCH"); 150 delay(5000);delay(5000); 151 lcd.clear();lcd.setCursor(8,0);lcd.print("FRONT");lcd.setCursor(8,1);lcd.print("ACCIDENT"); 152 delay(2000);lcd.clear();lcd.print("sending SMS");delay(2000);send();delay(2000);goto st; 153} 154 155if(((MEMSX>=160)&(MEMSX<=175))&((MEMSY>=180)&(MEMSY<=195))) 156{ 157 lcd.setCursor(8,0);lcd.print("BACK");lcd.setCursor(8,1);lcd.print("ACCIDENT"); 158 digitalWrite(buzz,HIGH);digitalWrite(led,HIGH);delay(2000); 159 lcd.clear();lcd.setCursor(6,0);lcd.print("PRESS RST");lcd.setCursor(6,1);lcd.print("SWITCH"); 160 delay(5000);delay(5000); 161 lcd.clear();lcd.setCursor(8,0);lcd.print("BACK");lcd.setCursor(8,1);lcd.print("ACCIDENT"); 162 delay(2000);lcd.clear();lcd.print("SENDING SMS");delay(2000);send();delay(2000);goto st; 163} 164} 165 166 167
Accident Detection
c_cpp
1////Collision Warning System//// 2 3const int trigPin = 7; 4 5const int echoPin = 8; 6 7int buzz = 10; 8int led = 13; 9 10long duration; 11 12int distance; 13 14// the setup function runs once when you press reset or power the board 15 16//********wheels************ 17const int leftForward = 2; 18const int leftBackward = 3; 19const int rightForward = 4; 20const int rightBackward = 5; 21//*************************** 22 23void setup() { 24 25// initialize digital pin 13 as an output. 26 27pinMode(trigPin, OUTPUT); 28 29pinMode(echoPin, INPUT); 30 31pinMode(13, OUTPUT); //led 32 33pinMode(10, OUTPUT); //buzzer 34 35Serial.begin(9600); 36 37//************wheels************ 38 pinMode(leftForward , OUTPUT); 39 pinMode(leftBackward , OUTPUT); 40 pinMode(rightForward , OUTPUT); 41 pinMode(rightBackward , OUTPUT); 42 // ******************************** 43} 44 45// the loop function runs over and over again forever 46 47void loop() 48 49{ 50 51 //************//wheels*********** 52 digitalWrite(leftForward , HIGH); 53 digitalWrite(leftBackward , LOW); 54 digitalWrite(rightForward , HIGH); 55 digitalWrite(rightBackward , LOW); 56 //****************************** 57 58 59 60// Clears the trigPin 61 62digitalWrite(trigPin, LOW); 63 64delayMicroseconds(2); 65 66// Sets the trigPin on HIGH state for 10 micro seconds 67 68digitalWrite(trigPin, HIGH); 69 70delayMicroseconds(10); 71 72digitalWrite(trigPin, LOW); 73 74// Reads the echoPin, returns the sound wave travel time in microseconds 75 76duration = pulseIn(echoPin, HIGH); 77 78// Calculating the distance 79 80distance= duration*0.034/2; 81 82// Prints the distance on the Serial Monitor 83 84if(distance <= 50 && distance >= 20) 85 86{ 87 88digitalWrite(13, HIGH); 89 90 91 92// turn the LED on (HIGH is the voltage level) 93 94} 95 96else 97 98{ 99 100digitalWrite(13, LOW); // turn the LED off by making the voltage LOW 101 102// wait for a second 103 104} 105 106if(distance <= 20) 107 108{digitalWrite(13,HIGH); 109 110 111 digitalWrite(leftForward , LOW); 112 digitalWrite(leftBackward , LOW); 113 digitalWrite(rightForward , LOW); 114 digitalWrite(rightBackward , LOW); 115 116 117 118digitalWrite(10, HIGH); 119 120tone(buzz, 2000); 121 122delay(100); 123 124noTone(buzz); 125 126delay(100); 127 128tone(buzz, 2000); 129 130delay(100); 131 132noTone(buzz); 133 134delay(100); 135 136tone(buzz, 2000); 137 138delay(100); 139 140noTone(buzz); 141 142tone(buzz, 2000); 143 144delay(100); 145 146noTone(buzz); 147 148delay(100); 149 150} 151 152else 153 154{ 155 156digitalWrite(13, LOW); // turn the LED off by making the voltage LOW 157 158// wait for a second 159 160} 161 162} 163 164
Accident Prevention
c_cpp
1#include<LiquidCrystal.h> 2LiquidCrystal lcd(8,9,10,11,12,13); 3#include<SoftwareSerial.h> 4SoftwareSerial 5 GSM(2,3); 6 7int led=6; 8int buzz=4; 9 10unsigned int MEMSX; 11unsigned 12 int MEMSY; 13void initModule(String cmd,char *res,int t) 14{ 15 while(1) 16 17 { 18 Serial.println(cmd); 19 delay(100); 20 while(Serial.available()>0) 21 22 { 23 if(Serial.find(res)) 24 { 25 Serial.println(res); 26 27 delay(t); 28 return; 29 } 30 else 31 32 { 33 34 Serial.println("error"); 35 } 36 } 37 delay(t); 38 39 40 } 41} 42void send() 43{ 44 45 Serial.begin(9600); 46 GSM.begin(9600); 47 48 GSM.println("AT+CMGF=1"); 49 delay(1000); 50 GSM.println("AT+CMGS=\\"+919079800458\\"\ "); 51 52 delay(1000); 53 GSM.println("help accident happened"); 54 delay(100); 55 56 GSM.println((char)26); 57 delay(1000); 58} 59 60void setup() { 61 // put 62 your setup code here, to run once: 63 64 65 //************** 66 String cmd; 67 68 char *res; 69 int t; 70 //************ 71 72 73lcd.begin(16,2); 74Serial.begin(9600); 75 76pinMode(buzz,OUTPUT); 77pinMode(led,OUTPUT); 78 79lcd.begin(16,2); 80lcd.setCursor(0,0); 81lcd.print("vehicle 82 accident"); 83lcd.setCursor(0,1); 84lcd.print("DETECTION USING"); 85delay(5000); 86lcd.clear(); 87lcd.setCursor(0,0); 88lcd.print("MEMS,GSM"); 89lcd.setCursor(0,1); 90lcd.print("AND 91 ARDUINO UNO"); 92delay(5000); 93lcd.clear(); 94lcd.print("initializing"); 95lcd.setCursor(0,1); 96lcd.print("GSM 97 MODEM"); 98delay(1000); 99 100 101/*initModule("AT","OK",1000); 102initModule("ATE1","OK",1000); 103initModule("AT+CPIN?","READY",1000); 104initModule("AT+CMGF=1","OK",1000); 105initModule("AT+CNMI=2,2,0,0,0","OK",1000);*/ 106 107 108lcd.clear(); 109lcd.print("initialized"); 110lcd.setCursor(0,1); 111lcd.print("Successfully"); 112delay(2000); 113lcd.clear(); 114} 115 116void 117 loop() { 118 // put your main code here, to run repeatedly: 119st: 120lcd.clear(); 121MEMSX=analogRead(0);MEMSX=MEMSX/2; 122lcd.setCursor(0,0);lcd.print("X:");lcd.setCursor(3,0);lcd.print(MEMSX);delay(1000); 123MEMSY 124 = analogRead(1); 125MEMSY =MEMSY/2; 126lcd.setCursor(0,1);lcd.print("Y:");lcd.setCursor(3,1);lcd.print(MEMSY);delay(1000); 127if((MEMSX 128 >= 160 ) & (MEMSX <= 175) & ((MEMSY >=160) &(MEMSY<=175))) 129{ 130 lcd.setCursor(8,0); 131 132 lcd.print("NORMAL"); 133 delay(500); 134 digitalWrite(buzz,LOW); 135 digitalWrite(led,LOW); 136} 137if(((MEMSX 138 >=130) & (MEMSX<=150)) & ((MEMSY>=160) & (MEMSY<=175))) 139 140{ 141 142 lcd.setCursor(8,0);lcd.print("RIGHT 143 ");lcd.setCursor(8,1);lcd.print("ACCIDENT "); 144 digitalWrite(buzz,HIGH);digitalWrite(led,HIGH);delay(2000); 145 146 lcd.clear();lcd.setCursor(6,0);lcd.print("PRESS RST");lcd.setCursor(6,1);lcd.print("SWITCH"); 147 148 delay(5000);delay(5000); 149 lcd.clear();lcd.setCursor(8,0);lcd.print("RIGHT 150 ");lcd.setCursor(8,1);lcd.print("ACCIDENT"); 151 delay(2000);lcd.clear();lcd.print("Sending 152 SMS");delay(2000); 153 154 send();delay(2000);goto st; 155 156} 157if(((MEMSX>=185)&(MEMSX<=200))&((MEMSY>=160)&(MEMSY<=175))) 158{ 159 160 lcd.setCursor(8,0);lcd.print("LEFT"); 161 lcd.setCursor(8,1); 162 lcd.print("ACCIDENT"); 163 164 digitalWrite(buzz,HIGH);digitalWrite(led,HIGH);delay(2000); 165 lcd.clear();lcd.setCursor(6,0);lcd.print("PRESS 166 RST");lcd.setCursor(6,1);lcd.print("SWITCH"); 167 delay(5000);delay(5000); 168 169 lcd.clear();lcd.setCursor(8,0);lcd.print("left");lcd.setCursor(8,1);lcd.print("accident"); 170 171 delay(2000);lcd.clear();lcd.print("SENDING SMS"); 172 delay(2000);send();delay(2000);goto 173 st; 174} 175if(((MEMSX>=160)&(MEMSX<=175))&((MEMSY>=130)&(MEMSY<=150))) 176 177{ 178 179 lcd.setCursor(8,0);lcd.print("FRONT");lcd.setCursor(8,1);lcd.print("ACCIDENT"); 180 181 digitalWrite(buzz,HIGH);digitalWrite(led,HIGH);delay(2000); 182 lcd.clear();lcd.setCursor(6,0);lcd.print("PRESS 183 RST");lcd.setCursor(6,1);lcd.print("SWITCH"); 184 delay(5000);delay(5000); 185 186 lcd.clear();lcd.setCursor(8,0);lcd.print("FRONT");lcd.setCursor(8,1);lcd.print("ACCIDENT"); 187 188 delay(2000);lcd.clear();lcd.print("sending SMS");delay(2000);send();delay(2000);goto 189 st; 190} 191 192if(((MEMSX>=160)&(MEMSX<=175))&((MEMSY>=180)&(MEMSY<=195))) 193{ 194 195 lcd.setCursor(8,0);lcd.print("BACK");lcd.setCursor(8,1);lcd.print("ACCIDENT"); 196 197 digitalWrite(buzz,HIGH);digitalWrite(led,HIGH);delay(2000); 198 lcd.clear();lcd.setCursor(6,0);lcd.print("PRESS 199 RST");lcd.setCursor(6,1);lcd.print("SWITCH"); 200 delay(5000);delay(5000); 201 202 lcd.clear();lcd.setCursor(8,0);lcd.print("BACK");lcd.setCursor(8,1);lcd.print("ACCIDENT"); 203 204 delay(2000);lcd.clear();lcd.print("SENDING SMS");delay(2000);send();delay(2000);goto 205 st; 206} 207} 208 209 210
Downloadable files
Accident Prevention
Accident Prevention

Accident Prevention
Accident Prevention

Accident Detection
Accident Detection

Comments
Only logged in users can leave comments