Adam Mansour
Created November 10, 2015

Project Two: Final Remote Control Car

Full instructions provided313
Project Two: Final Remote Control Car

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
L298 H-bridge
×1
9V battery and battery pack
×1
4 AA batteries and 6V battery pack
×1
1 Perfboard
×1
1 protoshield
×1
4 switches
×1
4 1-in screws and corresponding nuts and washers
×1
DC motor (generic)
And 2 wheels that fit, along with 1 marble
×2
rubber wheels
×1
stranded wire
×1
solid core wire
×1
heat shrink wrap
×1
CA glue
×1

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

The vehicle base

Laser cut acrylic for the base

The top of the remote casing

The bottom of the remote casing

Spacers for the inside of the remote casing

Schematics

Schematic

Code

Code for steering control

C/C++
const int switchPinLeft = 12;    // switch input
const int switchPinRight = 9;    // Enable for Motor 1
const int switchPinForward = 10;    // Enable for Motor 2
const int switchPinBackward = 11;
const int switchPinStation = 13;
const int motor1Pin = 7;    // H-bridge leg 1 (pin 2, 1A)
const int motor2Pin = 6;    // H-bridge leg 2 (pin 7, 2A)
const int motor3Pin = 3;    // H-bridge leg 3 (pin 10, 3A)
const int motor4Pin = 2;    // H-bridge leg 4 (pin 15, 4A)
int buttonStateLeft = LOW;
int buttonStateRight = LOW;
int buttonStateForward = LOW;
int buttonStateBackward = LOW;
int buttonStateStation = LOW;

void setup() {
  // set the switch as an input:
  pinMode(switchPinLeft, INPUT_PULLUP);
  pinMode(switchPinRight, INPUT_PULLUP);
  pinMode(switchPinForward, INPUT_PULLUP);
  pinMode(switchPinBackward, INPUT_PULLUP);
  pinMode(switchPinStation, INPUT_PULLUP);


  // set all the other pins you're using as outputs:
  pinMode(switchPinLeft, OUTPUT);
  pinMode(switchPinRight, OUTPUT);
  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
  pinMode(motor3Pin, OUTPUT);
  pinMode(motor4Pin, OUTPUT);


}
void backward() {


  digitalWrite(motor1Pin, HIGH);   // set leg 1A of the H-bridge HIGH
  digitalWrite(motor2Pin, LOW);  // set leg 2A of the H-bridge low
  digitalWrite(motor3Pin, HIGH);   // set leg 1B of the H-bridge high
  digitalWrite(motor4Pin, LOW);  // set leg 2B of the H-bridge low
}


void forward() {
  digitalWrite(motor1Pin, LOW);  // set leg 1A of the H-bridge LOW
  digitalWrite(motor2Pin, HIGH);   // set leg 2A of the H-bridge high
  digitalWrite(motor3Pin, LOW);   // set leg 1B of the H-bridge low
  digitalWrite(motor4Pin, HIGH);  // set leg 2B of the H-bridge high
}

void left() {

digitalWrite(motor1Pin, LOW);  // set leg 1A of the H-bridge low
  digitalWrite(motor2Pin, LOW);   // set leg 2A of the H-bridge low
  digitalWrite(motor3Pin, HIGH);   // set leg 1B of the H-bridge high
  digitalWrite(motor4Pin, LOW);  // set leg 2B of the H-bridge low
}


void right() {
  digitalWrite(motor1Pin, HIGH);  // set leg 1A of the H-bridge high
  digitalWrite(motor2Pin, LOW);   // set leg 2A of the H-bridge low
digitalWrite(motor3Pin, LOW);  // set leg 1A of the H-bridge low
  digitalWrite(motor4Pin, LOW);   // set leg 2A of the H-bridge low
}

void station()  {
  
digitalWrite(motor1Pin, LOW);  // set leg 1A of the H-bridge low
  digitalWrite(motor2Pin, LOW);   // set leg 2A of the H-bridge low
digitalWrite(motor3Pin, LOW);  // set leg 1A of the H-bridge low
  digitalWrite(motor4Pin, LOW);   // set leg 2A of the H-bridge low
}
void loop() {


  buttonStateLeft = digitalRead(switchPinLeft);
  buttonStateRight = digitalRead(switchPinRight);
  buttonStateForward = digitalRead(switchPinForward);
  buttonStateBackward = digitalRead(switchPinBackward);
  buttonStateStation = digitalRead(switchPinStation);
  
  if (buttonStateForward == HIGH && buttonStateBackward == LOW) { //forward switch are pressed
    forward();
  }
  else if (buttonStateRight == HIGH && buttonStateLeft == LOW) { //right switch is pressed
    right();
  }

  else if (buttonStateRight == LOW && buttonStateLeft == HIGH) { //left switch is pressed
    left();
  }

   else if (buttonStateForward == LOW && buttonStateBackward == HIGH) { //backward switch is pressed
    backward();
    
  }
 else if (buttonStateStation == HIGH) { //none are pressed
    station();
    
  }


}

Credits

Adam Mansour

Adam Mansour

10 projects • 1 follower

Comments