Sad Cat Fixer Toy
This instructable is a toy to make a sad cat happy. It is in the shape of a rectangular box with a small hole in the middle. The hole is big enough for the cat to stick its paw inside. In the hole is a servo rotating a toy mouse in a clockwise direction. There are buttons inside at the back of the box that runs the program when they are pressed. Two buttons control the rotation of the servo and make it rotate fully. One button controls a RGB and turns on the RGB when it is pressed. The RGB then flashes red for five seconds, then green for five seconds, and finally blue for five seconds.
Supplies
- Servo Motor
- Breadboard
- Arduino board
- 3 Buttons
- Toy Mouse
- RGB
- 2 LED's
- Resistors
- Cardboard Box - big enough for a cat to stick its paw inside of it
- Optional: Cat mat
Cut Out Hole in the Middle of Cardboard Box
Make sure the hole you cut out is big enough for a cat to stick its paw inside.
Build Your Circuit Using a Breadboard
Follow the circuit diagram to build your circuit.
Program the Circuit
Now it's time to program what you have built, go to Arduino and add the following code:
/**************************************************************/
//Name: Sad Cat Fixer
/*Description: Toy for sad cat that rotates servo when pressing and holding button.
Turns RGB on whe pressing and holding button. RGB flashes red for five seconds,
then green for five seconds, and finally blue for five seconds then turns off*/
//Programmer: Balraj Mor
//Date: 2021.12.20
//Pins connected(2, 3, 5, 6, 9, 10, 11)
/**************************************************************/
// include the library code
#include <Servo.h>
/*************************************************/
//Global Variables:
/*************************************************/
Servo myservo; //create servo object to control a servo
const int sensorMin = 0;
const int sensorMax = 400;
int rotation = 0; // Variabvle for the rotation of the servo motor
int angle = 90; // Sets angle of the servo motor to 90
int pushButton; // Variable to check if the button was pushed
const int button = 5; // button pin number
const int LED1 = 2; // player's 1 LED is connected to pin 2
const int LED2 = 3; // player's 2 LED is connected to pin 3
const int redPin = 11; // R petal on RGB LED module connected to digital pin 11
const int greenPin = 9; // G petal on RGB LED module connected to digital pin 9
const int bluePin = 10; // B petal on RGB LED module connected to digital pin 10
/**************************************************************/
//Setup Function: This code runs once
/**************************************************************/
void setup() {
Serial.begin(9600); // start serial port at 9600 bps:
myservo.attach(6); //attaches the servo on pin 6 to servo object
pinMode(LED1, OUTPUT); // sets LED1 as an output
pinMode(LED2, OUTPUT); // sets LED2 as an output
pinMode(redPin, OUTPUT); // sets the redPin to be an output
pinMode(greenPin, OUTPUT); // sets the greenPin to be an output
pinMode(bluePin, OUTPUT); // sets the bluePin to be an output
pinMode(button, INPUT); // sets the button as an input
}
/**************************************************************/
//Loop Function: This code runs forever
/**************************************************************/
void loop() {
pushButton = digitalRead(button);
if (pushButton == HIGH){ // checks if the button was pressed
digitalWrite(redPin, HIGH);// turn the red pin on
delay(5000); // delay for 5000 microseconds
digitalWrite(redPin, LOW); // turn the red pin off
digitalWrite(greenPin, HIGH);// turn the green pin on
delay(5000); // delay for 5000 microseconds
digitalWrite(greenPin, LOW); // turn the green pin off
digitalWrite(bluePin, HIGH);// turn the blue pin on
delay(5000); // delay for 5000 microseconds
digitalWrite(bluePin, LOW); // turn the blue pin off
}
else{
digitalWrite(redPin, LOW);//turn the red pin off
digitalWrite(greenPin, LOW);//turn the green pin off
digitalWrite(bluePin, LOW);//turn the blue pin off
}
rotation = map(analogRead(A0), 0, 1023, 0,2); // map for the rotation of the servo
Serial.println(analogRead(A0));
Serial.println(rotation); // Prints the angle the servo rotates on the serial monitor
switch (rotation) { // switch for the rotation of the servo
case 1:
if (angle < 180) { // Checks if the angle is less than 180
::angle+=4;
digitalWrite(LED1, LOW); // Turns LED1 off
Serial.println(rotation); // Prints what the rotation is on the serial monitor
Serial.println(angle); // Prints what the angle is on the serial monitor
myservo.write(angle); // rotates the servo which is dependent on what the angle is
digitalWrite(LED2, HIGH); // Turns LED2 on
delay(25); // delay for 25 microseconds
}
break;
case 2:
if (angle > 0) { // Checks if the angle is greater than 0
::angle-=4;
digitalWrite(LED2, LOW); // Turns LED2 off
Serial.println(rotation); // Prints what the rotation is on the serial monitor
Serial.println(angle); // Prints what the angle is on the serial monitor
myservo.write(angle); // rotates the servo which is dependent on what the angle is
digitalWrite(LED1, HIGH); // Turns LED1 on
delay(25); // delay for 25 microseconds
}
break;
default:
delay(10); // delay for 10 microseconds
}
}
Add the Toy Mouse to the Servo
After programming your circuit, find some sort of small toy that can be attached to a servo and it doesn't have to be a mouse. It's best to choose a toy that your cat would like to play with.
Place Your Circuit Inside the Box
Make sure you put something soft under your breadboard and Arduino board to make sure it's secure.
Optional: Place Cat Mat in Front of the Box to Make It Attractive to a Cat
This step is optional, but if you have a cat mat place it in front of your project.
Test to Make Sure Everything Works
Run your toy multiple times to make sure everything runs smoothly.