---
title: "Video surveillance system using RP2040, W5100S and OV2640"
url: "https://maker.wiznet.io/viktor/projects/video-surveillance-system-using-rp2040%2C-w5100s-and-ov2640/"
markdown_url: "https://maker.wiznet.io/viktor/projects/video-surveillance-system-using-rp2040%2C-w5100s-and-ov2640/md"
type: "WCC: WIZnet Created Content"
author: "viktor"
author_url: "https://maker.wiznet.io/viktor/"
original_author: "Viktor"
published: "2023-09-07"
language: "en"
hardware: ["WIZnet W5100S-EVB-Pico", "Arducam Mini 2MP Plus", "SparkFun Ultrasonic Sensor - HC-SR04"]
likes: 1
views: 1900
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Video surveillance system using RP2040, W5100S and OV2640

> This example aims to demonstrate how to implement simple security surveillance system. The camera can be controlled via Telegram Bot.

Original author: Viktor

## Components

- **WIZnet W5100S-EVB-Pico** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5100S/w5100s-evb-pico))
- **Arducam Mini 2MP Plus** x 1 ([docs](https://www.arducam.com/product/arducam-2mp-spi-camera-b0067-arduino/))
- **SparkFun Ultrasonic Sensor - HC-SR04** x 1 ([docs](https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf))
- Software: **Arduino IDE** ([docs](https://www.arduino.cc/en/software))

## Documents and links

- [SurveillanceSystem.ino](https://github.com/wiznetmaker/W5100S-ArduCAM-Arduino-Examples/tree/main/SurveillanceSystem) (code)

## Article

## Project summary

The "Ethernet" example from AsyncTelegram library was used as a basis for this project. "Capture" button was added to the keyboard to make a single shot. "Automode ON/OFF" buttons were added to enable/disable the ultrasound sensor.

When sensor is enabled, if there is any object within 1 meter (short distance was selected for test purposes), then camera automatically captures and sends image to the Telegram bot.

![](https://maker.wiznet.io/upload/ckeditor5/77976289%5F1694100203%2Epng)

## Libraries used in the project

1. [Arducam library](https://github.com/wiznetmaker/W5100S-ArduCAM-Arduino-Examples/blob/main/SurveillanceSystem): please pay attention to important note in main readme file.

2. [WebServer](https://github.com/khoih-prog/EthernetWebServer/tree/master) by Khoi Hoang

3. [AsyncTelegram2](https://github.com/cotestatnt/AsyncTelegram2/tree/master) by Tolentino Cotesta

## Code explanation

### Ethernet and Telegram bot related code:

For test purposes the board is assigned with static IP.

Telegram bot setup is done main setup() function:

**Setup Function:**

```
- The `setup()` function is the initialization routine.
- It initializes serial communication, I2C, SPI, camera, and Ethernet.
- It sets up the Telegram bot, reply keyboard, and inline keyboard.
- A welcome message is sent to the Telegram bot.
- `alarmStatusEE` is set to `false` initially.
```

### Camera related functions

**test_capture() Function:**

```
- This function clears the FIFO (First In, First Out) flag of the camera and initiates a capture.
```

**camCapture() Function:**

```
- This function captures an image from the camera and sends it as an HTTP response with the appropriate content type and length.
- It reads the image data from the camera's FIFO buffer and sends it to the client.
```

**i2c_init(), spi_init(), and camera_init() Functions:**

```
- These functions initialize the I2C and SPI communication interfaces and set up the camera module.
- They perform various checks to ensure that the communication with the camera module is established correctly.
```

### Main Loop

```
- The `loop()` function runs repeatedly.
- It handles incoming Telegram messages and manages the reply keyboard.
- It checks if the ultrasonic distance sensor detects an intruder and sends a capture requesto the Telegram bot.
```

**Ultrasonic Distance Sensor:**

```
- The code monitors the ultrasonic distance sensor to detect intruders.
- It calculates the distance and, if an intruder is detected, sends a message to the Telegram bot and captures an image.
- The ultrasonic sensor is controlled by the `triggerPort` and `echoPort` pins.
```

## Demonstration

For full project demo, please refer to the video below:

[Embedded media](https://www.youtube.com/embed/JPQ0hpEAPEw)

---

Source: https://maker.wiznet.io/viktor/projects/video-surveillance-system-using-rp2040%2C-w5100s-and-ov2640/
