Genesis of the Arduino Dalek

As previously mentioned here, I was recently given a broken toy Dalek, which I promptly took apart (in the name of Science).

Here it is before surgery commenced…

dalek-1

Having stripped the thing down, I found inside two perfectly good electric motors, and when you find two working motors inside a toy there is only one thing to do: Work out how to use a computer to control them!

So, figuring out that the easiest way of doing this was with an Arduino, I bought one.

I won’t bleat on about how good the Arduino is, or how easy it is to use. There are hundreds of sites that do that.

Instead, here is a list of things wot i dun to get a PC controlling the Dalek.

To start with, I think we’ll have a bit of circuit design. Below is a simple circuit that takes 2 inputs from the Arduino and runs a motor either forwards or backwards. One input decides the direction of the motor, the other whether it is on or off.

relay-circuit

All very nice and abstract, but to be of any use it’ll need to be built. The quickest and easiest way is on Veroboard. So here is the design for that:

relay-vero

The relays do the switching, and the diodes are there to protect the Arduino from back-emf currents when the relays toggle. Two of these circuits will be used, one for each motor. I built them on separate strips of board to make things easier for myself. This is what they look like when all connected up and dumped onto the Dalek chassis:

dalek-wired1

The small board in the top left of the picture is just a plug I bodged up to make connecting the thing easier.

The parts used are 4x 1A5VDC DPDT relays, 4x 1N4004 diodes, a 10×39 strip of Veroboard and some wires.

After all that soldering and burning my fingers, the next step is to write some code to make the thing move.

Each motor can be controlled to go backwards, forwards or stop. This gives nine possible movements, as this table shows:

dalek-matrix

And now its time to test this whole think by writing a program that takes keyboard commands (the letters in red, above) and sending signals to the circuitry to control the motors. Heres it is:

// Project: Dalek control system
// Version 0.1 - Written before my Arduino even arrived
// Tony Blews tony@tonyblews.co.uk

int MotorDirectionR = 10;
int MotorDirectionL = 11;
int MotorPowerR     = 12;
int MotorPowerL     = 13;

void setup()
{
 pinMode(MotorDirectionR, OUTPUT);
 pinMode(MotorDirectionL, OUTPUT);
 pinMode(MotorPowerR, OUTPUT);
 pinMode(MotorPowerL, OUTPUT);

 Serial.begin(9600);
 Serial.println("Serial control Dalek system starting...");

}

// modes for the motor control
// convention here is modeXX - where X is F for forward, S for stationary and B for backwards
// first X is the left motor, second X is the right one
// for direction control, the LOW if forward and HIGH is backward
// for power control, LOW is off and HIGH is on

// all stop
void modeSS()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,LOW);
 digitalWrite(MotorPowerL,LOW);
}

// move straight ahead
void modeFF()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

// move straight backwards
void modeBB()
{
 digitalWrite(MotorDirectionR, HIGH);
 digitalWrite(MotorDirectionL, HIGH);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

// spin left
void modeBF()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, HIGH);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

//spin right
void modeFB()
{
 digitalWrite(MotorDirectionR, HIGH);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,HIGH);
}

// move forward left
void modeSF()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,LOW);
}

// move forward right
void modeFS()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,LOW);
 digitalWrite(MotorPowerL,HIGH);
}

// move backward left
void modeSB()
{
 digitalWrite(MotorDirectionR, HIGH);
 digitalWrite(MotorDirectionL, LOW);
 digitalWrite(MotorPowerR,HIGH);
 digitalWrite(MotorPowerL,LOW);
}

// move backward right
void modeBS()
{
 digitalWrite(MotorDirectionR, LOW);
 digitalWrite(MotorDirectionL, HIGH);
 digitalWrite(MotorPowerR,LOW);
 digitalWrite(MotorPowerL,HIGH);
}

//main program loop
void loop()
{
 if (Serial.available() >0)
 {
 char inByte = Serial.read();
 // this version uses the QWEASDZXC "square" on the keyboard
 // as my laptop doesn't have a numeric keypad
 switch (inByte)
 {
 case 'q':
 modeSF();
 break;
 case 'w':
 modeFF();
 break;
 case 'e':
 modeFS();
 break;
 case 'a':
 modeBF();
 break;
 case 's':
 modeSS();
 break;
 case 'd':
 modeFB();
 break;
 case 'z':
 modeBS();
 break;
 case 'x':
 modeBB();
 break;
 case 'c':
 modeSB();
 break;
 default:
 modeSS();
 break;
 }
 }
}

And with that done, I suppose all that is left to do is show a video of the bottom bit of the dalek trundling around under computer control…

… which have to wait until the next post.

Leave a Reply