Interactable Pet

by Asha19_A in Circuits > Arduino

44 Views, 1 Favorites, 0 Comments

Interactable Pet

20250127_085529.jpg
Screenshot 2025-01-22 151342.png

In this Project, it is basically a robotic pet that when something is detected the LEDs change colours and the tail of it moves. I got this idea, from Hatchimals as I always wanted it growing up and thought this would be the perfect time to make it come true. Although there are many things I can fix, this is a tutorial on how to get started!

Tinkercad link: https://www.tinkercad.com/things/3DiUqAUMNtF-daring-duup/editel?returnTo=https%3A%2F%2Fwww.tinkercad.com%2Fdashboard

Supplies

Screenshot 2025-01-22 151647.png

This circuit uses the following:

1x Ultrasonic Sensor | Cost: $8.12

2x Servo Motor | Cost: $5.84 each

6x RGB LED's | Cost $9.99

1x Breadboard | Cost: $6.54

3x 330 Ohms Resistor | Cost: $0.16

4x Male/Female Wires | Cost: $1.99

Wires | Cost $16.99

Cardboard | Cost: $1.49

Wiring

20250123_100935.jpg

Using the appropriate wires connect the following to the corresponding pin:

RGB (green) = pin 4

RGB (red) = pin 3

RGB (blue) = pin 2

RGB (anode) = Power/ Positive rail

Ultrasonic sensor (Trig) = pin 13

Ultrasonic sensor (echo) = pin 12

Servo motor = pin 5

The Code

Upload the following code to your Arduino:

#include <Servo.h>

Servo myservo;
int pos = 0;
int trig = 13;
int echo = 12;
int red = 4;
int green = 3;
int blue = 2;
long duration, inches;

void setup() {
Serial.begin(9600);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
myservo.attach(5);
}

void loop() {
delay(10);
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
inches = duration / 74 / 2;
Serial.println(inches);

if (inches > 4) {
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
else {
for (pos = 0; pos <= 90; pos++) {
myservo.write(pos);
delay(15);
}
for (pos = 90; pos >= 0; pos--) {
myservo.write(pos);
delay(15);
}
digitalWrite(red, HIGH);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
delay(2000);
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
digitalWrite(blue, LOW);
delay(2000);
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, HIGH);
delay(2000);
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
}


This code makes it so that when the ultrasonic sensor detects something the servo motors turn 90 degree then to its original position. Afterwards the RGB changes to from its normal state to red, to green, then to blue, then changing back to original form, waiting until something is detected again.

Downloads

Prop

20250123_100631.jpg

Create a animal of your choice using cardboard. Afterwards stick a piece of cardboard on each servo motor to create the illusion that its moving. Moreover make sure that your Ultrasonic sensor is visible so that it can work properly. The picture above is the final product of mine, although it isn't the best it still works as intended.