I wanted to create a simple Surveillance system using Arduino. I had all the components on hand, the only difficulty was that Arduino Arducam library does not have example for Pico. There are sample codes for Pico C/C++ SDK, thus I had to tweak the Arducam library a little. The detail information on code changes can be found in the repository here.
- Arducam library: please pay attention to important note in main readme file.
- WebServer by Khoi Hoang
- AsyncTelegram2 by Tolentino Cotesta
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.
Code explanationEthernet 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 functionstest_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.
DemonstrationBefore running, do not forget to input Bot token and your ID!
When connected, the board will attempt connection to Telegram. Once successful, it will send the keyboard settings and will wait for commands.
Comments