Tech Gyan Set
Published © MIT

Smart Helmet Safety & Accident Evidence System

A smart helmet that detects wearing, records accident evidence, and instantly alerts family—designed for everyday rider safety.

BeginnerFull instructions provided8 hours37
Smart Helmet Safety & Accident Evidence System

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

1️⃣ Libraries Include + Pin Definition

C/C++
#include <Wire.h>
#include <WiFi.h>
#include <TinyGPSPlus.h>
#include <SPI.h>
#include <SD.h>

// ===== PIN CONFIGURATION =====
#define WEAR_SENSOR_PIN 34
#define BUZZER_PIN 23

#define MPU_SDA 21
#define MPU_SCL 22

#define GPS_RX 16
#define GPS_TX 17

#define GSM_RX 27
#define GSM_TX 26

#define SD_CS 5

🔟 Setup Function

C/C++
void setup() {
  Serial.begin(115200);

  pinMode(WEAR_SENSOR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  Wire.begin(MPU_SDA, MPU_SCL);
  Wire.beginTransmission(0x68);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission();

  GPS_Serial.begin(9600, SERIAL_8N1, GPS_RX, GPS_TX);
  GSM_Serial.begin(9600, SERIAL_8N1, GSM_RX, GSM_TX);

  if (!SD.begin(SD_CS)) {
    Serial.println("❌ SD Card Failed");
  }

  Serial.println("✅ Smart Helmet System Started");
}

1️⃣1️⃣ Main Loop

C/C++
✅ PROJECT WORKING SUMMARY

✔ Helmet wear detection
✔ Accident auto detection
✔ Last 10 sec evidence save
✔ SMS alert to family
✔ GPS location included
✔ Police & insurance ready

📞 Support & Training

Agar:

Code samajh na aaye

GSM / GPS ka issue ho

Ya complete project banana sikhna ho

📲 Contact:
+91 9336183481

👉 Low cost me:

Complete code

Wiring + explanation

End-to-end training
void loop() {
  checkHelmetWear();
  readMPU();
  detectAccident();

  if (accidentDetected && helmetWorn) {
    triggerAlert();
    accidentDetected = false;
  }

  delay(100);
}

2️⃣ Global Variables

C/C++
// MPU6050
float ax, ay, az;
float impactThreshold = 2.5;

// Accident buffer
#define BUFFER_SIZE 100
float accelBuffer[BUFFER_SIZE];
int bufferIndex = 0;

// GPS
TinyGPSPlus gps;

// Serial Ports
HardwareSerial GPS_Serial(1);
HardwareSerial GSM_Serial(2);

// Flags
bool helmetWorn = false;
bool accidentDetected = false;

3️⃣ MPU6050 Read Function (Acceleration)

C/C++
void readMPU() {
  Wire.beginTransmission(0x68);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(0x68, 6, true);

  ax = (Wire.read() << 8 | Wire.read()) / 16384.0;
  ay = (Wire.read() << 8 | Wire.read()) / 16384.0;
  az = (Wire.read() << 8 | Wire.read()) / 16384.0;
}

4️⃣ Helmet Wear Detection Logic

C/C++
void checkHelmetWear() {
  int sensorValue = digitalRead(WEAR_SENSOR_PIN);

  if (sensorValue == HIGH) {
    helmetWorn = true;
  } else {
    helmetWorn = false;
  }

  Serial.print("Helmet Worn: ");
  Serial.println(helmetWorn ? "YES" : "NO");
}

5️⃣ Accident Detection Logic

C/C++
void detectAccident() {
  float totalAcc = sqrt(ax * ax + ay * ay + az * az);

  accelBuffer[bufferIndex++] = totalAcc;
  if (bufferIndex >= BUFFER_SIZE) bufferIndex = 0;

  if (totalAcc > impactThreshold) {
    accidentDetected = true;
    Serial.println("🚨 ACCIDENT DETECTED!");
  }
}

6️⃣ Save Last 10 Seconds Data to SD Card

C/C++
void saveEvidence() {
  File dataFile = SD.open("/accident.txt", FILE_WRITE);

  if (dataFile) {
    dataFile.println("Accident Evidence Data:");
    for (int i = 0; i < BUFFER_SIZE; i++) {
      dataFile.println(accelBuffer[i]);
    }
    dataFile.close();
    Serial.println("✅ Evidence Saved to SD Card");
  } else {
    Serial.println("❌ SD Card Write Failed");
  }
}

7️⃣ Read GPS Location

C/C++
String getGPSLocation() {
  while (GPS_Serial.available()) {
    gps.encode(GPS_Serial.read());
  }

  if (gps.location.isValid()) {
    return String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6);
  }
  return "Location Not Available";
}

8️⃣ Send SMS via GSM Module

C/C++
void sendSMS(String message) {
  GSM_Serial.println("AT+CMGF=1");
  delay(1000);
  GSM_Serial.println("AT+CMGS=\"+919999999999\""); // family number
  delay(1000);
  GSM_Serial.print(message);
  delay(500);
  GSM_Serial.write(26);
}

9️⃣ Alert System (Buzzer + SMS + Evidence)

C/C++
void triggerAlert() {
  digitalWrite(BUZZER_PIN, HIGH);

  String location = getGPSLocation();
  String msg = "Accident Detected!\nLocation: " + location;

  sendSMS(msg);
  saveEvidence();

  delay(5000);
  digitalWrite(BUZZER_PIN, LOW);
}

Credits

Tech Gyan Set
10 projects • 2 followers
Thanks to Tech Gyan Set .

Comments