circuitprofessor.com

path to learn electronics

Build Your Own Remote-Controlled Arduino Car (5 STEPS)

ByDavid E. Olson

Jan 24, 2023
arduino car

The project will help you learn and gain more real-world experience. We’ll give you all the information you need to build an Arduino car.

Learn basics about Arduino like IDE.

What knowledge will you gain from having completed this practical

  • Arduino programming
  • Arduino pins
  • PWM signals
  • Bluetooth communication
  • Serial communication
  • basic robotic concepts
  • optimization

Step 01 – collecting equipment

  • Arduino UNO board

we use an arduino UNO board for making this arduino car.

arduino car

  • chassis

you can use any kind of chassis for this project.

arduino car

“if you are a creative person then you can make your own custom-made chassis.”

  • motors and wheels

for this project, we use normal wheels. if you are interested in any other types of wheels like the omi direction wheel.

arduino car
  • motor driver

for this project, we use L298N Motor Drive Controller. you can make your own mother controller using transistors and capacitors.

arduino car
  • Bluetooth module

HC – 05 is a good Bluetooth module for Bluetooth communication. Actually, we use our mobile phones as remote controllers.

arduino car
  • wires

you need jumper wires. there are three kinds of jumper wires (male to male, female to female, male to female)

arduino car

  • Battery

Finally, we need a power source to power up the system.

it is up to you. it depends on your system’s required torque and work time.

batteries for robotics

read more about battery explanation

my recommendation is to use rechargeable ALKALINE batteries or NICKEL METAL HYBRID batteries. otherwise, you will have to use more batteries during the testing stage.

Step 02 – Making a sketch

my suggestion is to do some tests and then assemble your car. you will understand more about the motor driver,arduino pins and Bluetooth module. the step by step guidance about making code have provided below.

The diagram

arduino car
  • we use 4 motors and 2 motors are coupled together.
  • there are only 6 PWM pins in the arduino Uno board.(pin numbers = 11,10,9,6,5,3)

“By changing the duty cycle of a square wave signal, PWM, also known as pulse width modulation, is a method used by Arduino to regulate the amount of power delivered to a particular device..”

read more about PWM

  • for this project, we use 11 and 10 pins.
//defining PWM pins for microcontrollers.
const int ENA = 11;
const int ENB = 10;

” NOTE – remove the CLIPs in PWM pins in L298N( ENA, ENB)”

PWM
  • if we consider about pins configuration in L298N ; we use IN1,IN2,IN3,IN4 for change the direction of the motors.
//defining motor pins for microcontroller 

int motor1pin1 = 7;//IN1
int motor1pin2 = 6;//IN2
int motor2pin1 = 4;//IN3
int motor2pin2 = 3;//IN4
  • then, in order to store the Serial values, a character variable needs to be defined. Actually, we use serial communication to control the car.
  • To wirelessly communicate with mobile phones, a Bluetooth module is used.

char Incoming_value = 0; 
  • then we define the pin modes

void setup()
 {

  Serial.begin(9600);//start serial communication
  pinMode(motor1pin1,OUTPUT); // define the pin as OUTPUT FOR MOTOR 1
  pinMode(motor1pin2,OUTPUT); // define the pin as OUTPUT FOR MOTOR 1
  
  pinMode(motor2pin1, OUTPUT);// define the pin as OUTPUT FOR MOTOR 2
  pinMode(motor2pin2, OUTPUT);// define the pin as OUTPUT FOR MOTOR 2

  pinMode (ENA, OUTPUT);//define PWM pins
  pinMode (ENB, OUTPUT);//define PWM pins
}
  • then we can move into the controlling part. we use “F” for forward, “B” for backward, “L” for turn left, and “R” for turn right to control our arduino car.
  • There are two-speed limits. When sending “1,” the Arduino car moves at half its maximum speed; when sending “2,” it travels at its fastest rate.

