First before I go into the article I should mention you should not rely on this tool as a fool proof safety device. It's possible someone could slip past the camera especially if they are moving very fast. I highly suggest pool gates for safety (neighbor kids, etc.) and teaching your kids how to swim to avoid accidental drowning.
I decided upon this project as I wanted an effective way to monitor an environment that was self sufficient power wise, safe from Florida's humidity, and provided a platform for me to test various machine learning models. One of my first ideas to use the vision sensor was as a pool alert system. I noticed there were several models for detection of people available on the SenseCraft AI website so this project could utilize one of them in an effective way. In addition the use of Telegram, as documented by Seeed on their wiki, gave me the means to be alerted when this event occurred.
Vision Sensor V2 SetupAs shown in the video the first step to prepare this device is to flash the module with the new model logic.
To do this you'll need to following these steps:
- Using Chrome or Microsoft Edge Visit the SenseCraft Web Toolkit
- Connect to your device via the “Connect” button
- A web serial popup will appear allowing you to connect to your device
- Select a model from the available and send to the device
This next process takes a little bit of time but when it completes your device is ready to be used. Invoking the model from the web toolkit also provides a means to test it prior to launch confirming it's working as intended.
Telegram SetupWith the model on the vision sensor the next step is to prepare telegram for sending messages via its API. You can refer to the Seeed Wiki article on the topic. I’ll go over the steps here.
- Contact https://telegram.me/BotFather sending the message
/newbot
to initiate the bot creation process - Respond to the messages from the BotFather giving your bot a name and username
- After this the bot will respond with a token you can use for interfacing with the API
- Adding this bot to a group will associate a chat id with your user and the bot (until this step is taken the response will not contain a chat id)
- Hitting the endpoint
https://api.telegram.org/bot{Token}/getUpdates
after replacing the{Token}
with your token will return a payload that includes your chat id - After you’ve received this chat id you can subsequently send messages to the bot via the
/sendMessage
endpoint
With cURL you can send a message directly to the bot via:
curl https://api.telegram.org/bot{Token}/sendMessage -H 'Content-Type: application/json' -X POST --data '{"chat_id": 7216726720, "text":"Test Message"}'
Component SetupI've included a list of the components as part of the project file. Here I will go through each step to fully setup your device to match the one shown in the video. It's a mostly no solder setup outside of the level shifting component. In my video I used the simple Grove to Grove level shifter I setup.
I suggest VHB tape from 3M for mounting as it holds well.
- First take the Lipo Rider Pro and position it such that there’s enough room for the 90 degree connector, connect the 90 degree connector
- Attach the solar panel via its connector
- Attach a lithium ion battery to its connector
- Attach the Xiao ESP32C3 to the Grove Shield and break off the extra HY 2.0 4P connectors (for this enclosure I could not fit the full shield)
- With the Xiao ESP32C3 now connected attach it to the 90 degree connector via the USB-C connection
- Connect the buzzer to the A1 A0 grove connector via a Grove cable (A1 is not used in this case as the Buzzer only uses the 4th pin)
- Connect the LED bar to the A2 A1 grove connector via a Grove cable (both pins are used here)
- You will need to level shift for the Grove Vision AI V2 (it seems to work with 3V3 but the wiki states it only takes 5V so likely not a good idea – the Grove connection leads to a 3V3 regulator and expects 5V from the schematic)
- For the level shifting connect SDA and SCL to the LV#s side of a level shifter, connect the LV to 3V3, GND to GND. On the HV side connect the HV to the 5V / VBUS from the Grove Shield extra pins, then connect the corresponding SDA and SCL wires leading to the Grove Vision AI V2 along with the GND wire. To make this process simpler I setup a DIY inline level shifter circuit I described in another article. I also designed a Xiao Level Shifting base board that’s on the way – hoping it simplifies future projects.
- With the connections in place use the VHB tape to prevent movement in the enclosure for most of the parts and electrical tape to hold the LED bar, solar panel, and camera to the roof.
So a bit complicated sounding but mostly straightforward connections.
Code SetupFor the code you’ll first want to setup Arduino for use with the Espressif boards. To do this you’ll need to:
- Press
File
from the menu bar and pressPreferences
from the list - Near the bottom of the screen you’ll see an area for additional board management URLs to be added. Here you’ll want to add
https://espressif.github.io/arduino-esp32/package_esp32_index.json
to the comma separated list (it may be blank if this is the first non-Arduino board you’re configuring) - After installing go to the boards submenu from the left-hand side bar selection menu
- Type in “Espressif” in the search bar
- You’ll see a
esp32
board option, install this to setup the associated esp-tool tooling and related boards - In the code screen pull down the board select and type in “Xiao ESP32C3” it should return the associated board
- For the libraries you’ll need to add the 1.0.1 version of the LED Bar from GitHub as it hasn’t been published at this time
- In addition the SSCMA library should be installed
The entire code for this example can be found with my gist. I've gone into some detail describing the code on my site but I think it's pretty straightforward. The code is designed to configure the various components and then in a loop keep an eye out for the number of found bounding boxes with a score over a given confidence value. Once this happens it triggers a message to Telegram in the way we described previously.
Future ThoughtsI've put together a simple board to connect to the Xiao footprint and optionally level shift. I'm hoping this approach makes projects like this a lot more compact in the future. I'll be sure to make note of my project once the PCB has been assembled.
Thank you for taking the time to read through my project!
Comments