Cyber Mouse

Introduction: Cyber Mouse

The Cyber Mouse is an innovative product that can be used to entertain cats and kids. This mouse on four wheels can navigate throughout the house on its own using infrared sensors and code from the arduino. It is the perfect toy for a cat because the toy resembles a mouse and cats love chasing mice therefore they would love the toy. The product also has a mouse tail at the end to keep the cat entertained. For those who do not want the CyberMouse to navigate on it's own they can control the moving mouse using an app on their phone to move the toy backwards, forward, left, and right.

Supplies:

- Cardboard

- Hot Glue Gun

- Yarn

- Car with motors

- Wires

- Transistors

- Infrared Sensors

- Infrared Remote

- 9V Battery

- Arduino

- Bluetooth Module

- Bread Board

- Smartphone (Android)

- Paint (

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Making the Cyber Mouse Body

First, ensure you have enough cardboard for your base car with motors and wheels. Paint the cardboard grey by mixing black and white paint equally to create grey paint. After that cut the cardboard so it is the same length as your base but a little bit wider than your base in order to fold up the cardboard and make a cylinder shape. Once that is done using your glue gun glue this piece to your base. After that make the hood piece to your desired length in a triangular shape in order to resemble a mouse's nose. For the trunk, glue a piece to the rear end of the body creating a hinge type of contraption in which you can use to open and close the body. You can put the circuit inside of the mouse opening the door from the back so that the product can look organized. Glue the front hood on to the front of the base and add extra details such as eyes and a nose to the hood piece to make it more realistic. We also added a tail at the end of it so that the cat can be more attracted to the toy

Supplies needed for this step:

-Cardboard

- Hot Glue Gun

- Yarn

- Car with motors

- Paint (White & Black)

Step 2: Making the Circuit

Copy the circuit above and connect it to your "cyber mouse's" motors, and place the circuit inside the mouse using the "door" at the back of the toy.

Step 3: Object Avoidance Code

Copy this code into arduino:

#include

IRrecv receiver (remoteInputPin); decode_results results;

int motorD = 8; int motorS = 9; const int irReceiverPin = 2; const int ledPin = 13; const int irReceiverPin = 2; IRrecv irrecv(irReceiverPin); //create an IRrecv object decode_results decodedSignal; //stores results from IR sensor

void setup() { // put your setup code here, to run once: Serial.begin (9600); receiver.enableIRIn ();

pinMode (motorD, OUTPUT); pinMode (motorS, OUTPUT); } boolean lightState = false; //keep track of whether the LED is on unsigned long last = millis(); //remember when we last received an IRmessage void loop() {if (irrecv.decode(&decodedSignal) == true) //this is true if a message has been received

{ if (millis() - last > 250) { //has it been 1/4 sec since last message digitalWrite (motorD, HIGH); digitalWrite (motorS, HIGH); } last = millis(); irrecv.resume(); // watch out for another message } }

Step 4: Making the Circuit for Controlling It on Your Phone

Build the circuit above

Step 5: Coding the Toy to Control It From Your Phone

Copy the following code into your arduino:

#include "EEPROM.h"
#define D1 2 // direction of motor rotation 1 #define M1 3 // PWM left motor #define D2 4 // direction of motor rotation 2 #define M2 5 // PWM right motor #define HORN 13 // additional channel 1 //#define autoOFF 2500 // milliseconds after which the robot stops when the connection

#define cmdL 'L' // UART-command for left motor #define cmdR 'R' // UART-command for right motor #define cmdH 'H' // UART-command for additional channel (for example Horn) #define cmdF 'F' // UART-command for EEPROM operation #define cmdr 'r' // UART-command for EEPROM operation (read) #define cmdw 'w' // UART-command for EEPROM operation (write)

char incomingByte; // incoming data

char L_Data[4]; // array data for left motor byte L_index = 0; // index of array L char R_Data[4]; // array data for right motor byte R_index = 0; // index of array R char H_Data[1]; // array data for additional channel byte H_index = 0; // index of array H char F_Data[8]; // array data for EEPROM byte F_index = 0; // index of array F char command; // command

unsigned long currentTime, lastTimeCommand, autoOFF;

void setup() { Serial.begin(9600); // initialization UART pinMode(HORN, OUTPUT); // additional channel pinMode(D1, OUTPUT); // output for motor rotation pinMode(D2, OUTPUT); // output for motor rotation /*EEPROM.write(0,255); EEPROM.write(1,255); EEPROM.write(2,255); EEPROM.write(3,255);*/ timer_init(); // initialization software timer }

void timer_init() { uint8_t sw_autoOFF = EEPROM.read(0); // read EEPROM "is activated or not stopping the car when losing connection" if(sw_autoOFF == '1'){ // if activated char var_Data[3]; var_Data[0] = EEPROM.read(1); var_Data[1] = EEPROM.read(2); var_Data[2] = EEPROM.read(3); autoOFF = atoi(var_Data)*100; // variable autoOFF ms } else if(sw_autoOFF == '0'){ autoOFF = 999999; } else if(sw_autoOFF == 255){ autoOFF = 2500; // if the EEPROM is blank, dafault value is 2.5 sec } currentTime = millis(); // read the time elapsed since application start } void loop() { if (Serial.available() > 0) { // if received UART data incomingByte = Serial.read(); // raed byte if(incomingByte == cmdL) { // if received data for left motor L command = cmdL; // current command memset(L_Data,0,sizeof(L_Data)); // clear array L_index = 0; // resetting array index } else if(incomingByte == cmdR) { // if received data for left motor R command = cmdR; memset(R_Data,0,sizeof(R_Data)); R_index = 0; } else if(incomingByte == cmdH) { // if received data for additional channel command = cmdH; memset(H_Data,0,sizeof(H_Data)); H_index = 0; } else if(incomingByte == cmdF) { // if received data for EEPROM op command = cmdF; memset(F_Data,0,sizeof(F_Data)); F_index = 0; } else if(incomingByte == '\r') command = 'e'; // end of line else if(incomingByte == '\t') command = 't'; // end of line for EEPROM op if(command == cmdL && incomingByte != cmdL){ L_Data[L_index] = incomingByte; // store each byte in the array L_index++; // increment array index } else if(command == cmdR && incomingByte != cmdR){ R_Data[R_index] = incomingByte; R_index++; } else if(command == cmdH && incomingByte != cmdH){ H_Data[H_index] = incomingByte; H_index++; } else if(command == cmdF && incomingByte != cmdF){ F_Data[F_index] = incomingByte; F_index++; } else if(command == 'e'){ // if we take the line end Control4WD(atoi(L_Data),atoi(R_Data),atoi(H_Data)); delay(10); } else if(command == 't'){ // if we take the EEPROM line end Flash_Op(F_Data[0],F_Data[1],F_Data[2],F_Data[3],F_Data[4]); } lastTimeCommand = millis(); // read the time elapsed since application start } if(millis() >= (lastTimeCommand + autoOFF)){ // compare the current timer with variable lastTimeCommand + autoOFF Control4WD(0,0,0); // stop the car } }

void Control4WD(int mLeft, int mRight, uint8_t Horn){

bool directionL, directionR; // direction of motor rotation L298N byte valueL, valueR; // PWM M1, M2 (0-255) if(mLeft > 0){ valueL = mLeft; directionL = 0; } else if(mLeft < 0){ valueL = 255 - abs(mLeft); directionL = 1; } else { directionL = 0; valueL = 0; } if(mRight > 0){ valueR = mRight; directionR = 0; } else if(mRight < 0){ valueR = 255 - abs(mRight); directionR = 1; } else { directionR = 0; valueR = 0; } analogWrite(M1, valueL); // set speed for left motor analogWrite(M2, valueR); // set speed for right motor digitalWrite(D1, directionL); // set direction of left motor rotation digitalWrite(D2, directionR); // set direction of right motor rotation digitalWrite(HORN, Horn); // additional channel }

void Flash_Op(char FCMD, uint8_t z1, uint8_t z2, uint8_t z3, uint8_t z4){

if(FCMD == cmdr){ // if EEPROM data read command Serial.print("FData:"); // send EEPROM data Serial.write(EEPROM.read(0)); // read value from the memory with 0 address and print it to UART Serial.write(EEPROM.read(1)); Serial.write(EEPROM.read(2)); Serial.write(EEPROM.read(3)); Serial.print("\r\n"); // mark the end of the transmission of data EEPROM } else if(FCMD == cmdw){ // if EEPROM data write command EEPROM.write(0,z1); // z1 record to a memory with 0 address EEPROM.write(1,z2); EEPROM.write(2,z3); EEPROM.write(3,z4); timer_init(); // reinitialize the timer Serial.print("FWOK\r\n"); // send a message that the data is successfully written to EEPROM } }

Step 6: Controlling It From Your Phone

Download ArduDroid

Go on the app and select connect device and connect the bluetooth device used on the cyber mouse circuit and connect it to your phone

There Will be 4 buttons displayed on the screen; forward, back, left, and right. Use these buttons to control your mouse.

Be the First to Share

    Recommendations

    • Magnets Challenge

      Magnets Challenge
    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest

    Discussions