Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Mega 2560-Based Smart Vehicle Safety System with GPS and GSM

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560-Based Smart Vehicle Safety System with GPS and GSM

Circuit Documentation

Summary

This document provides a detailed overview of a circuit designed using an Arduino Mega 2560 microcontroller. The circuit integrates various sensors and modules, including a SIM900A GSM module, a Neo 6M GPS module, an HC-SR04 ultrasonic sensor, an SW-420 vibration sensor, a Hall sensor, an MQ-3 alcohol sensor, and a piezo buzzer. The system is designed to monitor alcohol levels, detect vibrations, measure speed, and ensure the use of a helmet or seatbelt. It also includes functionalities for sending SMS alerts and making missed calls in case of emergencies.

Component List

  1. Arduino Mega 2560

    • Description: Microcontroller board based on the ATmega2560.
    • Pins: IOREF, RESET, 3V3, 5V, GND, VIN, A0-A15, D0-D53, PWM, AREF, SDA, SCL.
  2. SIM900A

    • Description: GSM/GPRS module for communication.
    • Pins: GND, DB9-3 (RXD), DB9-2 (TXD), 5V, 3VR, 5VR, 3VT, 5VT, VCC, Ring, RESTART, RESET, STATUS.
  3. Neo 6M GPS Module

    • Description: GPS module for location tracking.
    • Pins: GND, TX, RX, VCC.
  4. Piezo Buzzer

    • Description: Buzzer for audio alerts.
    • Pins: pin 1, pin 2.
  5. HC-SR04 Ultrasonic Sensor

    • Description: Ultrasonic sensor for distance measurement.
    • Pins: VCC, TRIG, ECHO, GND.
  6. SW-420 Vibration Sensor

    • Description: Vibration sensor for detecting vibrations.
    • Pins: vcc, Ground, Digital output.
  7. Hall Sensor (Magnetic)

    • Description: Magnetic sensor for detecting magnetic fields.
    • Pins: VCC (5V), GND, D0 (Digital), A0 (Analog).
  8. MQ-3 Breakout

    • Description: Alcohol sensor for detecting alcohol levels.
    • Pins: VCC, GND, DO, AO.

Wiring Details

Arduino Mega 2560

SIM900A

Neo 6M GPS Module

Piezo Buzzer

HC-SR04 Ultrasonic Sensor

SW-420 Vibration Sensor

Hall Sensor (Magnetic)

MQ-3 Breakout

Code Documentation

#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GPS.h>

// Pin definitions
#define ALCOHOL_SENSOR_PIN A0
#define ULTRASONIC_TRIG_PIN 7
#define ULTRASONIC_ECHO_PIN 8
#define MOTOR_PIN 5
#define SPEED_SENSOR_PIN 10
#define VIBRATION_SENSOR_PIN 9
#define BUZZER_PIN 6
#define BUTTON_PIN 12

// GSM and GPS pins
SoftwareSerial gpsSerial(19, 18);  // RX, TX for GPS
SoftwareSerial gsmSerial(15, 14);  // RX, TX for GSM

Adafruit_GPS GPS(&gpsSerial);

// Variables
bool alcoholDetected = false;
bool helmetSeatbeltDetected = false;
bool engineStarted = false;
bool overSpeed = false;
bool vibrationDetected = false;
int speedLimit = 80;  // Speed limit in km/h

// Function to read alcohol level
bool readAlcoholSensor() {
  int sensorValue = analogRead(ALCOHOL_SENSOR_PIN);
  if (sensorValue > 200) {  // Adjust threshold based on calibration
    return true;  // Alcohol detected
  }
  return false;  // No alcohol detected
}

// Function to check seatbelt/helmet (ultrasonic distance)
bool checkHelmetSeatbelt() {
  long duration, distance;
  digitalWrite(ULTRASONIC_TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(ULTRASONIC_TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(ULTRASONIC_TRIG_PIN, LOW);
  duration = pulseIn(ULTRASONIC_ECHO_PIN, HIGH);
  distance = duration * 0.0344 / 2;  // Calculate distance in cm
  
  if (distance < 30) {  // If hand is close to the sensor, assume helmet/seatbelt is on
    return true;
  }
  return false;
}

// Function to read speed sensor
int readSpeedSensor() {
  static unsigned long lastTime = 0;
  static int pulseCount = 0;
  unsigned long currentTime = millis();
  if (digitalRead(SPEED_SENSOR_PIN) == HIGH) {
    pulseCount++;
  }
  
  if (currentTime - lastTime > 1000) {  // Update speed every second
    lastTime = currentTime;
    int speed = pulseCount * 60 / 2;  // Adjust according to the sensor setup
    pulseCount = 0;
    return speed;
  }
  return 0;
}

// Function to send SMS
void sendSMS(String message) {
  gsmSerial.println("AT+CMGF=1");  // Set SMS mode
  delay(100);
  gsmSerial.println("AT+CMGS=\"+919641646315\"");  // Send SMS to the specified number
  delay(100);
  gsmSerial.println(message);  // Send message
  delay(100);
  gsmSerial.write(26);