const int TEMP_SENSOR_PIN = A0;
const int GAS_SENSOR_PIN = A1;
const int BUZZER_PIN = 8;
const int LED_PIN = 13;
const float THR_TEMP = 40.0;
const int THR_GAS = 400;
void setup() {
pinMode(TEMP_SENSOR_PIN, INPUT);
pinMode(GAS_SENSOR_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(LED_PIN, LOW);
Serial.println("=== Safety Monitoring System Started ===");
Serial.println("Monitoring temperature and gas levels...");
Serial.println();
}
void loop() {
int tempRaw = analogRead(TEMP_SENSOR_PIN);
int gas = analogRead(GAS_SENSOR_PIN);
//float voltage = tempRaw * (5.0 / 1023.0);
//float tempC = map(tempRaw, 0, 1023, 0, 100);
int tempC = map(tempRaw, 650, 420, 25, 60);
Serial.print("temp in C: ");
Serial.print(tempC);
Serial.print( " C | gas level: ");
Serial.print(gas);
if (tempC > THR_TEMP) {
tone(BUZZER_PIN, 1000);
Serial.print("TEMP ALERT!!!");
}
else {
noTone(BUZZER_PIN);
}
if (gas > THR_GAS) {
digitalWrite(LED_PIN, HIGH);
Serial.print(" Gas Alert!!!");
}
else {
digitalWrite(LED_PIN, LOW);
}
Serial.println();
delay(500);
}