void loop() {
  //analogWrite(ENA,125 );
  //analogWrite(ENB,125 ); 

  if(Serial.available() > 0)  
  {
    Incoming_value = Serial.read();//Read the incoming data and store it into variable Incoming_value
    Serial.print(Incoming_value);//Print Value of Incoming_value in Serial monitor
    Serial.print("\n");        //New line 
    if(Incoming_value == 'F') //Checks whether value of Incoming_value is equal to 1 
      {
   digitalWrite(motor1pin1, HIGH);
  digitalWrite(motor1pin2, LOW);

  digitalWrite(motor2pin1, HIGH);
  digitalWrite(motor2pin2, LOW); 
           
       }
    else if(Incoming_value == 'B')//Checks whether value of Incoming_value is equal to 0
      {
      digitalWrite(motor1pin1, LOW);
      digitalWrite(motor1pin2, HIGH);

    digitalWrite(motor2pin1, LOW);
    digitalWrite(motor2pin2, HIGH);   
        
      }
      else if(Incoming_value == 'L')//Checks whether value of Incoming_value is equal to 0
      {
      digitalWrite(motor1pin1, LOW);
      digitalWrite(motor1pin2, HIGH);

    digitalWrite(motor2pin1, LOW);
    digitalWrite(motor2pin2, LOW);   
        
      }
      else if(Incoming_value =='R')//Checks whether value of Incoming_value is equal to 0
      {
      digitalWrite(motor1pin1, LOW);
      digitalWrite(motor1pin2, LOW);

    digitalWrite(motor2pin1, LOW);
    digitalWrite(motor2pin2, HIGH);   
        
      }
      if(Incoming_value =='1')//Checks whether value of Incoming_value is equal to 1 
     {
   analogWrite(ENA,125 );
   analogWrite(ENB,125 );  
          
      }
      if(Incoming_value =='2')//Checks whether value of Incoming_value is equal to 1 
     {
     analogWrite(ENA,225 );
    analogWrite(ENB,225 ); 
          
       }
       else //Checks whether value of Incoming_value is equal to 0
      {
      digitalWrite(motor1pin1, LOW);
      digitalWrite(motor1pin2, LOW);

      digitalWrite(motor2pin1, LOW);
      digitalWrite(motor2pin2, LOW);   
        
      }
      
  } 

” NOTE: Disconnect the TX and RX pins from the Bluetooth module before uploading the code to the board.”

Step 03 – Attaching components together

Due to your finish of the challenging part of the project, your Arduino car is now almost complete.

  • attached the all the parts in steady.
  • the Bluetooth module is attached open area of the Arduino car chassis.
  • recheck your motor configuration before attaching the chassis.

Step 04 – optimization

  • If you’d choose, you can skip this step. because your Arduino car is functional.

Here is the optimized code

const int MOTOR_1_PIN_1 = 7;
const int MOTOR_1_PIN_2 = 6;
const int MOTOR_2_PIN_1 = 4;
const int MOTOR_2_PIN_2 = 3;
const int PWM_PIN_1 = 11;
const int PWM_PIN_2 = 10;

char incomingValue = 0;

void setup() {
    Serial.begin(9600);
    pinMode(MOTOR_1_PIN_1, OUTPUT);
    pinMode(MOTOR_1_PIN_2, OUTPUT);
    pinMode(MOTOR_2_PIN_1, OUTPUT);
    pinMode(MOTOR_2_PIN_2, OUTPUT);
    pinMode(PWM_PIN_1, OUTPUT);
    pinMode(PWM_PIN_2, OUTPUT);
}

void loop() {
    if(Serial.available() > 0) {
        incomingValue = Serial.read();
        Serial.println(incomingValue);
        
        switch(incomingValue) {
            case 'F':
                moveForward();
                break;
            case 'B':
                moveBackward();
                break;
            case 'L':
                moveLeft();
                break;
            case 'R':
                moveRight();
                break;
            case '1':
                setSpeed(125);
                break;
            case '2':
                setSpeed(225);
                break;
            default:
                stop();
        }
    }
}

void moveForward() {
    digitalWrite(MOTOR_1_PIN_1, HIGH);
    digitalWrite(MOTOR_1_PIN_2, LOW);

    digitalWrite(MOTOR_2_PIN_1, HIGH);
    digitalWrite(MOTOR_2_PIN_2, LOW);
}

void moveBackward() {
    digitalWrite(MOTOR_1_PIN_1, LOW);
    digitalWrite(MOTOR_1_PIN_2, HIGH);

    digitalWrite(MOTOR_2_PIN_1, LOW);
    digitalWrite(MOTOR_2_PIN_2, HIGH);
}

void moveLeft() {
    digitalWrite(MOTOR_1_PIN_1, LOW);
    digitalWrite(MOTOR_1_PIN_2, HIGH);

    digitalWrite(MOTOR_2_PIN_1, LOW);
    digitalWrite(MOTOR_2_PIN_2, LOW);
}

void moveRight() {
    digitalWrite(MOTOR_1_PIN_1, LOW);
    digitalWrite(MOTOR_1_PIN_2, LOW);

    digitalWrite(MOTOR_2_PIN_1, LOW);
    digitalWrite(MOTOR_2_PIN_2, HIGH);
}

void setSpeed(int speed) {
    analogWrite(PWM_PIN_1, speed);
    analogWrite(PWM_PIN_2, speed);
}

void stop() {
    digitalWrite(MOTOR_1_PIN_1, LOW);
    digitalWrite(MOTOR_1_PIN_2, LOW);
    digitalWrite(MOTOR_2_PIN_1, LOW);
    digitalWrite(MOTOR_2_PIN_2, LOW);
}    

Step 05 – Finalization of Arduino car

This is the last step in building your Arduino car. Most of the time, Bluetooth errors happen when an Arduino car communicates with a phone. Additionally, there are a bunch of apps for controlling Arduino car that can be found in the play store and apps store. Using the app’s settings, you can modify Serial transmission values. Additionally, we can use the ROS platform to use our laptops to control our Arduino car.

If you want to develop your project into a high-speed RC car, changing wireless communication is the first thing you need to do. Later, we’ll offer those kinds of projects.

more about Arduino

To learn about robotics

One thought on “Build Your Own Remote-Controlled Arduino Car (5 STEPS)”

Leave a Reply

Your email address will not be published. Required fields are marked *