#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int pirSensor = 2; // PIR motion sensor connected to pin 2
const int buzzer = 11;
void setup() {
pinMode(pirSensor, INPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display(); // Show initial display buffer contents on the screen
delay(2000); // Pause for 2 seconds
display.clearDisplay(); // Clear the buffer
}
void loop() {
int motionDetected = digitalRead(pirSensor);
if (motionDetected == LOW) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(16, 15);
display.println("ALERT! SURAJ");
display.println("");
display.println("");
display.setCursor(0, 30);
display.println("A Thief is Detected");
display.display();
tone(buzzer, 1000);
} else {
display.clearDisplay();
display.display();
noTone(buzzer);
}
delay(500); // Adjust delay as needed
}