This circuit is designed to monitor alcohol levels using an MQ-3 alcohol sensor and a GPS module for location tracking. It interfaces with an Arduino UNO microcontroller, which controls a buzzer, an LED, and a SIM800L GSM module to send SMS alerts. The circuit also includes a 16x2 LCD for displaying messages, a motor driver to control DC motors, and a 12V battery for power supply.
#include <SoftwareSerial.h>
SoftwareSerial sim(8,9); // SIM800L GSM Module communication
#include <TinyGPS++.h> // GPS Module
#include <LiquidCrystal.h> // LCD Display
// LCD pin assignments
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// GPS variables
float latitude, longitude;
SoftwareSerial gpsSerial(0,1); // RX, TX
TinyGPSPlus gps;
// Sensor reading
int val;
// Output pin assignments
#define motor 7
#define buzzer 6
#define led 10
// Phone number for SMS
String number = "+918421041408";
int threshold = 700;
void setup() {
pinMode(motor, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
Serial.begin(9600); // Start serial communication
lcd.begin(16,2); // Initialize LCD
lcd.setCursor(0,0);
lcd.print("Mini Project 1");
lcd.setCursor(0,1);
sim.begin(9600); // Start SIM800L communication
gpsSerial.begin(9600); // Start GPS communication
delay(6000);
lcd.clear();
}
void loop() {
val = analogRead(A0); // Read alcohol sensor value
lcd.setCursor(0,0);
lcd.print("Value of Alcohol");
lcd.setCursor(0,1);
lcd.print(val);
delay(100);
digitalWrite(motor, HIGH); // Turn on motor
digitalWrite(buzzer, LOW); // Turn off buzzer
digitalWrite(led, LOW); // Turn off LED
if(val > threshold) {
send_message(); // Send SMS if alcohol level is high
}
}
void send_message() {
digitalWrite(motor, LOW); // Turn off motor
digitalWrite(buzzer, HIGH); // Turn on buzzer
boolean newData = false;
// Attempt to get new GPS data
for(unsigned long start = millis(); millis() - start < 2000;) {
while(gpsSerial.available() > 0) {
if(gps.encode(gpsSerial.read())) {
newData = true;
}
}
}
// If new GPS data is available, send an SMS
if(newData) {
Serial.print("Latitude");
Serial.print(gps.location.lat(), 6);
Serial.print("Longitude");
Serial.print(gps.location.lng(), 6);
newData = false;
delay(300);
sim.println("AT+CMGF=1"); // Set SMS mode
delay(200);
sim.println("AT+CMGS=\"" + number + "\"\r");
delay(200);
sim.print("http://maps.google.com/maps?q=loc:");
sim.print("Latitude");
sim.print(gps.location.lat(), 6);
sim.print("Longitude");
sim.print(gps.location.lng(), 6);
delay(100);
sim.println((char)26); // Send SMS
Serial.println("GPS location SMS sent successfully");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Sending....");
lcd.setCursor(0,1);
lcd.print("Your Location");
delay(5000);
lcd.clear();
delay(100);
digitalWrite(buzzer, LOW);
// Indicate drunk driving and lock engine
while(1) {
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(buzzer, HIGH);
delay(500);
digitalWrite(buzzer, LOW);
lcd.setCursor(0,0);
lcd.print("Driver Drunked");
lcd.setCursor(0,1);
lcd.print("Engine Locked");
}
}
}
This code is responsible for reading the alcohol sensor data, displaying it on the LCD, and controlling the motor, buzzer, and LED based on the sensor's readings. If the alcohol level exceeds the threshold, it sends an SMS with the current GPS coordinates using the SIM800L module.