#include <Wire.h>
#define MQ3_PIN A0 // Analog input for MQ-3 sensor
#define GSM_TX 7 // ESP32 TX → GSM RX
#define GSM_RX 6 // ESP32 RX ← GSM TX
#define GSMBaud 9600 // Adjust for your GSM module
HardwareSerial gsmSerial(2); // UART2 for GSM
void setup() {
Serial.begin(115200);
gsmSerial.begin(GSMBaud, SERIAL_8N1, GSM_RX, GSM_TX);
pinMode(MQ3_PIN, INPUT);
Serial.println("MQ-3 Alcohol Sensor Initialized...");
}
void loop() {
int sensorValue = analogRead(MQ3_PIN);
float alcoholLevel = sensorValue * (5.0 / 1023.0); // Convert to voltage
Serial.print("Alcohol Level: ");
Serial.println(alcoholLevel);
if (alcoholLevel > 0.5) { // Threshold for detection
Serial.println("ALCOHOL DETECTED! Sending Alert...");
sendAlert();
}
delay(2000);
}
void sendAlert() {
String message = "ALERT: Alcohol detected in helmet! Immediate medical response required.";
gsmSerial.println("AT+CMGF=1"); // Set SMS mode
delay(100);
gsmSerial.println("AT+CMGS=\"+1234567890\""); // Replace with recipient's number
delay(100);
gsmSerial.println(message);
delay(100);
gsmSerial.write(26); // End SMS command (Ctrl+Z)
Serial.println("Alert Sent to Medical Response Team!");
}