The Start


Hi, What and Why

Plug it in

Rule number 1

Water Sensor

Sound Sensor

Joystick

Tri Colour LED

RTC (Real Time Clock) DS1302

RTC (Real Time Clock) DS3231

Matrix LED step 1

LCD

Stepper Motor

LCD revisited with PCF8574T

Humidity Sensor

Shift Register

RFID tags (RC-522)

7 Segment display

Ultrasonic distance sensor

5V regulator

analogRead and analogWrite

Wiring an Array of Switches

The next step


Other things I have bought

Infra red and Processing

Programming a separate arduino chip

Creating your own PCB

L293D for a DC motor

4 digit 7 segment display

Starting with motors

RF433 Wireless Comms

Sort a character array

More stuff


I2C devices (SDA,SCL)

I2C scanner

SPI devices (MOSI,MISO)

HMC5883L Compass

MMA7361 Accelerometer

Added projects


Message Display System

4WD robot car
4WD robot car II

4WD robot car COMPLETE

MP3 Player

A 4WD remote controlled car

I wanted to start putting together some of what I had learned, and the best reward is always something that moves. I hunted for quite a while for motors, but ran into issues with finding gears. (If anyone knows where I can buy a bag of 50 or 100 plastic gears with assorted spindle sizes from 2mm up, then do leave a comment.)

Anyway, I was thrilled when I found this entire kit. It's a 4 wheel drive car chassis, and I quite liked the style as well.

The kit contains 4 geared motors, wheels, and a chassis in clear plastic.
It arrived the day; first class service from chemilia0902 on EBay (UK). Hope he enjoys the plug; I'm not affiliated in any way, I just really appreciate speedy service.

My 4WD car chassis kit.
The chassis has the protecting layer on at the mo.
4 motors, one already fixed in. 4 wheels.

There's also another 'wheel' to attach inside the chassis, that you can just see. I think it can be used for measuring distance. More on that later.
4WD car kit

These were the immediate questions that I had about the kit:

Planning the locations of the battery pack (lower chassis) and electronics (upper). Assembly 1

Note that wheel, bottom right of the pic, inside the chassis. Distance measurement device ?

Upper chassis fits on. Have forgotten to remove the brown paper protective covering !
Assembly 2
Starting the electronics with a couple of L293D ICs as motor controllers
Assembly 3
After a lot of wiring; a shift register is unused at the moment.
Assembly 3
Wired up and working with the code below.
Assembly 3
It's still using the main arduino, and the USB cable for +5V power for the circuit.
The motors are driven by the 9V battery pack below.
It works with this code below. (Works = the wheels go around, forwards and backwards, and each wheel at a speed that I control)
Clearly this code, which is based on a tutorial, needs to be rewritten as the next step, and then I can start to test turning corners.
		   /*
 *  CIRC-22 Controlling Motors (L293D)
 * 
 * A demo program which demonstrates how to control two
 * DC motors
 * For more details and links visit: http://tinyurl.com/nsuwln
 */
 
 
//L293 Pin assignments


//Motor one
int m1_enable = 3;  //bridge 1 and 2 enable (pin 1 on the 16 pin IC) 
                   //pull this pin HIGH to turn the outputs on and LOW to turn them off
                   //using PWM on this puin will control speed
int m1_forward      = 2;  //m1_forward (out1 will be HIGH when set HIGH and LOW when set LOW) (pin 2 on the 16 pin IC)
int m1_backward      = 4;  //m1_backward (out2 will be HIGH when set HIGH and LOW when set LOW) (pin 7 on the 16 pin IC)

//Motor two
int m2_enable = 5;  //bridge 1 and 2 enable (pin 1 on the 16 pin IC)
                    //pull this pin HIGH to turn the outputs on and LOW to turn them off
                    //using PWM on this puin will control speed
int m2_forward      = 7;  //m1_forward (out1 will be HIGH when set HIGH and LOW when set LOW) (pin 2 on the 16 pin IC)
int m2_backward      = 6;  //m1_backward (out2 will be HIGH when set HIGH and LOW when set LOW) (pin 7 on the 16 pin IC)

//Motor 3
int m3_enable = 10;
int m3_forward = 8;
int m3_backward = 9;

//Motor 4
int m4_enable = 13;
int m4_forward = 12;
int m4_backward = 11;


void setup(){
  pinMode(m1_enable, OUTPUT);  //Set the three pins for bridge 1 & 2 to outputs
  pinMode(m1_forward, OUTPUT);
  pinMode(m1_backward, OUTPUT);

  pinMode(m2_enable, OUTPUT);  //Set the three pins for 3 & 4 to outputs
  pinMode(m2_forward, OUTPUT);
  pinMode(m2_backward, OUTPUT); 
  
  pinMode(m3_enable, OUTPUT);  //Set the three pins for bridge 1 & 2 to outputs
  pinMode(m3_forward, OUTPUT);
  pinMode(m3_backward, OUTPUT);

  pinMode(m4_enable, OUTPUT);  //Set the three pins for 3 & 4 to outputs
  pinMode(m4_forward, OUTPUT);
  pinMode(m4_backward, OUTPUT);  
}

