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!
Jennifer Chen
Created November 9, 2015 © GPL3+

Arduino Remote Controlled Vehicle

IntermediateShowcase (no instructions)360
Arduino Remote Controlled Vehicle

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
DC motor (generic)
×2
L298 Dual H-Bridge Motor Controller
×1
Electrical Wire
×10
9V battery (generic)
9V battery (generic)
×1
AA Battery
×4
Zip Ties
×4
CA Adhesive
×1
Hot Glue
×1
Rubber Bands
×10
Wooden Rod
×1
Push Button Switch
×4
PVC Electrical Connector
×1
Aluminum Spacer 3/4"
×4
Screws 1/4"
Should fit the threaded spacer
×8
Magnets
×6
Marbles
×2
Pipe Cleaners
×1

Software apps and online services

Fusion
Autodesk Fusion
Adobe Illustrator

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Laser cutter (generic)
Laser cutter (generic)
Soldering iron (generic)
Soldering iron (generic)
Hacksaw
Digital Multimeter
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Circuit Schematic

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
//Remote Control Vehicle


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;    // One motor wire connected to digital pin 10
int motorPin4 = 11;    // One motor wire connected to digital pin 11

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

//initial button states are 0, not pressed
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); //backward on
    digitalWrite(motorPin2, LOW);  //forward off
    
    if(buttonState3 == HIGH){
      digitalWrite(motorPin3, HIGH); //Right wheel backward
      digitalWrite(motorPin4, LOW);
    }
    else if(buttonState4 == HIGH){
      digitalWrite(motorPin4, HIGH); //Right wheel forward
      digitalWrite(motorPin3, LOW);
    }
  }
  
  
  //Left wheel forwards
  if(buttonState2 == HIGH){
    digitalWrite(motorPin2, HIGH); //forward on
    digitalWrite(motorPin1, LOW);  //backward off
    
    if(buttonState3 == HIGH){
      digitalWrite(motorPin3, HIGH); //Right wheel backward
      digitalWrite(motorPin4, LOW);
    }
    else if(buttonState4 == HIGH){
      digitalWrite(motorPin4, HIGH);  //Right wheel forward
      digitalWrite(motorPin3, LOW);
    }
  }
  
  //Right wheel backwards
   if(buttonState3 == HIGH){
    digitalWrite(motorPin3, HIGH); //backward on
    digitalWrite(motorPin4, LOW);  //forward off
    
    if(buttonState1 == HIGH){
      digitalWrite(motorPin1, HIGH); //Left wheel backward
      digitalWrite(motorPin2, LOW);
    }
    else if(buttonState2 == HIGH){
      digitalWrite(motorPin2, HIGH); //Left wheel forward
      digitalWrite(motorPin1, LOW);
    }
  }

   //Right Wheel forwards
   if(buttonState4 == HIGH){
    digitalWrite(motorPin4, HIGH); //forward on
    digitalWrite(motorPin3, LOW);  //backward off
    
    if(buttonState1 == HIGH){
      digitalWrite(motorPin1, HIGH);  //Left wheel backward
      digitalWrite(motorPin2, LOW);
    }
    else if(buttonState2 == HIGH){
      digitalWrite(motorPin2, HIGH);  //Right wheel forward
      digitalWrite(motorPin1, LOW);
    }
  }

  
  delay(10);
  //turn all motors off and wait for next command
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  
  
}

Credits

Jennifer Chen

Jennifer Chen

13 projects • 12 followers

Comments