BW21-CBV-Kit — Your Personal Desk Sentinel
OverviewHave 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
The software is developed using Arduino, modified based on the example RTSPFaceRecognition.
#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 Description1. Face Detection and RecognitionAfter powering on, the system begins real-time face detection. To register your own face, face the camera at a distance less than 50cm and press the green button. The system will register your face as "myself" to avoid recording your own presence.
Strangers will be labeled as "unknown."
When someone stays within 50cm for over 3 seconds, the system will take a photo.
Press the red button to delete registered faces.
Press the green button to re-register a face.
Note: To also record your own sitting and leaving times, remove the condition: String(item.name()) != "myself"2. Distance Monitoring
An ultrasonic sensor monitors proximity. You can adjust the detection range based on your workspace.
3. Timestamped Image SavingOnce connected to WiFi, the system fetches NTP time and saves photos with timestamped filenames:
Format: YYYY-MM-DD_hh-mm-ss.jpg
To enable image capture, configure the camera for JPEG frames:
VideoSetting config(VIDEO_FHD, CAM_FPS, VIDEO_JPEG, 1);
H264 streaming mode does not support image saving:
VideoSetting config(VIDEO_FHD, 30, VIDEO_H264, 0);Feature Extensions
Currently, the system saves images only to the local SD card. To enable remote or real-time monitoring, you can extend functionality using MQTT to upload images to a cloud server.
This way, you can instantly check who has visited your workstation.
Comments