This circuit is designed to monitor alcohol levels using an MQ-3 sensor and provide a visual indication via an LCD display and an LED. If the alcohol level exceeds a certain threshold, the system sends a GPS location via SMS using the SIM800L module, activates a buzzer, and locks the engine by disabling a motor. The system is powered by a 3.7V battery and controlled by an Arduino UNO microcontroller. A rocker switch is used to control the power supply to the SIM800L module.
#include <SoftwareSerial.h>
SoftwareSerial sim(8, 9); // RX, TX for SIM800L
#include <TinyGPS++.h> // GPS library
#include <LiquidCrystal.h> // LCD library
// 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 for GPS
TinyGPSPlus gps; // GPS object
// Alcohol sensor reading
int value;
// Motor, buzzer, and LED pins
#define motor 10
#define buzzer 13
#define led 7
// Phone number for SMS
String number = "+919889342918";
void setup() {
pinMode(motor, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
int threshold = 700; // Alcohol threshold value
Serial.begin(9600); // Start serial communication
lcd.begin(16, 2); // Initialize LCD
lcd.setCursor(0, 0);
lcd.print(" Subscribe");
lcd.setCursor(0, 1);
lcd.print(" AEROTECH INDIA");
sim.begin(9600); // Start SIM800L communication
gpsSerial.begin(9600); // Start GPS communication
delay(6000); // Wait for initialization
lcd.clear();
}
void loop() {
value = analogRead(A0); // Read alcohol sensor value
lcd.setCursor(0, 0);
lcd.print("value of alcohol");
lcd.setCursor(0, 1);
lcd.print(value);
delay(100);
digitalWrite(motor, HIGH); // Activate motor
digitalWrite(buzzer, LOW); // Deactivate buzzer
digitalWrite(led, LOW); // Deactivate LED
if (value > threshold) {
SendMessage(); // Send message if over threshold
}
}
void SendMessage() {
digitalWrite(motor, LOW); // Lock engine
digitalWrite(buzzer, HIGH); // Activate buzzer
boolean newData = false;
for (unsigned long start = millis(); millis() - start < 2000;) {
while (gpsSerial.available() > 0) {
if (gps.encode(gpsSerial.read())) {
newData = true; // New GPS data received
}
}
}
if (newData) {
// Send SMS with GPS location
sim.println("AT+CMGF=1");
delay(200);
sim.println("AT+CMGS=\"" + number + "\"\r");
delay(200);
sim.print("http://maps.google.com/maps?q=loc:");
sim.print(gps.location.lat(), 6);
sim.print(",");
sim.print(gps.location.lng(), 6);
delay(100);
sim.println((char)26); // End SMS
delay(200);
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(200);
digitalWrite(buzzer, LOW);
// Flash LED and buzzer in a loop
while (1) {
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
digitalWrite(buzzer, HIGH);
delay(500);
digitalWrite(buzzer, LOW);
lcd.setCursor(0, 0);
lcd.print(" High Alcohol ");
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 is above the threshold, it sends the current GPS location via SMS and enters a loop that indicates a locked engine state.