Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Matthew Chiang
Created November 9, 2015

Project Two Second Week: Working Design

A finished rolling chassis, working steering, working motors. Treat this as a final design, but without the polish of final presentation.

BeginnerShowcase (no instructions)308
Project Two Second Week: Working Design

Things used in this project

Hardware components

Acrylic
I used black acrylic for the matte finish on one side, but you can use any color you want.
×1
Double sided tape
For sticking the motors to the body and testing placement too.
×1
Arduino UNO
Arduino UNO
×1
Arduino L298N Dual H-Bridge Motor Controller
×1
DC motor (generic)
×2
DC motor gear box
For the DC motors to decrease speed and increase torque to turn the car wheels
×2
RC car tires
×2
9V battery (generic)
9V battery (generic)
×1
9V battery pack
×1
4 x AA Battery Holder with On/Off Switch
×1
AA Battery
These will power the L298 H-bridge controller
×4
9V battery holder with switch
×1
Solid core jumper wires
15 is about the number you'll need. You'll also need a few red and black ones for power and ground
×15
Breadboard (generic)
Breadboard (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×4
pushbutton
×4

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
wire stripper
Pliers
Soldering iron (generic)
Soldering iron (generic)
Soldering iron and the other items in a soldering set including lead, fume extractor, safety goggles, etc.

Story

Read more

Schematics

Chassis AI File

Adobe Illustrator file for the chassis

rc-controls-breadboard-circuit

Circuitry for the remote control breadboard

rc-controls-breadboard-circuit

Code

dc_motor_sketch_test.ino

Java
Sketch to test if motor works. If it doesn't, check your wiring.
// Single motor sketch for testing
// Matthew Chiang Des Inv 90-2

// motor 1
int IN1 = 7; // Set IN1 to digital pin 7. Your wire should literally go from 7 on the Arduino to IN1 on the L298
int IN2 = 6;

void setup() {
  pinMode(IN1, OUTPUT); // Set the pin IN1 and IN2 to behave as an output
  pinMode(IN2, OUTPUT);
}

void loop() {

  // For clock-wise motion, IN1 = HIGH, IN2 = LOW
  // Test one motor
  digitalWrite (IN1, HIGH);
  digitalWrite (IN2, LOW);


}

rc-controls-breadboard.ino

Java
For WASD controls
// Which L298 IN is hooked up to which digital pin on the Arduino?
// If you change these, make sure one IN for each motor is linked to a PWM digital pin.
// Motor 1
int IN1 = 7; // IN1 on the L298 is linked to digital pin 7
int IN2 = 6; // pwm
// Motor 2
int IN3 = 4;
int IN4 = 3; // pwm

// The buttons are hooked up to which digital pins?
const int upButtonPin = 9; // the number of the pushbutton pin
const int downButtonPin = 10;
const int leftButtonPin = 11;
const int rightButtonPin = 12; // WHAT, MAKING THIS 0 MADE IT GO FOREVER

// Variables will change:
int upButtonState = 0; // variable for reading the pushbutton status; 1 on (pressed) 0 off (unpressed)
int downButtonState = 0;
int leftButtonState = 0;
int rightButtonState = 0;

void forward() {
  digitalWrite (IN1, HIGH);
  digitalWrite (IN2, LOW);
  digitalWrite (IN3, HIGH);
  digitalWrite (IN4, LOW);
//    analogWrite(IN3, 255);
//    analogWrite(IN1, 255); // IN3 is attached to digital pin 3 which is a PWM pin.  
}

void backward() {
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, HIGH);
  digitalWrite (IN3, LOW);
  digitalWrite (IN4, HIGH);
}

void turnLeft() {
  // Turn left by stopping/slowing the left wheel and moving the right wheel forward
  digitalWrite (IN1, LOW); // LOW for stopping
  digitalWrite (IN2, LOW);
  digitalWrite (IN3, HIGH);
  digitalWrite (IN4, LOW);
  //    analogWrite(IN3, 255); // uncomment for slowing
  //    analogWrite(IN1, 100);
}


void turnRight() {
  // Turn right by stopping/slowing the right wheel and moving the left wheel forward
  digitalWrite (IN1, HIGH);
  digitalWrite (IN2, LOW);
  digitalWrite (IN3, LOW); // LOW
  digitalWrite (IN4, LOW);
  //    analogWrite(IN3, 100);
  //    analogWrite(IN1, 255);
}

void setup() {
  pinMode(IN1, OUTPUT); // Set the pin IN# to behave as an output
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  // Set up the button
  pinMode(upButtonPin, INPUT);
  pinMode(downButtonPin, INPUT);
  pinMode(leftButtonPin, INPUT);
  pinMode(rightButtonPin, INPUT);
}

void loop() {

  // read the state of the pushbutton value
  upButtonState = digitalRead(upButtonPin);
  downButtonState = digitalRead(downButtonPin);
  leftButtonState = digitalRead(leftButtonPin);
  rightButtonState = digitalRead(rightButtonPin);

  // For clock-wise motion, IN1/3 = HIGH, IN2/4 = LOW. This could be different depending on your wiring.

  // Move both wheels forward if upButton is pressed.
  if (upButtonState == HIGH) {
    forward();
  } else if (downButtonState == HIGH) {
    backward();
  } else if (leftButtonState == HIGH) {
    turnLeft();
  } else if (rightButtonState == HIGH) {
    turnRight();
  } else {
    // Stop all wheels if unpressed
    digitalWrite (IN1, LOW);
    digitalWrite (IN2, LOW);
    digitalWrite (IN3, LOW);
    digitalWrite (IN4, LOW);
  }
}

Credits

Matthew Chiang

Matthew Chiang

16 projects • 9 followers

Comments