Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO-Based Alcohol Detection and GPS Tracking System with Wi-Fi Connectivity

Image of Arduino UNO-Based Alcohol Detection and GPS Tracking System with Wi-Fi Connectivity

Circuit Documentation

Summary

This circuit integrates an Arduino UNO microcontroller with various sensors and modules to create a system capable of detecting alcohol levels, obtaining GPS coordinates, and transmitting data via a Wi-Fi module. The system also includes a motor driver to control a DC motor and a buzzer for alerts.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. MQ-3 Breakout

    • Description: Alcohol sensor module.
    • Pins: VCC, GND, DO, AO
  3. GPS NEO 6M

    • Description: GPS module for obtaining location data.
    • Pins: VCC, RX, TX, GND
  4. L298N DC Motor Driver

    • Description: Dual H-Bridge motor driver for controlling DC motors.
    • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
  5. 12V Battery

    • Description: Power source for the motor driver.
    • Pins: -, +
  6. DC Motor

    • Description: Motor to be controlled by the motor driver.
    • Pins: pin 1, pin 2
  7. Buzzer

    • Description: Audio alert component.
    • Pins: PIN, GND
  8. Wi-Fi Module ESP8266-01

    • Description: Wi-Fi module for data transmission.
    • Pins: RX, GPIO0, GPIO2, GND, +3V3, Reset, CH-PD Chip power down, TX

Wiring Details

Arduino UNO

  • 3.3V connected to +3V3 and CH-PD Chip power down of the Wi-Fi module ESP8266-01.
  • 5V connected to VCC of the GPS NEO 6M and VCC of the MQ-3 Breakout.
  • GND connected to GND of the GPS NEO 6M, GND of the MQ-3 Breakout, GND of the L298N DC motor driver, GND of the buzzer, and GND of the Wi-Fi module ESP8266-01.
  • A0 connected to AO of the MQ-3 Breakout.
  • D12 connected to ENA of the L298N DC motor driver.
  • D11 connected to IN2 of the L298N DC motor driver.
  • D10 connected to IN1 of the L298N DC motor driver.
  • D8 connected to PIN of the buzzer.
  • D4 connected to TX of the GPS NEO 6M.
  • D3 connected to RX of the GPS NEO 6M.
  • D1 connected to RX of the Wi-Fi module ESP8266-01.
  • D0 connected to TX of the Wi-Fi module ESP8266-01.

MQ-3 Breakout

  • VCC connected to 5V of the Arduino UNO.
  • GND connected to GND of the Arduino UNO.
  • AO connected to A0 of the Arduino UNO.

GPS NEO 6M

  • VCC connected to 5V of the Arduino UNO.
  • GND connected to GND of the Arduino UNO.
  • TX connected to D4 of the Arduino UNO.
  • RX connected to D3 of the Arduino UNO.

L298N DC Motor Driver

  • GND connected to GND of the Arduino UNO and - of the 12V Battery.
  • ENA connected to D12 of the Arduino UNO.
  • IN2 connected to D11 of the Arduino UNO.
  • IN1 connected to D10 of the Arduino UNO.
  • OUT1 connected to pin 2 of the DC Motor.
  • OUT2 connected to pin 1 of the DC Motor.
  • 5V connected to + of the 12V Battery.

12V Battery

  • - connected to GND of the L298N DC motor driver.
  • + connected to 5V of the L298N DC motor driver.

DC Motor

  • pin 1 connected to OUT2 of the L298N DC motor driver.
  • pin 2 connected to OUT1 of the L298N DC motor driver.

Buzzer

  • PIN connected to D8 of the Arduino UNO.
  • GND connected to GND of the Arduino UNO.

Wi-Fi Module ESP8266-01

  • +3V3 connected to 3.3V of the Arduino UNO.
  • CH-PD Chip power down connected to 3.3V of the Arduino UNO.
  • GND connected to GND of the Arduino UNO.
  • RX connected to D1 of the Arduino UNO.
  • TX connected to D0 of the Arduino UNO.

Documented Code

#include <SoftwareSerial.h>

// Define pins for modules and components
#define MQ3_PIN A0         // MQ-3 sensor analog pin
#define BUZZER_PIN 8       // Buzzer pin
#define IN1 2              // L298N Motor Driver IN1
#define IN2 3              // L298N Motor Driver IN2
#define ENA 9              // L298N Motor Driver ENA
#define WIFI_TX 10         // ESP8266 TX pin
#define WIFI_RX 11         // ESP8266 RX pin
#define GPS_RX 4           // GPS RX pin
#define GPS_TX 5           // GPS TX pin

// Threshold for alcohol detection
#define ALCOHOL_THRESHOLD 300

// SoftwareSerial for Wi-Fi and GPS modules
SoftwareSerial esp8266(WIFI_RX, WIFI_TX);
SoftwareSerial gpsSerial(GPS_RX, GPS_TX);

void setup() {
  // Serial communication for debugging
  Serial.begin(9600);
  esp8266.begin(9600);
  gpsSerial.begin(9600);

  // Setup pins
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(ENA, OUTPUT);

  // Initialize motor and buzzer
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  analogWrite(ENA, 0); // Motor off
  digitalWrite(BUZZER_PIN, LOW);

  Serial.println("System initialized!");
}

void loop() {
  // Alcohol level reading
  int alcoholLevel = analogRead(MQ3_PIN);
  Serial.print("Alcohol Level: ");
  Serial.println(alcoholLevel);

  // Read GPS data
  String gpsData = readGPSData();
  if (gpsData.length() > 0) {
    Serial.println("Raw GPS Data: " + gpsData);
    double latitude, longitude;
    if (parseGPS(gpsData, latitude, longitude)) {
      Serial.print("Latitude: ");
      Serial.println(latitude, 6);
      Serial.print("Longitude: ");
      Serial.println(longitude, 6);

      // Send GPS data via ESP8266
      sendToServer(alcoholLevel, latitude, longitude);
    }
  }

  // Activate buzzer and stop motor if alcohol is detected
  if (alcoholLevel > ALCOHOL_THRESHOLD) {
    Serial.println("Alcohol detected! Stopping motor and activating buzzer.");
    digitalWrite(BUZZER_PIN, HIGH);
    stopMotor();
  } else {
    digitalWrite(BUZZER_PIN, LOW);
    runMotor();
  }

  delay(1000);
}

String readGPSData() {
  String data = "";
  while (gpsSerial.available() > 0) {
    char c = gpsSerial.read();
    if (c == '$') { // Start of NMEA sentence
      data = "";
    }
    data += c;
    if (c == '\n') { // End of NMEA sentence
      if (data.startsWith("$GPRMC")) { // RMC sentence contains position info
        return data;
      }
    }
  }
  return "";
}

bool parseGPS(String gpsData, double &latitude, double &longitude) {
  int commaIndex[12];
  int index = 0;

  // Find all comma positions in the NMEA sentence
  for