How to Build an Arduino Mouse Trap (Simple & Effective)
by ArtusIndus in Circuits > Arduino
126 Views, 1 Favorites, 0 Comments
How to Build an Arduino Mouse Trap (Simple & Effective)
In this project, I will show you how to build a simple automated mouse trap using an Arduino and a servo motor.
The system uses a phototransistor and an LED as a light barrier. When a mouse interrupts the light beam, the trap is triggered instantly.
Additionally, the Arduino records how long the system was running before activation using EEPROM.
This project is simple, low-cost, and great for learning basic electronics and sensor systems.
For the complete code and future updates, check out my GitHub repository:
https://github.com/ArtusIndus/arduino-mouse-trap
Supplies
You will need the following components:
- Arduino (e.g. Uno or Nano)
- Servo motor
- Phototransistor
- LED (used as light source)
- Resistors
- Jumper wires
- Breadboard (optional)
- Power supply
Understanding the Detection System
The detection system is based on a light barrier.
- The LED continuously shines light onto the phototransistor
- As long as the light reaches the sensor, nothing happens
- When a mouse passes through, it blocks the light
- This change is detected by the Arduino
This is a simple but effective way to detect movement in a specific area.
Wiring the Components
Connect the components as follows:
- Connect the LED with a resistor to a digital pin
- Connect the phototransistor to an analog pin
- Connect the servo motor to a PWM pin
- Make sure to connect GND and VCC properly
⚠️ Tip: Keep the LED and phototransistor aligned so the light beam directly hits the sensor.
Upload the Code
Upload your Arduino code to the board.
The important part of the code checks the sensor value:
- High value → light detected
- Low value → light blocked → trigger
You may need to adjust the threshold depending on lighting conditions.
Setting Up the Trap Mechanism
Attach the servo motor to your trap mechanism.
- 90° = open position
- 180° = triggered (closed)
When the sensor is triggered, the servo quickly closes the trap.
Adding Bait
To make the trap effective, you need bait.
Good options include:
- Peanut butter
- Chocolate
- Nuts or seeds
- Bread
Place the bait behind the sensor, so the mouse must pass through the light barrier.
EEPROM Time Tracking
The Arduino stores how long the system was running before activation.
It saves:
- Days
- Hours
- Minutes
This data is stored in EEPROM and can be useful for testing and optimization.
Testing the System
Before using the trap:
- Test the sensor by blocking the light with your hand
- Adjust the threshold if needed
- Make sure the servo moves correctly
- Check alignment of LED and phototransistor
Downloads
Improvements
You can improve this project further:
- Add a potentiometer to adjust sensitivity
- Shield the sensor from ambient light
- Use an ESP8266/ESP32 for notifications
Important Notes & Safety
Sensor alignment is critical for reliable detection
Ambient light may affect readings
Always test the system before use
Disclaimer
This project is for educational purposes only.
Use responsibly and follow local regulations regarding animal handling.