#include const int buzzerPin = 12; // Define the pin connected to the buzzer int farma = 0; int farmb = 0; // Define buzzer states const int BUZZER_ON = HIGH; const int BUZZER_OFF = LOW; // State and timing variables int buzzerState = BUZZER_OFF; unsigned long lastMotionTime = 0; const unsigned long buzzerDuration = 5000; // Buzzer duration in milliseconds (10 seconds) LiquidCrystal lcd(9, 8, 7, 6, 5, 4); // Your LCD connections void setup() { Serial.begin(9600); // Initialize serial communication lcd.begin(16, 2); // Initialize the LCD pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output } void loop() { // Simulating PIR sensor readings farma = digitalRead(2); // Pin 2 for PIR sensor A farmb = digitalRead(3); // Pin 3 for PIR sensor B // Display Fence A lcd.setCursor(0, 0); lcd.print("Farm A: "); printWithDelay(farma, 0); // Display Fence B lcd.setCursor(0, 1); lcd.print("Farm B: "); printWithDelay(farmb, 1); // Check for motion if (farma == HIGH || farmb == HIGH) { buzzerState = BUZZER_ON; // Turn on the buzzer if motion detected lastMotionTime = millis(); // Update last motion time } // Control buzzer based on timer if (buzzerState == BUZZER_ON) { tone(buzzerPin, 1000); // Play sound at 1000 Hz // Check if the buzzer should be turned off if (millis() - lastMotionTime >= buzzerDuration) { buzzerState = BUZZER_OFF; // Turn off the buzzer after the duration } } else { noTone(buzzerPin); // Stop playing sound } // Read Bluetooth data if (Serial.available() > 0) { char data = Serial.read(); // Read single character from Bluetooth if (data == '1') { buzzerState = BUZZER_ON; } else if (data == '0') { buzzerState = BUZZER_OFF; } } delay(100); // Delay for stability } void printWithDelay(int motionDetected, int row) { // Move cursor to the start of the message area lcd.setCursor(7, row); // Position cursor after "Farm A: " or "Farm B: " // Clear the line by printing spaces lcd.print(" "); // 16 spaces to clear the line lcd.setCursor(7, row); // Reset cursor to start of message area if (motionDetected == HIGH) { slowPrint("Birds ", row); } else { slowPrint("No Motion", row); } } void slowPrint(const char *str, int row) { lcd.setCursor(7, row); // Ensure cursor is at the correct row while (*str) { lcd.write(*str++); delay(100); // Adjust the delay as needed for desired speed } }