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.
Arduino UNO
MQ-3 Breakout
GPS NEO 6M
L298N DC Motor Driver
12V Battery
DC Motor
Buzzer
Wi-Fi Module ESP8266-01
#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