Arduino UNO-Based Alcohol Detection and GPS Tracking System with GSM Alert
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to detect alcohol levels using an MQ-3 sensor and take appropriate actions such as stopping a motor, alerting the driver with a buzzer and LED, and sending the GPS location via a GSM module. The circuit is controlled by an Arduino UNO microcontroller.
Component List
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
MQ-3 Breakout
- Description: Alcohol sensor module.
- Pins: VCC, GND, DO, AO
Sim800l
- Description: GSM module for sending SMS.
- Pins: NET, RST, VCC, RXD, TXD, GND
Resistor (10 Ohms)
- Description: Resistor with 10 Ohms resistance.
- Pins: pin1, pin2
Resistor (20 Ohms)
- Description: Resistor with 20 Ohms resistance.
- Pins: pin1, pin2
GPS NEO 6M
- Description: GPS module for location tracking.
- Pins: VCC, RX, TX, GND
L298N DC Motor Driver
- Description: Dual H-Bridge motor driver.
- 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
12V Battery
- Description: Power source for the circuit.
- Pins: -, +
DC Motor
- Description: Motor controlled by the L298N driver.
- Pins: pin 1, pin 2
Buzzer
- Description: Audio alert device.
- Pins: PIN, GND
LED: Two Pin (yellow)
- Description: Visual alert device.
- Pins: cathode, anode
Wiring Details
Arduino UNO
- 5V connected to VCC of MQ-3 Breakout and GPS NEO 6M.
- GND connected to GND of MQ-3 Breakout, GPS NEO 6M, Sim800l, buzzer, and L298N DC motor driver.
- A0 connected to AO of MQ-3 Breakout.
- D12 connected to ENA of L298N DC motor driver.
- D11 connected to IN2 of L298N DC motor driver.
- D10 connected to IN1 of L298N DC motor driver.
- D8 connected to PIN of buzzer through a 20 Ohms resistor.
- D7 connected to TXD of Sim800l.
- D4 connected to TX of GPS NEO 6M.
- D3 connected to RX of GPS NEO 6M.
MQ-3 Breakout
- VCC connected to 5V of Arduino UNO.
- GND connected to GND of Arduino UNO.
- AO connected to A0 of Arduino UNO.
Sim800l
- GND connected to GND of Arduino UNO.
- TXD connected to D7 of Arduino UNO.
- RXD connected to pin2 of a 10 Ohms resistor.
Resistor (10 Ohms)
- pin1 connected to D8 of Arduino UNO.
- pin2 connected to RXD of Sim800l.
Resistor (20 Ohms)
- pin1 connected to PIN of buzzer.
- pin2 connected to GND of Arduino UNO.
GPS NEO 6M
- VCC connected to 5V of Arduino UNO.
- GND connected to GND of Arduino UNO.
- TX connected to D4 of Arduino UNO.
- RX connected to D3 of Arduino UNO.
L298N DC Motor Driver
- GND connected to GND of Arduino UNO and 12V Battery.
- 5V connected to + of 12V Battery.
- ENA connected to D12 of Arduino UNO.
- IN2 connected to D11 of Arduino UNO.
- IN1 connected to D10 of Arduino UNO.
- OUT1 connected to pin 2 of DC Motor.
- OUT2 connected to pin 1 of DC Motor.
12V Battery
- - connected to GND of L298N DC motor driver.
- + connected to 5V of L298N DC motor driver.
DC Motor
- pin 2 connected to OUT1 of L298N DC motor driver.
- pin 1 connected to OUT2 of L298N DC motor driver.
Buzzer
- PIN connected to D8 of Arduino UNO through a 20 Ohms resistor.
- GND connected to GND of Arduino UNO.
LED: Two Pin (yellow)
- cathode connected to GND.
- anode connected to D9 of Arduino UNO.
Documented Code
#include <SoftwareSerial.h> // Include for GSM communication
#include <Wire.h> // Include for I2C communication (if needed)
// Define hardware pins
#define ALCOHOL_PIN A0 // Analog pin for alcohol sensor
#define BUZZER_PIN 8 // Digital pin for buzzer
#define LED_PIN 9 // Digital pin for LED
#define MOTOR_IN1_PIN 10 // Digital pin for motor driver IN1
#define MOTOR_IN2_PIN 11 // Digital pin for motor driver IN2
#define MOTOR_ENA_PIN 12 // Digital pin for motor driver ENA
// SoftwareSerial for GSM module
SoftwareSerial gsmSerial(7, 6); // RX, TX for GSM module
// Function prototypes
void stopMotor();
void alertDriver();
void sendLocation();
void sendSMS(const char* text);
bool getGPSLocation(double* latitude, double* longitude);
// Setup function
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging
gsmSerial.begin(9600); // Initialize GSM communication
// Configure pin modes
pinMode(ALCOHOL_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(MOTOR_IN1_PIN, OUTPUT);
pinMode(MOTOR_IN2_PIN, OUTPUT);
pinMode(MOTOR_ENA_PIN, OUTPUT);
digitalWrite(MOTOR_ENA_PIN, HIGH); // Enable motor
// Send initialization message
sendSMS("System initialized and ready.");
}
// Main loop
void loop() {
// Alcohol detection
int alcoholValue = analogRead(ALCOHOL_PIN);
// Alcohol detection threshold
if (alcoholValue > 400) {
Serial.println("Alcohol detected!");
stopMotor();
alertDriver();
sendLocation(); // Send GPS location via SMS
}
// Simulate GPS data (mock, replace with actual GPS logic)
double latitude = 12.345678;
double longitude = 98.765432;
Serial.print("Latitude: ");
Serial.println(latitude, 6);
Serial.print("Longitude: ");
Serial.println(longitude, 6);
delay(1000);
}
// Stop the motor
void stopMotor() {
digitalWrite(MOTOR_IN1_PIN, LOW);
digitalWrite(MOTOR_IN2_PIN, LOW);
}
// Alert the driver
void alertDriver() {
digitalWrite(BUZZER_PIN, HIGH);
digitalWrite(LED_PIN, HIGH);
delay(2000); // Sound the alarm for 2 seconds
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(LED_PIN, LOW);
}
// Send location via SMS
void sendLocation() {
double latitude = 12.345678; // Replace with actual GPS data
double longitude = 98.765432;
char message[100];
snprintf(message, sizeof(message), "Emergency! Alcohol detected. Location: Lat: %.6f, Lon: %.6f", latitude, longitude);
sendSMS(message);
}
// Send an SMS message
void sendSMS(const char* text) {
gsmSerial.println