As a mole, you sometimes have the same problems like humans: Nasty neighbours. In my case, mice. I have a cat named Tommy (his full name is Thomas Alva Edison G.) and he takes it’s job quite seriously. He catches around 1.5-2 mice a day (or better say night?). Most of them are headless. Dear IT guys, mice don’t tend to have screens, but headless here means, without a head. Unfortunately, some of them seem to be better suited as a toy and kept alive. These little animals are really smart and quickly hide behind a cabinet or somewhere else when not continously wathced. After half an hour, Tommy loses interest, these mice found a new home and tend to stay.
Everybody knowing me will correctly guess, that I didn’t simply bought a trap. And as it was saturday late evening, when I decided to hunt them down, I started printing one. You can find a nice one on printables here. The print took a few hours and was finished, just before I went to bed. So I placed it in the basement, where I definitely had a mouse. And I forgot about it until Tuesday. When I came back to the trap, you didn’t even need to look, you could smell it already, that the mouse did not piss off, but it pissed. I put it in the garden for Tommy to hunt it again 😛 and cleaned up the mess in the trap with a huge amount of water.
That was the point, where I thought about a trap with notification. So I took the 3D model and modified it first, to place a 6×3 magnet in the flap and added an opening in the lid at the right place to add some electronics stuff for detection of the magnet and sending the information to my smart home, where I can do whatever I want with that data (e.g. send a pushover message).
![](https://the78mole.de/wp-content/uploads/2024/06/LidWithCover.png)
![](https://the78mole.de/wp-content/uploads/2024/06/LidWithCover2.png)
![](https://the78mole.de/wp-content/uploads/2024/06/SensorAttachment.png)
![](https://the78mole.de/wp-content/uploads/2024/06/MouseTrap-disassembled-1024x576.jpg)
As a sensor, I decided to use the integrated magnetic field sensor of the ESP32 (the old one, newer ones don’t have it integrated anymore). Additionally, I took a simple TP4056 USB-Li-Ion-Charger module from AliExpress and a LiPo battery, I just had lying around. But the case is designed that it can receive a 18650 cell (optional including a battery holder).
Charging looks like this
![](https://the78mole.de/wp-content/uploads/2024/06/MouseTrap-charging-1024x576.jpg)
To test it in action, I decided to use ESPhome, since it has the magnetic field sensor well integrated. Later I’ll implement a BThome firmware, to extend battery life by magnitudes, but for now, it is the perfect rapid prototyping solution. The ESPhome YAML looks as follows:
esphome:
name: mousetrap1
esp32:
board: esp32dev
framework:
type: arduino
logger:
# Enable Home Assistant API
api:
ota:
- platform: esphome
password: <XXX>
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 172.22.3.233
gateway: 172.22.0.1
subnet: 255.255.240.0
sensor:
- platform: esp32_hall
name: "Mouse Trap 1 Magnetic Field"
id: mouse_trap_1_mag
update_interval: 1s
- platform: adc
name: "Mouse Trap 1 3V3"
id: mouse_trap_1_3v3
pin: 39
attenuation: auto
update_interval: 10s
filters:
multiply: 3.128 # 100K/47K divider
- platform: adc
name: "Mouse Trap 1 VBat"
id: mouse_trap_1_vbat
pin: 33
attenuation: auto
update_interval: 10s
filters:
multiply: 3.128 # 100K/47K divider
To monitor the battery and supply voltages, I added a 100K/47K resisttor divider. These two dividers will draw around 0.02 mA (less than 100 mW) each, which is quite fine. The ESP32 will draw not much less even with Bluetooth LE only, because it needs to sample the magnetic sensor quite often (at least once per second) to detect the quick flap movement by a mouse. With WiFi enabled, it takes around 100 mA and the battery will only last for one day.
In Home Assistant, this looks now like this:
![](https://the78mole.de/wp-content/uploads/2024/06/HA-Trap.png)
And with an automation and the Pushover service, my smartphone’s notification shows as follows:
![](https://the78mole.de/wp-content/uploads/2024/06/pushover-1024x752.png)
To test it, I just turned the trap over and within only a few seconds, my Smartphone received the notification.
Since I already have some bluetooth proxies around my house, next step is, to write a BThome compliant firmware to send the notification… Stay tuned 🙂
Schreibe einen Kommentar