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)

IMG_1274.jpg

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:

  1. Arduino (e.g. Uno or Nano)
  2. Servo motor
  3. Phototransistor
  4. LED (used as light source)
  5. Resistors
  6. Jumper wires
  7. Breadboard (optional)
  8. Power supply

Understanding the Detection System

The detection system is based on a light barrier.

  1. The LED continuously shines light onto the phototransistor
  2. As long as the light reaches the sensor, nothing happens
  3. When a mouse passes through, it blocks the light
  4. This change is detected by the Arduino

This is a simple but effective way to detect movement in a specific area.

Wiring the Components

IMG_1261.jpg

Connect the components as follows:

  1. Connect the LED with a resistor to a digital pin
  2. Connect the phototransistor to an analog pin
  3. Connect the servo motor to a PWM pin
  4. 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:

while (analogRead(sensor) > 30) {} // Adjust this value for your setup
  1. High value → light detected
  2. Low value → light blocked → trigger

You may need to adjust the threshold depending on lighting conditions.

Setting Up the Trap Mechanism

IMG_1249.JPG

Attach the servo motor to your trap mechanism.

  1. 90° = open position
  2. 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:

  1. Peanut butter
  2. Chocolate
  3. Nuts or seeds
  4. 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:

  1. Days
  2. Hours
  3. Minutes

This data is stored in EEPROM and can be useful for testing and optimization.

Testing the System

Before using the trap:

  1. Test the sensor by blocking the light with your hand
  2. Adjust the threshold if needed
  3. Make sure the servo moves correctly
  4. Check alignment of LED and phototransistor

Downloads

Improvements

You can improve this project further:

  1. Add a potentiometer to adjust sensitivity
  2. Shield the sensor from ambient light
  3. 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.