A friend’s store was robbed at gunpoint several times - not so unusual in Argentina - and that was the starting point for this experimental project: automatically detect a gun to trigger a loud alarm without human intervention.
I’ve thought of using Raspberry Pi with a Raspberry Cam, compiling data sets and train a neural network, but then I’ve found out about HuskyLens developed by DFRobot and overall complexity was reduced a lot.
What is HuskyLens? it is a camera that can be connected to Arduino and Raspberry Pi but it is not just a camera since itincludes LCD monitor and computer vision functions with learning abilities. By default HuskyLens is able to recognize colors, objects, faces, tagsand lines. Arduino communication is performed with 2 cables (UART / I2C) plus power. Then with a few code lines, you are ready to react to different scenarios based on camera recognition. Example in this case: if a gun is detected, close a Relay and trigger a Loud Alarm.
Note: again, this is just an experimental project.
Parts used1 x Husky Lens
1 x DfRduino (it is Arduino Uno v3.0 ATmega328p with robust female headers)
1 x Red Led Switch
1 x Relay module
1 x compatible microSD card
1 x Siren horn
Jumper cables male-female and female-female
Custom 3d printed case (you can make your own with wood or a generic enclosure)
Huskylens Library InstallationDownload library zip from https://github.com/HuskyLens/HUSKYLENSArduino
Then unzip and copy the files into your Arduino libraries folder, inside a new Huskylens folder.
Huskylens Firmware UpdateCheck inside HuskyLensGeneral Settings. If you have 0.47 firmware you may want to upgrade to v0.5 Some features like custom names for objects and saving screenshots to microSD card won’t work otherwise. But they are optional features so you can also skip Firmware update.
Training HuskyLensFor the first part, connect a USB Power Bank or Power Supply to the microUSB of the Husky Lens. Screen will turn on. Then you will be able to navigate using the wheel, which also has a push button. On the other side there is the learning button.
We will use Object Tracking feature. Just go there, enter settings, select "Learn Enable", then short press the function button, and dial it to the right to turn the "Learn Enable" ON, that is, the square icon on the progress bar is turned to the right. Turn on also "Auto Save" Select “Save & Return”
Point Huskylens to a generic gun, adjusting the distance and until the object is included in the yellow frame of the center of the screen. Then long press "learning button" to learn the gun shape from various angles and distances. When the recognition result meets the requirements, you can turn off "Learn Enable".
If you want to save images, place a first brand microSD card like Sandisk or Kingston with Fat32 format into the slot.
ConnectionsHusky Lens red cable to Arduino 5V, Black cable to Arduino Ground. Green cable to pin D10, Blue cable to pin D11. You will need male to female jumper cables.
Relay VCC to Arduino VIN, Relay GND to Arduino Ground, Relay IN1 to Arduino D2.
Led Switch Green Cable to Arduino D7, red cable to Arduino 5v and black cable to Arduino Ground.
Finally connect the Siren Power + to the Relay Com. Relay NO to Siren + and Power Ground to Siren Ground. So the Relay is in the middle of the Power + and the Siren will sound only when Arduino tells the Relay to close the circuit.
Using Gun AwayPress the button to arm the system. Now, whenever a gun is placedin front of the camera the siren will start. You can configure siren delay inside code settings.
Adjusting ThreesoldHuskyLens includes threesold setting inside Object Tracking settings, so you can teach with one generic gun and recognize other similar guns as well. You mayalso need to configureFalse Positive threesold and frame size and ratio.
Browse imagesWhenever a gun is detected a picture will be also saved into microSD card. To view Gun Away screenshots, just remove the microSD from HuskyLens and place into your computer.
Demo videoWhere to go from here?What about replacing Arduino Uno by Arduino MKR WiFi or ESP32 so you can send Telegram messages to a group?
Comments