#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C // I2C address for the OLED display (adjust if needed)
#define PIR_SENSOR_PIN 34 // Analog pin connected to PIR sensor
// Create an instance of the OLED display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Serial.begin(115200);
// Initialize the OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
// Clear the display and set up initial display settings
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("PIR Sensor Readings"));
display.display();
}
void loop() {
int sensorValue = analogRead(PIR_SENSOR_PIN); // Read the analog value from PIR sensor
// Clear the display before updating
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print(F("PIR Sensor Value: "));
display.println(sensorValue);
display.display();
delay(500); // Update the display every 500 milliseconds
}