Jennifer Chen
Created November 2, 2015 © GPL3+

Working Chassis Design

Remote Controlled Vehicle - Week 2

IntermediateFull instructions provided1,636
Working Chassis Design

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×40
9V battery (generic)
9V battery (generic)
×1
AA Battery
×4
DC motor (generic)
×2
Rubber Bands
×10
Breadboard (generic)
Breadboard (generic)
×1

Hand tools and fabrication machines

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

Story

Read more

Code

Chassis Motor Control with Buttons

C/C++
Each button controls a function of the wheels (Forward/Backwards of Left wheel & Forwards/Backwards of Right Wheel)
//2-Way motor control - Jennifer Chen
//Chassis Working Design


int motorPin1 =  8;    // One motor wire connected to digital pin 8
int motorPin2 =  9;    // One motor wire connected to digital pin 9
int motorPin3 = 10;    
int motorPin4 = 11;

int buttonPin1 = 4;
int buttonPin2 = 5;
int buttonPin3 = 6;
int buttonPin4 = 7;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;

// The setup() method runs once, when the sketch starts

void setup()   {                
  // initialize the digital pins as an OUTPUT:
  pinMode(motorPin1, OUTPUT); 
  pinMode(motorPin2, OUTPUT);  
  pinMode(motorPin3, OUTPUT); 
  pinMode(motorPin4, OUTPUT);  
  
  //initialize the button pins as INPUT:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
 
}

// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()                     
{
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
  
  //Left wheel backwards
  if(buttonState1 == HIGH){
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    
    if(buttonState3 == HIGH){
      digitalWrite(motorPin3, HIGH);
      digitalWrite(motorPin4, LOW);
    }
    else if(buttonState4 == HIGH){
      digitalWrite(motorPin4, HIGH);
      digitalWrite(motorPin3, LOW);
    }
  }
  
  
  //Left wheel forwards
  if(buttonState2 == HIGH){
    digitalWrite(motorPin2, HIGH);
    digitalWrite(motorPin1, LOW);
    
    if(buttonState3 == HIGH){
      digitalWrite(motorPin3, HIGH);
      digitalWrite(motorPin4, LOW);
    }
    else if(buttonState4 == HIGH){
      digitalWrite(motorPin4, HIGH);
      digitalWrite(motorPin3, LOW);
    }
  }
  
  
   if(buttonState3 == HIGH){
    digitalWrite(motorPin3, HIGH);
    digitalWrite(motorPin4, LOW);
    
    if(buttonState1 == HIGH){
      digitalWrite(motorPin1, HIGH);
      digitalWrite(motorPin2, LOW);
    }
    else if(buttonState2 == HIGH){
      digitalWrite(motorPin2, HIGH);
      digitalWrite(motorPin1, LOW);
    }
  }
  
  
  delay(500);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  
  
}


void rotateLeftFull(int motorPinF, int motorPinB, int length){  
  digitalWrite(motorPinF, HIGH); //rotates motor
  digitalWrite(motorPinB, LOW);    // set the Pin motorPin1 LOW
  delay(length); //waits
  digitalWrite(motorPinF, LOW);    // set the Pin motorPin2 LOW
}

void rotateRightFull(int motorPinF, int motorPinB, int length){
  digitalWrite(motorPinB, HIGH); //rotates motor
  digitalWrite(motorPinF, LOW);    // set the Pin motorPin1 LOW
  delay(length); //waits
  digitalWrite(motorPinB, LOW);    // set the Pin motorPin2 LOW
}

Credits

Jennifer Chen

Jennifer Chen

13 projects • 12 followers

Comments