Blog - Sketching with Hardware

Mouse Catch

Published on: | Author: Ehsan Nezamolislami | Categories: 2016b, Best Projects, Projects

MouseCatch_2MouseCatch_1

In little time we decided to have the paper chasing tested by quickness and agility. After we sat down and let our creative juices flow it was clear that we would build a car. But not only a car. It would be prepared to look like a mouse. You have to catch the mouse.

USING PARTS:
Acrylic Ground // Arduino // H-Bridge // Motor // 2Tires // 2Ultrasonic Sensors // Infrared Sensor // Speaker

MouseCatch_6

Let’s begin with the most important part. The motor and the tires.
The Arduino is connected to a H-Bridge which contains 4 transistors so we are able to switch plus and minus pole making the tires go forward and backward.
We are using up to three 9V Batteries giving the motors enough power to speed up. Providing  every chance to make the chase after the mouse as thrilling as possible.

To make sure the mouse never hits a wall or something we installed a ultrasonic sensor in front of the vehicle. The Sensor gives the Arduino information to turn over if it’s near to hit a wall.

Our vehicle is easy to break. In order to protect it we must find a way that people chasing it don’t need to touch it but can catch it. We installed an ultrasonic sensor on top of the mouse. By holding your hand above the mouse you interact with the sensor and the mouse will stop.
But not only it will stop and the chase has ended. The mouse is making noises, too.

Now that you caught the mouse you can take the notice off it. The notice will tell you were the next task of the paper chase is taking place.
Although it’s able to start the chase again using a remote that sends information to the infrared sensor we installed in the vehicle aswell.

CatchMouse_3MouseCatch_4

CODE:

#include <IRremote.h>

// rigth motor pins
int IN1 = 7;
int IN2 = 6;

// left motor pins
int IN3 = 5;
int IN4 = 4;

// ultrasonic sensor front
const unsigned int PING_SENSOR_IO_PIN = 8;
const unsigned int BAUD_RATE = 9600;
//long distance1 = 0;

// ultrasonic sensor top
int trigger = 10;
int echo = 11;
long duration = 0;
long distance = 0;

// the mouse was caught
boolean caught = false;
boolean startMouse = false;

// turnLeft
boolean leftTurn = false;

// IR-Sensor (remote)
int RECV_PIN = 9;
IRrecv irrecv(RECV_PIN);

decode_results results;

// servo

// piezo speaker
int piezoSpeaker = 13;
int time = 10;

unsigned long microseconds_to_cm(const unsigned long microseconds) {
return microseconds / 29 / 2;
}

void setup() {

// IR-Sensor
pinMode(9, OUTPUT);
irrecv.enableIRIn();

// pin 1,2, 3 and 4 declare as output
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);

// ultrasonic sensor top
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);

// Piezo Speaker
pinMode(piezoSpeaker, OUTPUT);

}

void loop() {

// IR-Sensor
if (irrecv.decode(&results)) {
// reset vehicle
if(results.value == 16724175) {
startMouse = true;
//time = 100;
}

// stop vehicle
if(results.value == 16718055) {
startMouse = false;
}

irrecv.resume(); // receive the next value
}

// ultrasonic sensor front
unsigned long distance1 = ultrasonicSensorFront();

// ultrasonic sensor top
long distance2 = ultrasonicSensorTop();

if(startMouse) {

if (distance2 <= 3) {
caught = true;
startMouse = false;
}

if (caught == true) {
startMouse = false;
turnSpeakerOn();
}

if (startMouse) {
if (distance1 <= 130) {
stopVehicle();
delay(1000);
TurnMouse();
delay(1000);
}

startVehicle();

if (distance2 <= 3) {
caught = true;
startMouse = false;
}
}
}
else {
stopVehicle();
if (caught == true) {
if (time > 0)
turnSpeakerOn();
}
}

}

void turnSpeakerOn() {
if (time > 0) {
digitalWrite(piezoSpeaker, HIGH);
delay(15);
digitalWrite(piezoSpeaker, LOW);
delay(15);
time–;
}
}

unsigned long ultrasonicSensorFront() {

pinMode(PING_SENSOR_IO_PIN, OUTPUT);
digitalWrite(PING_SENSOR_IO_PIN, LOW);
delayMicroseconds(2);

digitalWrite(PING_SENSOR_IO_PIN, HIGH);
delayMicroseconds(5);
digitalWrite(PING_SENSOR_IO_PIN, LOW);

pinMode(PING_SENSOR_IO_PIN, INPUT);
const unsigned long duration = pulseIn(PING_SENSOR_IO_PIN, HIGH);

return microseconds_to_cm(duration);
}

long ultrasonicSensorTop() {

digitalWrite(trigger, LOW);
delay(5);
digitalWrite(trigger, HIGH);
delay(10);
digitalWrite(trigger, LOW);

duration = pulseIn(echo, HIGH);
distance = (duration/2) / 29.1;

// return distance in cm
return distance;
}

void startVehicle() {
//in this case both motors rotate forward
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}

void stopVehicle() {
// turn power off
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}

void TurnMouse() {

digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}

MouseCatch_5

Ehsan Nezamolislami & Laurenz Dallinger

linked categories 2016b, Best Projects, Projects

|

Write a comment

Comment