// Define PIR sensor pin
const int pirSensorPin = 34; // Digital pin connected to PIR motion sensor
// Logging parameters
const int logInterval = 1000; // Log data every 1 second (in ms)
const int maxLogSize = 60; // Store last 60 readings (1 minute of data)
// Data storage array
int motionLog[maxLogSize];
int logIndex = 0;
// Timing
unsigned long lastLogTime = 0;
void setup() {
pinMode(pirSensorPin, INPUT);
Serial.begin(115200);
Serial.println("Breathing and Heart Rate (Motion) Logging");
}
void loop() {
// Read motion detected by PIR sensor
int motionDetected = digitalRead(pirSensorPin);
// Log data at regular intervals
if (millis() - lastLogTime >= logInterval) {
logData(motionDetected);
lastLogTime = millis();
}
// Display current motion status
Serial.print("Motion Detected: ");
Serial.println(motionDetected ? "YES" : "NO");
delay(500); // Short delay for stability
}
// Function to log data
void logData(int motionDetected) {
// Add data to circular buffer
motionLog[logIndex] = motionDetected;
logIndex = (logIndex + 1) % maxLogSize;
// Print logged data to serial for demonstration
Serial.println("Logged Data:");
for (int i = 0; i < maxLogSize; i++) {
Serial.print("Log ");
Serial.print(i + 1);
Serial.print(": ");
Serial.println(motionLog[i] ? "Motion Detected" : "No Motion");
}
Serial.println();
}