# Smart Roads for Autonomous Accident Detection and Warnings
## Appendix B Code of the AALS System for One Node  
//This code is built for \"Autonomous Accident Detection & Alert for Non-equipped Vehicles\"  
// This code is the property of [PERSON], MSCS FUUAST ISB. // Library added for code simplification  
#include <SoftwareSerial.h> // For serial communication though digital pins  
#include <LCD_I2C_h>  
LCD_I2C lcd(0x27): // Default address  
SoftwareSerial HC12(2, 5); // HC-12 TX Pin, HC-12 RX Pin  
// Variable Declarations  
// Pin mapping  
const int lightPin = 13; // used for alert by blinking light  
const int sinrenPin = 12; // used for alert by siren sound  
const int resetPin = 11; // used for reset with pushbutton  
const int softresetPin = 10; // software-based reset  
const int irSensor = A0; // used for IR sensor input  
const int micSensor = A1; // used for mic sensor inputconst int smokeSensor = A2; // used for smoke sensor input  
//PRE- Location Save  
const String GPSLatitude = \"32.783280\";  
const String GPSLongitude = \"72.703564\";  
const String mylocation = \"Lat32.783280, Long:72.703564; Kallar Kahar, Chakwal, Punjab, Pakistan, N2S\";  
// Sensor threshold settings  
const int irThreshold = 100;// less than this threshold detects obstacle  
const int micThreshold = 540; // greater than this threshold detects accident  
const int smokeThreshold = 240; // greater than this value indicates fire  
const int timeElapsedThreshold = 5000; // 5 s is for a long vehicle passing by  
// Variables for storage input data  
int irSensorValue = 0;  
int micSensorValue = 0;  
int smokeSensorValue = 0;  
int resetPinValue = 0;  
int timeElapse = 0;  
int accidentSound = 0;  
int fireDetected = 0;  
void setup () {  
// run once:  
**Serial. **begin(9600); // serial baud rate is set to 9600  
HC12.begin(9600); // Serial port to HC12  
// gps.begin(9600); // Serial port to GPS  
lcd.begin(); // If using more I2C devices using the wire library use lcd.begin(false)  
lcd.backlight();  
pinMode (lightPin, OUTPUT); // Declare lightPin as output pin  
pinMode (sirePin, OUTPUT); // Declare sirenPin as output pin  
pinMode (resetPin, INPUT); // Declare sirenPin as input pin  
pinMode (irSensor, INPUT); // Declare irSensor as input pin  
pinMode (micsensor, INPUT); // Declare micSensor as input pin  
pinMode (smokeSensor, INPUT); // Declare smokeSensor as input pin  
pinMode (softresetPin, OUTPUT); // Connect this pin to reset of Arduino Uno board  
digitalWrite (softresetPin, HIGH); // Make it high because reset is low  
void loop() {  
// runs repeatedly:  
// get values from input pins  
irSensorValue = analogRead (irSensor);  
micSensorValue = analogRead (micSensor);  
smokeSensorValue = analogRead (smokeSensor);  
resetPinValue = digitalRead (resetPin);  
// Check if hardreset button is pushed  
if (resetPinValue == 1) {  
HC12.write(\"Reset\");  
**Serial. **println(\"HardReset\");  
digitalWrite (softresetPin, LOW);  
// serial print the values of sensors  
**Serial. **print(\"IR Sensor has value = \");  
**Serial. **printIn(irSensorValue);  
**Serial. **print(\"mic Sensor has value = \");  
**Serial. **printIn(micSensorValue);  
**Serial.