I was trying to decide what to do, as a 'productive' project with my arduino this weekend, when I stumbled upon my old wired xbox 360 controller, and remembered my RC car that no longer functioned.
Goals in mind, here I go!
RC car stripped down first
Stripped down the controller next
Wired the basic functions of the controller- RB and LB momentary switches, and X & Y axis trimpots from left and right analog joysticks.
Decided to do it this way, reading up on proprietary USB blah blah blah Microsoft junk made using the existing serial communication dang near impossible (or at least way too time consuming for a 'fun' project)
Removed PCB circuit tracing with dremel
Used Cat5 (with salvaged boot from controller USB wire) for signal transfer.
Controller all wired up
Wired cat5 to the RC car functions- 1 pair each for drive motor, steering motor, 'horn', and headlamps.
The arduino was fairly easy to wire up. I used a VCR motor drive chip for the forward and reverse action, and a DPDT relay for left and right steering.
12V 3A external power supply for the motor driver.
And the final outcome:
http://www.youtube.com/watch?v=PEnNImnBWwQ
Still needs some fine-tuning as far as the left/right steering adjustment, and i need to figure out a better horn sound, hahaha.
And here is the simple code for you all to enjoy... or whatever...
Code: Select all
int throttleInPin = A3;
int turnInPin = A2;
int hornInPin = A1;
int lightInPin = A0;
int throttleForwardPin = 3;
int throttleReversePin = 9;
int turnDirectionPin = 5;
int turnAmountPin = 10;
int hornOutPin = 7;
int lightOutPin = 4;
int throttle = 0;
int reverseThrottle = 0;
int turn = 0;
int reverseTurn = 0;
void setup() {
pinMode(throttleForwardPin, OUTPUT);
pinMode(throttleReversePin, OUTPUT);
pinMode(turnDirectionPin, OUTPUT);
pinMode(turnAmountPin, OUTPUT);
pinMode(lightOutPin, OUTPUT);
}
void loop() {
// ** HORN **
if (analogRead(hornInPin) >= 1001)
{
tone(hornOutPin, 700);
}
if (analogRead(hornInPin) <= 1000)
{
noTone(hornOutPin);
}
// ** HEADLIGHTS **
if (analogRead(lightInPin) >= 1001)
{
digitalWrite(lightOutPin, HIGH);
}
if (analogRead(lightInPin) <= 1000)
{
digitalWrite(lightOutPin, LOW);
}
// ** FORWARD & REVERSE **
throttle = map (analogRead(throttleInPin), 512, 1024, 1, 255);
if(throttle >= 50)
{
analogWrite(throttleForwardPin, throttle);
}
else if(throttle < 50 && throttle > -50)
{
throttle = 0;
analogWrite(throttleForwardPin, throttle);
analogWrite(throttleReversePin, throttle);
}
else if (throttle < -50)
{
reverseThrottle = map (throttle, 0, -255, 0, 255);
analogWrite(throttleReversePin, reverseThrottle);
}
// ** LEFT & RIGHT **
turn = map (analogRead(turnInPin), 512, 1024, 1, 255);
if(turn >= 50)
{
digitalWrite(turnAmountPin, HIGH);
digitalWrite(turnDirectionPin, LOW);
}
else if(turn < 50 && turn > -50)
{
turn = 0;
digitalWrite(turnAmountPin, LOW);
digitalWrite(turnDirectionPin, LOW);
}
else if (turn < -50)
{
reverseTurn = map (turn, 0, -255, 0, 255);
digitalWrite(turnDirectionPin, HIGH);
digitalWrite(turnAmountPin, HIGH);
}
}