R2D2 Project(On Going)

Though I am a math major, I often times find myself working on fun computer science, engineering, and robotic projects in my spare time. The most recent of which has been turning an 18″ R2D2 toy I bought from WalMart into a functioning robot.


To begin the project I tore the toy R2D2 apart to see what I had to work with. It became clear right away, that the manufacturer had at some point planned on making the toy robotic as there were many places to mount speakers, motors, and LEDS. 

After taking the R2 apart, I began laying out plans for how I could mount and wire the motors. I then began outlining the general structure of the code needed to drive the R2.

A few weeks passed before I got a chance to return to the R2. It now has two motors in the feet to make it move, and is controlled by an Arduino Uno. I will try to post the code below.

The following link is a video of the first test run to make sure both the motors were wired correctly and the code worked.
Motor Test- Video


Here is a copy of the test code I wrote:

int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface 
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface 
int pinI4=13;//define I4 interface 
int speedpinB=10;//enable motor B
int spead =10000;//defines the speed of motor
void setup()
{
 pinMode(pinI1,OUTPUT);
 pinMode(pinI2,OUTPUT);
 pinMode(speedpinA,OUTPUT);
 pinMode(pinI3,OUTPUT);
 pinMode(pinI4,OUTPUT);
 pinMode(speedpinB,OUTPUT);
}
void forward()//
{
 analogWrite(speedpinA,spead);//input a simulation value to set the speed
 analogWrite(speedpinB,spead);
 digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
 digitalWrite(pinI3,LOW);
 digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
 digitalWrite(pinI1,HIGH);
}
void backward()//
{
 analogWrite(speedpinA,spead);//input a simulation value to set the speed
 analogWrite(speedpinB,spead);
 digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
 digitalWrite(pinI3,HIGH);
 digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
 digitalWrite(pinI1,LOW);
}
void left()//
{
 analogWrite(speedpinA,spead);//input a simulation value to set the speed
 analogWrite(speedpinB,spead);
 digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
 digitalWrite(pinI3,LOW);
 digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
 digitalWrite(pinI1,LOW);
}
void right()//
{
 analogWrite(speedpinA,spead);//input a simulation value to set the speed
 analogWrite(speedpinB,spead);
 digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
 digitalWrite(pinI3,HIGH);
 digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
 digitalWrite(pinI1,HIGH);
}
void stop()//
{
 digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor. 
 digitalWrite(speedpinB,LOW);
 delay(1000);
}
/*
*As I plan on recycling this code as a continue building/upgrading my R2D2
*I added extra code, variations of the "forward()" method, that can be 
*implemented at a later date.
*/
void loop()
{
 forward();
}

It is proving much more difficult than I had originally anticipated to read data from an SD card, and have an Arduino Mega play the data back as sound. I am struggling with the libraries.

I should note on the subject of having the bot playback noise, I have two choices:
-Read a .mp4 file from an SD card
-Translate a .mp4 to a series of integers, store those values into an array and play them back as frequencies at set time intervals.

I prefer the SD card method as it requires the use of less onboard memory. It is my suspicion that the problem I am having is related to how the SD card board is powered.

 


20Feb17

Wow! it’s been a long time since I’ve had a chance to work on R2… I promise R2, you’re the droid I’ve been looking for. I’ve just been busy. Still planning to finish you!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s