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!
Eric Chen
Created November 1, 2015

Homework 7: Working Chassis Design

With no choice left, I did the unthinkable: I glued the motors to the prototype :(

BeginnerShowcase (no instructions)494
Homework 7: Working Chassis Design

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
male-to-male wire
×8
male-to-female wire
×10
lollipop sticks
×1
rubber band
×2
rubber wheel
×2
DC motor (generic)
×2
9V battery (generic)
9V battery (generic)
×1
AA battery
×4
L298 motor controller
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
button switch
×2
Resistor 1k ohm
Resistor 1k ohm
×2
Breadboard (generic)
Breadboard (generic)
×1
arcylic
×1

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Schematics

Cut Template

Circuitry

Code

Driving Code

C/C++
const int LEFT_IN = 3;
const int LEFT_OUT = 5;
const int RIGHT_OUT = 6;
const int RIGHT_IN = 9;

const int POTENTIOMETER = 0;
const int BACKWARD_SWITCH = 11;
const int FORWARD_SWITCH = 12;

void setup()  {
  Serial.begin(9600);
  pinMode(POTENTIOMETER, INPUT);
  pinMode(BACKWARD_SWITCH, INPUT);
  pinMode(FORWARD_SWITCH, INPUT);
}

void loop() {
  int val = analogRead(POTENTIOMETER);
  int left_val = 255;
  int right_val = 255;
  if (val < 475) {
    left_val = (val >= 150) ? map(val, 150, 475, 0, 255) : 0;
  } else if (val > 525) {
    right_val = (val <= 850) ? 255 - map(val, 525, 850, 0, 255) : 0;
  }
  if (digitalRead(FORWARD_SWITCH) == HIGH) {
    move_wheel(LEFT_IN, LEFT_OUT, left_val, true);
    move_wheel(RIGHT_IN, RIGHT_OUT, right_val, true);
  } else if (digitalRead(BACKWARD_SWITCH) == HIGH) {
    move_wheel(LEFT_IN, LEFT_OUT, left_val, false);
    move_wheel(RIGHT_IN, RIGHT_OUT, right_val, false);
  } else {
    move_wheel(LEFT_IN, LEFT_OUT, 0, true);
    move_wheel(RIGHT_IN, RIGHT_OUT, 0, true);
  }
}

void move_wheel(int in, int out, int val, boolean forward) {
  analogWrite(in, (forward) ? val : 0);
  analogWrite(out, (forward) ? 0 : val);
  return;
}

Credits

Eric Chen

Eric Chen

9 projects • 2 followers
EECS student at UC Berkeley

Comments