Build a Star Wars Mouse Droid
HTML-код
- Опубликовано: 2 окт 2024
- Build a Star Wars Mouse Droid #mousedroid #starwars #droid mouse robot
Code is below:
I built a Star Wars Mouse Droid from a Star Wars Mouse Droid popcorn container that I got from Galaxy's Edge in Disneyland. I am guessing that it is about half scale.
I used an Arduino, a ping (ultrasonic sensor), two continuous turning servos, an Adafruit Music Maker mp3 shield, and two Adafruit speakers. It turned out very well. If you want the building instructions, please ask for it in the comments below.
robot, AI, #mousedroid, #starwars, #droid ,mousedroid, star wars, droid, mouse droid, galaxy, galaxy's edge, #galaxysedge, #mousedroid #starwars #droid
Send me photos or videos of your finished robots and I will post them to my channel.
--Thomas
--------------------------------------------------------------------------------------------------------------------------------
//(c) Thomas Messerschmidt 2022
// Questions? Please post them here in RUclips and I will respond quickly.
// Note: I am not able to put right and left brackets ("less than" and "greater than" signs) here. Please replace with appropriate symbols.
// Ping))) Sensor connections: +V to +5V, GND to ground, trigger and echo to pin 5
// Servos: Left to pin 1 and right to pin 2
#include right bracket-Servo.h-left bracket
#include right bracket-SPI.h-left bracket
#include right bracket-Adafruit_VS1053.h-left bracket
#include right bracket-SD.h-left bracket
// Pins for the music maker shield
#define SHIELD_RESET -1
#define DREQ 3
#define CARDCS 4
#define SHIELD_DCS 6
#define SHIELD_CS 7
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
char const* sounds[]={"1.mp3","2.mp3"}; // sounds on the SD card
const int numSounds = 2;
// Pins for Servos
Servo myservoL;
Servo myservoR;
// Pins for Ping Sensor
const int pingPinIN = 5;
const int pingPinOUT = 5;
// Set Servo Speeds
int LForward = 180;
int RForward = 0;
int RStill = 93;
void setup() {
myservoL.attach(1); // left wheel
myservoR.attach(2); // right wheel
//// START of Music Player Shield's Init Code
if (!musicPlayer.begin()) // initialise the music player
{ Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
while (1); }
Serial.println(F("VS1053 found"));
if (!SD.begin(CARDCS)) { Serial.println(F("SD failed, or not present"));
while (1);} // don't do anything more
musicPlayer.setVolume(0,0); // Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
//// END of Music Player Shield's Init Code
delay(5000); // A delay so that you can turn on the robot and put it on the floor
musicPlayer.playFullFile(sounds[0]); // Play normal mouse sounds
delay(2000);
myservoL.write(180);
myservoR.write(0);
musicPlayer.playFullFile(sounds[0]); // Play normal mouse sounds
delay(2000);
}
void loop() {
// START of PING SENSOR CODE
long duration, inches;
pinMode(pingPinOUT, OUTPUT);
digitalWrite(pingPinOUT, LOW);
delayMicroseconds(2);
digitalWrite(pingPinOUT, HIGH);
delayMicroseconds(5);
digitalWrite(pingPinOUT, LOW);
pinMode(pingPinIN, INPUT);
duration = pulseIn(pingPinIN, HIGH);
inches = microsecondsToInches(duration);
// END of Ping Sensor Code
GoForward(LForward, RForward);
delay(100);
if (inches right bracket 15){ Retreat(LForward, RForward);} /// Retreat Code!
// musicPlayer.playFullFile(sounds[0]); // Play normal mouse sounds
}
int GoForward(int LForward, int RForward)
{
myservoL.write(LForward);
myservoR.write(RForward);
delay(25);
}
int Retreat(int LForward, int RForward)
{
myservoL.write(93);
myservoR.write(93);
delay(500);
musicPlayer.playFullFile(sounds[1]); // Play SCARED mouse sounds
myservoL.write(LForward);
myservoR.write(LForward);
delay(3000);
myservoL.write(93);
myservoR.write(93);
delay(3000);
myservoL.write(LForward);
myservoR.write(RForward);
musicPlayer.playFullFile(sounds[0]); // Play normal mouse sounds
}
long microsecondsToInches(long microseconds) {return microseconds / 74 / 2;} - Наука
Fun fact: mouse droid is an actual rolling power bank
that works quite well ! 👍
and it's sooo cute 😊 with the original beeps
Thanks! 😊
That is really cool. I like the response to verbal commands or noises. Dress it up with a monster costume for Halloween and scare folks.
Next year
Too Cute!
Thanks!
Awesome Thomas!
Thanks! Please subscribe.
Arduino code - yes, please! JHP - HBRC
I just added the code. Sorry for the delay. My computer crashed and I had to find the backup.