Mouse Trap: Schematic

The schematic for the mouse trap used a serial interface with the A3BU in the form of a MAX232 IC. This was the same configuration used in a previous lab. The part we had to design and figure out was the four photoresistors that were set in the mouse trap. We accomplished this by hooking a 10K ohm resistor in series with two of the photoresistors and a 1 micro farad capacitor. This way when the photoresistors are blocked (meaning no light getting to them) the RC constant was about a second for the capacitor to fully charge. This then allowed us to code the correct trip times for the servo to trigger releasing the bar on the mouse trap. The servo was hooked up from a ground source, a 3.3V power source, and the SCL pin on the J1 header of the A3BU. This gave us our PWM that was needed to move the servo in the correct manner. Lastly we had a wire soldered to the mouse trap as well as one wrapping around the front of the mouse trap. These wires were then connected to a 220 Ohm resistor and a LED. When the circuit was complete the LED would light up indicating that nothing was caught and the trap needed to be reset.


mousetrap circuit

Mouse Trap: Code

For our final project, we were able to utilize and expand on a good amount of the code we had from Labs 3 and 4. There were two main components to our design which we had to figure out how to integrate with the A3BU- a set of simple photo resistors and a servo motor from a hobby helicopter.

Had we been using an Arduino, we could have used a specific library for servo motors and with a few simple commands get the motor to do what we needed. With the A3BU, figuring out the commands was a little more involved. We started with our PWM code from the fan in lab 4, but none of the values we had used in that lab produced a result. Recognizing that the servo was designed to only actuate for specific signals, we wrote a simple for loop to increment our PWM values and watched to see what values produced a reaction in the servo. We identified a single value which would cause the motor to turn 45°, which was what we needed to release the bar of our trap, and a series of values we could send to reset it to a locked position on command.

if (n1 > (o1*2) || n2 > (o2*2)) //executes if time to charge capacitor doubles from one reading to next.


pwm_set_duty_cycle_percent(&myservo[0],425); //turn servo to release bar, if trap is set


if (read_char == 114) //r for reset



for (i = 171; i < 180; i++) //sends values to turn servo back to starting position


dtostrf(i,3,2,temp_str); //convert float to string


gfx_mono_draw_string(temp_str, 0, 0, &sysfont);







The code to release the bar is executed when a significant change in the light hitting the photo resistors is recorded. The code to reset the bar is called when, after being tripped, the reset command is entered in the terminal.

Our next coding challenge was to get readings from the photo resistors. We wired a simple circuit with just our photo resistor, an LED and an additional resistor. Doing this, we verified the photo resistor was working and that by changing the light hitting the photo resistor, we affected the output voltage of the circuit, causing the LED to dim accordingly. Once we knew a changing voltage was being output, we wired the output to one of the A3BU’s ADC pin. Despite trying many different functions and code examples, we weren’t able to get consistent, satisfactory readings from the ADC pins. After several days of trying, we sought another solution.
By instead running the photo resistors to a capacitor, and wiring them to a GPIO pin, we were able to read the value of light hitting the photo resistor by first discharging the capacitor, then switching the GPIO pin to input mode and incrementing a counter until the capacitor is fully charged. By comparing the time it takes to charge the capacitor with each subsequent reading, we are able to detect sudden large changes in lighting and use this to trigger the trap. A doubling of the time it takes for the capacitor to charge would be enough to set off our trap.

//discharge capacitors

ioport_set_pin_dir(SERVO, IOPORT_DIR_OUTPUT);

ioport_set_pin_dir(PR1, IOPORT_DIR_OUTPUT);

ioport_set_pin_dir(PR2, IOPORT_DIR_OUTPUT);

ioport_set_pin_low( PR1);

ioport_set_pin_low( PR2);


ioport_set_pin_dir(PR1, IOPORT_DIR_INPUT);

//increment counter to determine how long it takes to charge first capacitor

while(ioport_get_pin_level(PR1) != 1)


n1 = n1 + 1;




//increment counter to determine how long it takes to charge second capacitor

ioport_set_pin_dir(PR2, IOPORT_DIR_INPUT);

while(ioport_get_pin_level(PR2) != 1)


n2 = n2 + 1;




if (n1 > (o1*2) || n2 > (o2*2)) //executes if time to charge capacitor doubles from one reading to next.


pwm_set_duty_cycle_percent(&myservo[0],425); //turn servo to release bar, if trap is set

gfx_mono_draw_string("SNAP!          ", 0, 0, &sysfont);

gfx_mono_draw_string("SNAP!          ", 0, 12, &sysfont);

Mouse Trap: Big Picture

The idea behind this lab comes from the inevitable frustration of a mouse invasion. We’ve all been there in the transition from fall to winter when the mice think it’s acceptable to become roommates through the cold weather. Not only have we devised a simpler and cooler solution to this issue, but we’ve perfected the classic mousetrap to make it more user friendly.

The following lab deals with the classic spring-loaded trap. In a normal situation, the user carefully, and sometimes painfully, sets the trap that will deliver a lethal surprise to our furry friends. The next step goes in one of two directions. Typically, the mouse outsmarts the user and makes off with a belly full of cheese and a bigger ego leaving the user frustrated and more determined. If you are lucky enough, the mouse is caught in the deadly trap. In most cases, the location of the trap is hidden and likely to be forgotten about. If the mouse is caught, the smell of it usually informs the user of success because of where it was hidden.

What we propose will increase the likelihood of “mouse-icide” and inform the user to check the trap upon success or failure via LED.

All I/O will be processed by A3BU and communicated via Bluetooth. Communication by Bluetooth may be an addendum for the future depending on the end of the semester class/work load.

–             User will have to prime the mousetrap beneath an arm of our servo. Position of servo indicating primed (0 degrees) or unprimed (> than 0 degrees)

–             Detection of the Mouse above the kill zone will be verified by photoresistors pointing up from the base of the trap.

–             When input from the diodes is received, the A3BU will command a servo to rotate the arm to a threshold value of 20 degrees or more to release the death-bar

–             SCENARIO 1: Mouse is terminated. This is verified by a timer set on the photoresistors. Speaker will sound to make the location of murder easier to find.

–             SCENARIO 2: Mouse somehow escapes and the death-bar completes an electrical connection that sends an input to the A3BU to inform the controller that we failed (which won’t happen).

–             Electronics will be housed in a separate module behind the trap to make the system as discrete as possible. Wire will be routed out beneath the board for inconspicuousness.

The objective of this lab is to simplify the mouse catching process by making it more effective, safer for your fingers, and more detectable.

Fixed variables include:

The food used: Peanut butter creamy and crunchy. It’s cheap and most desirable among mice.

Location: Along the perimeter of the room against a wall. This is typically the most trafficked area of the home with mice.

Bill Of Materials

Photo-resistors            GM5539 (x4)

Mouse traps                  TomCat (x1)

LED’s                                696-SSL-LX5093AGW (x1)

Servo                               HS-430BH (x1)

Resistor                           10K Ohm (x2)

Serial Interface             MAX2332 IC (x1)

Capacitor                        .1uF       (x7)