Kamera z detekcją ruchu:
- User
Kamera z detekcją ruchu:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Kamera z detekcją ruchu:
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Oto kompletny projekt kamery z detekcją ruchu do badań paranormalnych - szczegółowy opis, komponenty i kod:
PIR Sensor (HC-SR501) -> Arduino
VCC -> 5V
GND -> GND
OUT -> D2 (interrupt pin)
Kamera OV7670 -> Arduino
SIOD (SDA) -> A4
SIOC (SCL) -> A5
VSYNC -> D3
HREF -> A0
PCLK -> A1
XCLK -> D4
D7-D0 -> D5-D12
Moduł SD -> Arduino
CS -> D10
SCK -> D13
MOSI -> D11
MISO -> D12
RTC DS3231 -> Arduino
VCC -> 3.3V
GND -> GND
SDA -> A4
SCL -> A5
Diody IR -> D9 (przez tranzystor)
Status LED -> D8
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <RTClib.h>
#include <ArduCAM.h>
// Definicje pinów
#define PIR_PIN 2
#define IR_LED_PIN 9
#define STATUS_LED_PIN 8
#define CAM_CS_PIN 10
// Obiekty
RTC_DS3231 rtc;
ArduCAM myCAM(OV7670, CAM_CS_PIN);
// Zmienne globalne
volatile bool motionDetected = false;
bool isRecording = false;
int photoCounter = 0;
unsigned long lastMotionTime = 0;
const unsigned long MOTION_DELAY = 5000; // 5s przerwa między zdjęciami
void setup() {
Serial.begin(115200);
// Inicjalizacja pinów
pinMode(PIR_PIN, INPUT);
pinMode(IR_LED_PIN, OUTPUT);
pinMode(STATUS_LED_PIN, OUTPUT);
// Inicjalizacja przerwania PIR
attachInterrupt(digitalPinToInterrupt(PIR_PIN), motionISR, RISING);
// Inicjalizacja modułów
initializeCamera();
initializeSD();
initializeRTC();
Serial.println("Paranormal Motion Camera Ready");
blinkStatusLED(3); // Sygnał gotowości
}
void loop() {
if (motionDetected && (millis() - lastMotionTime > MOTION_DELAY)) {
handleMotionEvent();
motionDetected = false;
lastMotionTime = millis();
}
// Sprawdź stan baterii (opcjonalnie)
checkBatteryLevel();
delay(100);
}
// Przerwanie od czujnika PIR
void motionISR() {
motionDetected = true;
}
// Obsługa wykrycia ruchu
void handleMotionEvent() {
Serial.println("Motion detected! Taking photo...");
// Włącz oświetlenie IR
digitalWrite(IR_LED_PIN, HIGH);
digitalWrite(STATUS_LED_PIN, HIGH);
delay(100); // Czas na ustabilizowanie oświetlenia
// Zrób zdjęcie
if (capturePhoto()) {
Serial.println("Photo saved successfully");
photoCounter++;
} else {
Serial.println("Photo capture failed");
}
// Wyłącz oświetlenie IR
digitalWrite(IR_LED_PIN, LOW);
digitalWrite(STATUS_LED_PIN, LOW);
}
// Funkcja robienia zdjęcia
bool capturePhoto() {
// Generuj nazwę pliku z timestampem
String filename = generateFilename();
File imgFile = SD.open(filename, FILE_WRITE);
if (!imgFile) {
Serial.println("Failed to create file");
return false;
}
// Rozpocznij capture
myCAM.flush_fifo();
myCAM.clear_fifo_flag();
myCAM.start_capture();
// Czekaj na zakończenie
while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK));
// Zapisz dane do pliku
uint32_t length = myCAM.read_fifo_length();
if (length >= MAX_FIFO_SIZE) {
Serial.println("Image too large");
imgFile.close();
return false;
}
myCAM.CS_LOW();
myCAM.set_fifo_burst();
// Transfer danych
uint8_t temp = 0, temp_last = 0;
bool is_header = false;
for (uint32_t i = 0; i < length; i++) {
temp_last = temp;
temp = SPI.transfer(0x00);
// Wykryj początek JPEG
if ((temp == 0xD8) && (temp_last == 0xFF)) {
is_header = true;
imgFile.write(temp_last);
imgFile.write(temp);
} else if (is_header) {
imgFile.write(temp);
// Wykryj koniec JPEG
if ((temp == 0xD9) && (temp_last == 0xFF)) break;
}
}
myCAM.CS_HIGH();
imgFile.close();
return true;
}
// Generowanie nazwy pliku z timestampem
String generateFilename() {
DateTime now = rtc.now();
char filename[30];
sprintf(filename, "GHOST_%04d%02d%02d_%02d%02d%02d.jpg",
now.year(), now.month(), now.day(),
now.hour(), now.minute(), now.second());
return String(filename);
}
// Inicjalizacja kamery
void initializeCamera() {
Wire.begin();
myCAM.write_reg(0x07, 0x80);
delay(100);
myCAM.write_reg(0x07, 0x00);
delay(100);
// Sprawdź połączenie
if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)) {
Serial.println("Camera module connected");
} else {
Serial.println("Camera connection failed");
}
// Ustaw rozdzielczość i jakość
myCAM.set_format(JPEG);
myCAM.InitCAM();
myCAM.set_bit(ARDUCHIP_TIM, VSYNC_LEVEL_MASK);
myCAM.OV7670_set_JPEG_size(OV7670_640x480);
}
// Inicjalizacja karty SD
void initializeSD() {
if (!SD.begin(CAM_CS_PIN)) {
Serial.println("SD card initialization failed");
return;
}
Serial.println("SD card ready");
}
// Inicjalizacja RTC
void initializeRTC() {
if (!rtc.begin()) {
Serial.println("RTC initialization failed");
return;
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, setting time");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
// Sygnalizacja LED
void blinkStatusLED(int times) {
for (int i = 0; i < times; i++) {
digitalWrite(STATUS_LED_PIN, HIGH);
delay(200);
digitalWrite(STATUS_LED_PIN, LOW);
delay(200);
}
}
// Sprawdzenie poziomu baterii
void checkBatteryLevel() {
int batteryLevel = analogRead(A3); // Jeśli podłączony dzielnik napięcia
if (batteryLevel < 512) { // Przykładowy próg
// Migaj LED ostrzegawczo
digitalWrite(STATUS_LED_PIN, millis() % 1000 < 100);
}
}
1. Analiza różnicowa obrazu:
// Porównuj kolejne klatki i rób zdjęcie tylko przy większych zmianach
bool compareFrames(uint8_t* frame1, uint8_t* frame2, int size) {
int differences = 0;
for (int i = 0; i < size; i += 10) { // Co 10. piksel
if (abs(frame1[i] - frame2[i]) > 30) differences++;
}
return (differences > 100); // Próg różnic
}
2. Tryb czasowy (Time-lapse):
// Rób zdjęcie co X minut niezależnie od ruchu
if (millis() - lastTimelapsePhoto > TIMELAPSE_INTERVAL) {
capturePhoto();
lastTimelapsePhoto = millis();
}
3. Detekcja różnych typów ruchu:
// Analiza szybkości ruchu PIR
void analyzeMotionPattern() {
static unsigned long motionTimes[5];
static int motionIndex = 0;
motionTimes[motionIndex] = millis();
motionIndex = (motionIndex + 1) % 5;
// Szybkie następujące po sobie ruchy = "nietypowe"
bool rapidMotion = true;
for (int i = 1; i < 5; i++) {
if (motionTimes[i] - motionTimes[i-1] > 2000) {
rapidMotion = false;
break;
}
}
if (rapidMotion) {
// Specjalne oznaczenie w nazwie pliku
Serial.println("RAPID MOTION DETECTED!");
}
}
4. Transmisja WiFi (z ESP32-CAM):
// Wyślij zdjęcie na serwer lub email po wykryciu ruchu
void sendPhotoAlert(String filename) {
// Kod do wysłania zdjęcia przez WiFi
}
Zalecenia praktyczne:
Który aspekt chcesz rozwinąć bardziej szczegółowo?