You are on page 1of 6

Build a Mouse Trap Using Arduino UNO

Made by:
Jhon Lemuel Borines
Bryan Paul Permejo
Dan Wilbert Rodriguez
1

6 5

4 3
7

1 . Arduino Uno
2 . Servo
3 . Buzzer
4 . Ultrasonic sensor Project cost:
5 . Green led )
6 . Yellow led
7 . 220 ohm resistor
Arduino Uno P175.00
Servo Motor P176.00
Buzzer P44.00
Ultrasonic sensor Owned
Led 2pcs P10.00
330m Resistors P5.00
Bread Board Owned
Jumper Wire Owned
Plywood Owned
Blue Paint (Quick Dry) Owned
Live mouse Small/Large P110.00
Mouse trap P150.00
Total cost: P670.00
Project Development
The code
#include <Servo.h>//include the servo library

int redpin = 5;//name digitalpin 5 as redpin(it is our red led)

int greenpin = 6;//name digital pin 6 as greenpin(it is our green led)

int trigpin = 7;//name pin 7 as trigpin orange

int ecopin = 8;//name pin 8 as ecopin violet

Servo servo1;//name our servo as servo1

int distance, duration;//make two variables named distance and duration

int buzzer = 10;//name pin 10 as buzzer

void setup() {

// put your setup code here, to run once:

pinMode(redpin, OUTPUT);//set redpin as output

pinMode(greenpin, OUTPUT);//set greenpin as output

pinMode(trigpin, OUTPUT);//set the trigpin as output

//ultrasonic sensor as output

pinMode(buzzer, OUTPUT);//set the buzzer as output

pinMode(ecopin, INPUT);//set the echopin of ultrasonic sensor as input

servo1.attach(2);//attach the servo to pin 2

Serial.begin(115200);

void loop() {

// put your main code here, to run repeatedly:

digitalWrite(trigpin, LOW);//activate the trigpin

delayMicroseconds(2000);//activate the trigpin

digitalWrite(trigpin, HIGH);//activate the trigpin

delayMicroseconds(15);//activate the trigpin

digitalWrite(trigpin, LOW);//activate the trigpin

delayMicroseconds(10);//activate the trigpin

duration = pulseIn(ecopin, HIGH);//define the duration


distance = (duration/2)/29.1;//define the distance (don't worry if you didn't understand the code all it
does is that it //converts the time into distance

if(distance <=20)//if the distance is less than 15 cm then

digitalWrite(redpin, HIGH);//turn the red led on

digitalWrite(greenpin, LOW);//turn the green led off

servo1.write(180);//turn the servo 180 egree

digitalWrite(buzzer, HIGH);//turn the buzzer on

delayMicroseconds(2000);

Serial.println("The mouse has been Catch!");

else

digitalWrite(greenpin, HIGH);//turn the green led on

digitalWrite(redpin, LOW);//turn the red led off

digitalWrite(buzzer, LOW);//turn the buzzer off

servo1.write(0);//turn the servo to zero degree

delayMicroseconds(32000);

Serial.println("The cage is empty :<");

• With the help of Dan's father, we created the box


for the security of other device and wires then we
painted it blue.

You might also like