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.
|
|
These were the immediate questions that I had about the kit:
-
There's no movable steering bracket, so it'll be fun to test 4WD steering
-
The motors are DC; wonder can I replace them in the future with stepping motors ?
- Probable sensors; compass. wifi or wireless. remote control unit. Ultrasonic distance (for obstructions).
- A lot of fun code for all this !
|
Planning the locations of the battery pack (lower chassis) and electronics (upper).
|
|
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 !
|
|
Starting the electronics with a couple of L293D ICs as motor controllers
|
|
After a lot of wiring; a shift register is unused at the moment.
|
|
Wired up and working with the code below.
|
|
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);
}
|