void loop(){
  setSpeedMotor_1(255);     //Set the speed of motor one 255 = on 0 = off (simply a call to analogWrite on m1_enable pin)
  setSpeedMotor_2(255);     //Set the speed of motor two 255 = on 0 = off (simply a call to analogWrite on m2_enable pin)  
  setSpeedMotor_3(255);     //Set the speed of motor one 255 = on 0 = off (simply a call to analogWrite on m1_enable pin)
  setSpeedMotor_4(255);     //Set the speed of motor two 255 = on 0 = off (simply a call to analogWrite on m2_enable pin)  

  motor_1_Forward();         //Spin motor one forwards (set one bridge HIGH and the other LOW)
  motor_2_Forward();        //Spin motor two backwards (set one bridge LOW and the other HIGH)
  motor_3_Forward();         //Spin motor one forwards (set one bridge HIGH and the other LOW)
  motor_4_Forward();        //Spin motor two backwards (set one bridge LOW and the other HIGH)
  delay(1000);               //wait for a second
  
  brakeMotor_1();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  brakeMotor_2();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  brakeMotor_3();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  brakeMotor_4();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  delay(1000);               //wait for a second

  motor_1_Backward();        //Spin motor one backwards (set one bridge LOW and the other HIGH)
  motor_2_Backward();         //Spin motor two forwards (set one bridge HIGH and the other LOW)
  motor_3_Backward();        //Spin motor one backwards (set one bridge LOW and the other HIGH)
  motor_4_Backward();         //Spin motor two forwards (set one bridge HIGH and the other LOW)
  delay(1000);  //wait for a second
  
  brakeMotor_1();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  brakeMotor_2();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  brakeMotor_3();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  brakeMotor_4();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  delay(1000);               //wait for a second

  setSpeedMotor_1(150);     //Set the speed of motor one 255 = on 0 = off (simply a call to analogWrite on m1_enable pin)
  setSpeedMotor_2(150);     //Set the speed of motor two 255 = on 0 = off (simply a call to analogWrite on m2_enable pin)  
  setSpeedMotor_3(150);     //Set the speed of motor one 255 = on 0 = off (simply a call to analogWrite on m1_enable pin)
  setSpeedMotor_4(150);     //Set the speed of motor two 255 = on 0 = off (simply a call to analogWrite on m2_enable pin)  


  motor_1_Forward();         //Spin motor one forwards (set one bridge HIGH and the other LOW)
  motor_2_Forward();        //Spin motor two backwards (set one bridge LOW and the other HIGH)
  motor_3_Forward();         //Spin motor one forwards (set one bridge HIGH and the other LOW)
  motor_4_Forward();        //Spin motor two backwards (set one bridge LOW and the other HIGH)
  delay(1000);               //wait for a second
  
  brakeMotor_1();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  brakeMotor_2();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  brakeMotor_3();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  brakeMotor_4();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  delay(1000);               //wait for a second

  motor_1_Backward();        //Spin motor one backwards (set one bridge LOW and the other HIGH)
  motor_2_Backward();         //Spin motor two forwards (set one bridge HIGH and the other LOW)
  motor_3_Backward();        //Spin motor one backwards (set one bridge LOW and the other HIGH)
  motor_4_Backward();         //Spin motor two forwards (set one bridge HIGH and the other LOW)
  delay(1000);  //wait for a second
  
  brakeMotor_1();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  brakeMotor_2();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  brakeMotor_3();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  brakeMotor_4();           //by leaving the bridge on the motors are braked (stop quicker than setting the speed to zero) (sets both sides of the bridge to LOW)
  delay(1000);               //wait for a second


}

////// Motor One Routines  ////////////

void motor_1_Forward(){
 digitalWrite(m1_forward, LOW); 
 digitalWrite(m1_backward, HIGH); 
}
void motor_2_Forward(){
 digitalWrite(m2_forward, LOW); 
 digitalWrite(m2_backward, HIGH); 
}
void motor_3_Forward(){
 digitalWrite(m3_forward, LOW); 
 digitalWrite(m3_backward, HIGH); 
}
void motor_4_Forward(){
 digitalWrite(m4_forward, LOW); 
 digitalWrite(m4_backward, HIGH); 
}

void motor_1_Backward(){
 digitalWrite(m1_forward, HIGH); 
 digitalWrite(m1_backward, LOW); 
}   

void motor_2_Backward(){
 digitalWrite(m2_forward, HIGH); 
 digitalWrite(m2_backward, LOW); 
}   
void motor_3_Backward(){
 digitalWrite(m3_forward, HIGH); 
 digitalWrite(m3_backward, LOW); 
}   

void motor_4_Backward(){
 digitalWrite(m4_forward, HIGH); 
 digitalWrite(m4_backward, LOW); 
}   


void setSpeedMotor_1(int newSpeed){
  analogWrite(m1_enable, newSpeed);
}
void setSpeedMotor_2(int newSpeed){
  analogWrite(m2_enable, newSpeed);
}
void setSpeedMotor_3(int newSpeed){
  analogWrite(m3_enable, newSpeed);
}
void setSpeedMotor_4(int newSpeed){
  analogWrite(m4_enable, newSpeed);
}

void brakeMotor_1(){
 digitalWrite(m1_forward, LOW); 
 digitalWrite(m1_backward, LOW); 
} 
void brakeMotor_2(){
 digitalWrite(m2_forward, LOW); 
 digitalWrite(m2_backward, LOW); 
}   
void brakeMotor_3(){
 digitalWrite(m3_forward, LOW); 
 digitalWrite(m3_backward, LOW); 
} 
void brakeMotor_4(){
 digitalWrite(m4_forward, LOW); 
 digitalWrite(m4_backward, LOW); 
}