#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
// Define the RX and TX pins for the GPS module
#define GPS_RX 10
#define GPS_TX 11
// Define the RX and TX pins for the GSM module
#define GSM_RX 8
#define GSM_TX 9
// Define the analog pin for the potentiometer
#define POTENTIOMETER_PIN A0
// Define the pin for the alert LED
#define ALERT_LED_PIN 13
// Define LCD parameters
#define LCD_RS 12
#define LCD_EN 3
#define LCD_D4 4
#define LCD_D5 5
#define LCD_D6 6
#define LCD_D7 2
#define LCD_COLS 16
#define LCD_ROWS 2
SoftwareSerial gpsSerial(GPS_RX, GPS_TX);
SoftwareSerial gsmSerial(GSM_RX, GSM_TX);
LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
void setup() {
Serial.begin(9600);
gpsSerial.begin(9600);
gsmSerial.begin(9600);
lcd.begin(LCD_COLS, LCD_ROWS);
lcd.clear();
lcd.print("Alcohol Alert");
delay(1500);
lcd.setCursor(0, 1);
lcd.print("Not Detected");
delay(1500);
pinMode(ALERT_LED_PIN, OUTPUT);
}
void loop() {
// Read potentiometer value
//int threshold = map(analogRead(POTENTIOMETER_PIN), 0, 1023, 0, 1023);
int threshold = 512;
// Check if potentiometer value exceeds the threshold
if (analogRead(POTENTIOMETER_PIN) > threshold) {
sendAlert();
displayAlertOnLCD("Alcohol Detected!");
delay(1500);
digitalWrite(ALERT_LED_PIN, LOW);
delay(1000);
} else {
displayAlertOnLCD("Not Detected");
delay(1500);
digitalWrite(ALERT_LED_PIN, HIGH);
delay(1000);
}
// Handle GPS and GSM functionalities (simulated for Wokwi)
handleGPS();
handleGSM();
}
void sendAlert() {
gsmSerial.println("AT+CMGF=1"); // Set SMS mode to text
delay(1000);
displayAlertOnLCD("Sending Message");
delay(1000);
displayAlertOnLCD("Mob: 9427961822");
delay(1000);
gsmSerial.print("AT+CMGS=\"9427961822\""); // Replace with your phone number
delay(1000);
gsmSerial.print("Alcohol Detected! Location: ");
// You would add GPS location information here
displayAlertOnLCD("Alcohol Detected! Location: ");
delay(1000);
gsmSerial.write(26); // CTRL+Z to send SMS
delay(1000);
}
void handleGPS() {
// Simulated GPS reading for Wokwi
if (gpsSerial.available()) {
Serial.write(gpsSerial.read());
}
}
void handleGSM() {
// Simulated GSM response for Wokwi
if (gsmSerial.available()) {
Serial.write(gsmSerial.read());
}
}
void displayAlertOnLCD(String message) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(message);
delay(2000);
}