#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// LCD Initialization: Adjust the address if needed
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int sensorPin = A0; // Potentiometer simulating radiation sensor
const int greenLEDPin = 3; // Green LED for safe condition
const int redLEDPin = 4; // Red LED for alert condition
const int buzzerPin = 5; // Passive buzzer pin
int threshold = 700; // Radiation alert threshold
void setup() {
// Initialize LEDs and buzzer as outputs
pinMode(greenLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
// Initialize the LCD
lcd.begin(16, 2);
lcd.backlight();
lcd.print("Radiation Monitor");
delay(2000);
// Initialize Serial Monitor for SMS display
Serial.begin(9600);
Serial.println("System Initialized.");
}
void loop() {
int radiationLevel = analogRead(sensorPin); // Read the sensor value
// Clear LCD rows before updating
lcd.setCursor(0, 0);
lcd.print(" "); // Clear the first row
lcd.setCursor(0, 0);
lcd.print("Radiation: ");
lcd.print(radiationLevel);
lcd.setCursor(0, 1);
lcd.print(" "); // Clear the second row
lcd.setCursor(0, 1);
if (radiationLevel < threshold) {
// Safe condition
digitalWrite(greenLEDPin, HIGH);
digitalWrite(redLEDPin, LOW);
noTone(buzzerPin); // Turn off buzzer
lcd.print("Status: Normal");
// Print SMS-like message to Serial Monitor
Serial.println("Status: Normal. Radiation levels are safe.");
} else {
// Alert condition
digitalWrite(greenLEDPin, LOW);
digitalWrite(redLEDPin, HIGH);
// Continuous buzzer sound
tone(buzzerPin, 1000); // 1 kHz tone for passive buzzer
lcd.print("HIGH Radiation!");
// Print SMS-like message to Serial Monitor
Serial.println("ALERT: HIGH Radiation detected! Immediate action required.");
}
delay(1000); // Update every second
}