#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define EMF_SENSOR_PIN 34 // Potentiometer (simulating EMF signal)
#define LED_PIN 26 // LED to indicate phone detection
#define BUZZER_PIN 27 // Buzzer to alert detection
#define THRESHOLD 300 // EMF detection threshold (adjust as needed)
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD address (0x27) and size (16x2)
void setup() {
// Start I2C communication and initialize LCD
Wire.begin();
lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
lcd.backlight(); // Turn on the LCD backlight
// Set pin modes
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(EMF_SENSOR_PIN, INPUT);
// Display welcome message
lcd.setCursor(0, 0);
lcd.print("Welcome to the");
lcd.setCursor(0, 1);
lcd.print("Home of Phone Detector");
delay(2000); // Wait for 2 seconds to display the welcome message
lcd.clear(); // Clear the screen after the welcome message
}
void loop() {
// Read the potentiometer value (simulating EMF sensor)
int emfValue = analogRead(EMF_SENSOR_PIN);
// Display the EMF value on LCD
lcd.setCursor(0, 0);
lcd.print("EMF Level: ");
lcd.print(emfValue);
// Check if the EMF value exceeds the threshold (simulating phone detection)
if (emfValue > THRESHOLD) {
lcd.setCursor(0, 1);
lcd.print("Phone Detected!");
// Activate the LED and Buzzer
digitalWrite(LED_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH);
delay(500); // Wait for 500ms
digitalWrite(LED_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
} else {
lcd.setCursor(0, 1);
lcd.print("No Phone Found");
digitalWrite(LED_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
}
delay(500); // Delay between readings
}