BW21-CBV-Kit — Your Personal Desk Sentinel

Overview

Have you ever wondered who sat at your desk when you were away? At what time? What were they looking at? With these questions in mind, the BW21-CBV-Kit was designed to monitor your workstation. It discreetly records any visitors' presence and saves photo evidence.

Materials Required

  • BW21-CBV-Kit x1
  • SD Card x1
  • Tactile Push Button x2
  • Green LED (optional) x1
  • Red LED (optional) x1
  • Ultrasonic Distance Sensor x1

Functionality

1. Hardware Wiring


2. Software Development

The software is developed using Arduino, modified based on the example RTSPFaceRecognition.


Code Overview

#include "WiFi.h"

#include "StreamIO.h"

#include "VideoStream.h"

#include "RTSP.h"

#include "NNFaceDetectionRecognition.h"

#include "VideoStreamOverlay.h"

#include <NTPClient.h>

#include <WiFiUdp.h>

#include "AmebaFatFS.h"

#include <NewPing.h>

 

// Define ultrasonic sensor pins and distance

#define TRIGGER_PIN 17

#define ECHO_PIN 8

#define MAX_DISTANCE 400

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

 

// Define input pins for buttons

#define IOD18_PIN 18

#define IOD19_PIN 19

 

// Video channels

#define CHANNEL 0

#define CHANNELNN 3

 

// Neural network image resolution

#define NNWIDTH 576

#define NNHEIGHT 320

 

float dis = 0.0;

String name = "";

 

uint32_t img_addr = 0;

uint32_t img_len = 0;

 

unsigned long startTime = 0;  // Record the start time when proximity is detected

bool GPIOisHigh = false;      // Flag to check if proximity condition is active

bool facedetisTRUE = false;   // Flag to check if a face has been detected

AmebaFatFS fs;

 

// Video settings for RTSP and image capture

VideoSetting config(VIDEO_FHD, CAM_FPS, VIDEO_JPEG, 1);

VideoSetting configNN(NNWIDTH, NNHEIGHT, 10, VIDEO_RGB, 0);

 

// Modules

NNFaceDetectionRecognition facerecog;

RTSP rtsp;

StreamIO videoStreamer(1, 1);

StreamIO videoStreamerFDFR(1, 1);

StreamIO videoStreamerRGBFD(1, 1);

 

// WiFi credentials

char ssid[] = "Your WiFi SSID";    

char pass[] = "Your WiFi Password";

int status = WL_IDLE_STATUS;

 

// Time synchronization

WiFiUDP ntpUDP;

NTPClient timeClient(ntpUDP, "pool.ntp.org", 28800, 60000);

IPAddress ip;

int rtsp_portnum;

 

// Helper function: pad number with 0 if < 10

String padWithZero(int num) {

  return (num < 10) ? "0" + String(num) : String(num);

}

 

// Generate timestamp-based file name

String generateFileName() {

  timeClient.update();

  unsigned long epochTime = timeClient.getEpochTime();

  Serial.println(epochTime);

  time_t localTime = epochTime;

  struct tm *ptm = localtime(&localTime);

 

  int year = ptm->tm_year + 1900;

  int month = ptm->tm_mon + 1;

  int day = ptm->tm_mday;

  int hour = ptm->tm_hour;

  int minute = ptm->tm_min;

  int second = ptm->tm_sec;

 

  String fileName = String(year) + "-" + padWithZero(month) + "-" + padWithZero(day) + "_" +

                    padWithZero(hour) + "-" + padWithZero(minute) + "-" + padWithZero(second) + ".jpg";

 

  Serial.print("Current Date and Time: ");

  Serial.println(fileName);

 

  return fileName;

}

 

// Capture and save image

bool saveimage() {

  fs.begin();

  String fileName = generateFileName();

  File file = fs.open(String(fs.getRootPath()) + fileName);

  delay(1000);

  Camera.getImage(CHANNEL, &img_addr, &img_len);

  file.write((uint8_t *)img_addr, img_len);

  file.close();

  fs.end();

  return true;

}

Functional Description

1. Face Detection and...

Read more »