Building RoboMaster with Arduino - Part 2

 In my last blog post Building RoboMaster with Arduino I wrote the materials I have got for building the robomaster with Arduino. I bought a new 4 Wheel Smart Car Set chassis because the previous that I had bought had no screws and bolts and it was not robust and rigid. 

I assembled the newly bought four wheel chassis, fitted with motors and wheels and also connected the motor wires with Arduino with L293D motor shield. Below is picture of the newly assembled chassis for DIY Arduino RoboMaster.

4 wheel car chasis with L293D motor shield and arduino

Below are some pictures while assembling the 4 wheel car chasis with L293D motor shield and Arduino:


I tested each wheel and motor to see direction of rotation with a 9V battery as shown below.

For comparison purpose below picture shows the older chassis and the newer chassis.


After I assembled the motor shield, the battery with the chassis, I tested the motors wheels directions with the following Arduino sketch.


#include <AFMotor.h>

//initial motors pin
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

void setup(){
  Serial.begin(9600);
}

void loop(){
  forward();
  delay(5000);
  backward();
  delay(5000);
   left();
   delay(1000);
   right();
   delay(5000);
   
}

void forward(){
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(FORWARD);  //rotate the motor clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD);  //rotate the motor clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(FORWARD);  //rotate the motor clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(FORWARD);  //rotate the motor clockwise
}

void backward(){
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
}

void left(){
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(FORWARD);  //rotate the motor clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(FORWARD);  //rotate the motor clockwise
}

void right(){
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(FORWARD);  //rotate the motor clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD);  //rotate the motor clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
}

More on how to use the L293D motor shield works and the code works was explained in the previous tutorial DC motor control using L293D Motor Shield and Arduino

Following video shows the testing of the above code to see the direction and rotation of the wheels.

Next I have plan to buy HC-05 bluetooth module(my previous one used in the tutorial Bluetooth and IR sensor Interfacing got damaged somehow) and use a mobile app to control the car remotely and wirelessly.  

References

# Quick HC-05 AT startup guide - Arduino RoboMaster Part 3

# Testing RC Bluetooth Car App and Motor Code -Arduino RoboMaster Part 4

# Lithium Ion Battery and Charger - Arduino RoboMaster Part 5

# My First Arduino RC Car - Arduino RoboMaster part 6

# RC car Battery Charger- Arduino RoboMaster part 7

Post a Comment

Previous Post Next Post