#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define LED_PIN 2        // Pin connected to the LED
#define PIR_PIN 13       // Pin connected to the PIR sensor
#define BUZZER_PIN 4     // Pin connected to the buzzer

#define SCREEN_ADDRESS 0x3C  // I2C address for the OLED display
#define OLED_RESET    -1      // Reset pin not used

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire); //OLED_RESET

void setup() {
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");

  pinMode(LED_PIN, OUTPUT);
  pinMode(PIR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  // Initialize the display
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  //display.begin(SCREEN_ADDRESS, OLED_RESET);
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.display();
}

void loop() {
  //int pirValue = digitalRead(PIR_PIN);  // Read PIR sensor value

  int pirValue = HIGH;
  if (pirValue == HIGH) {  // Motion detected
    // Display message on the OLED
    display.clearDisplay();
    display.setCursor(0, 0);
    display.print("Time to Take pills!");

    display.display();
    
    digitalWrite(LED_PIN, HIGH);  // Turn LED on
    Serial.println("Time to     Take Pills!");  // Print message
    tone(BUZZER_PIN, 1000, 500);  // Play sound for 1 second, pin, frequency, duration

    delay(2000);  // Wait for 2 seconds to avoid multiple triggers
  } else {
    digitalWrite(LED_PIN, LOW);   // Turn LED off
  }

  delay(100);  // Small delay for stability
}
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
pir1:VCC
pir1:OUT
pir1:GND
led1:A
led1:C
bz1:1
bz1:2
Loading
ssd1306