How to Make Radio Controlled Arduino Car with FS-iA6 and LM298N Motor Driver Board

Learn Robotics

How to Make Radio Controlled Arduino Car with FS-iA6 and LM298N Motor Driver Board

Components Needed

    1. Arduino UNO –

2. FlySky Transmitter Reciever

3. L298N Motor Driver

4. DC Motors

5. Servo Motor

4. Jumper Wires

5. Wheels

6. LiPo Battery

7. LiPo Charger




 




 

Watch this Video For Full Tutorial

Code

int motor1Left = 5;// defines pin 5 as connected to the motor
int motor1Right= 6;// defines pin 6 as connected to the motor
int motor2Left = 7;// defines pin 7 as connected to the motor
int motor2Right = 8;// defines pin 8 as connected to the motor

int channel1 = 9; // defines the channels that are connected
int channel2 = 10;// to pins 9 and 10 of arduino respectively

int Channel1 ; // Used later to 
int Channel2 ; // store values

void  setup ()
{
   pinMode (motor1Left, OUTPUT);// initialises the motor pins
   pinMode (motor1Right, OUTPUT);
   pinMode (motor2Left, OUTPUT);
   pinMode (motor2Right, OUTPUT);// as outputs
   pinMode (channel1, INPUT);// initialises the channels
   pinMode (channel2, INPUT);// as inputs
   Serial.begin (9600); // Sets the baud rate to 9600 bps
}

void  loop ()
{
  Channel1 = (pulseIn (channel1, HIGH)); // Checks the value of channel1
  Serial.println (Channel1); //Prints the channels value on the serial monitor

  if (Channel1 > 1300 && Channel1 < 1500 ) /*If these conditions are true, do the following. These are the values that I got from my transmitter, which you may customize according to your transmitter values */
  {
    digitalWrite (motor1Left, LOW); // Sets both the
    digitalWrite (motor1Right, LOW);// motors to low
  }

  if (Channel1 < 1300) // Checks if Channel1 is lesser than 1300
  {
    digitalWrite (motor1Left, HIGH);// Turns the left
    digitalWrite (motor1Right, LOW); // motor forward
  }
  if (Channel1 > 1500) // Checks if Channel1 is greater than 1500
  {
    digitalWrite (motor1Left, LOW);// Turns the right
    digitalWrite (motor1Right, HIGH);// motor forward
  }
  Channel2 = (pulseIn (channel2, HIGH)); // Checks the value of channel1
  Serial.println (Channel2); //Prints the channels value value on the serial monitor

  if (Channel2 > 1300 && Channel1 < 1500 ) // If these conditions are true, do the following
  {
    digitalWrite (motor2Left, LOW);// Sets both the
    digitalWrite (motor2Right, LOW);// motors to low
  }

  if (Channel2 < 1300) // Checks if Channel2 is lesser than 1300
  {
    digitalWrite (motor2Left, LOW);// Turns the left
    digitalWrite (motor2Right, HIGH);// motor backward
  }
  if (Channel2 > 1500) // Checks if Channel2 is greater than 1500
  {
    digitalWrite (motor2Left, HIGH);// Turns the right
    digitalWrite (motor2Right, LOW);// motor backward
  }

/* NOTE – Check the values of the channels that you get in the serial monitor
           and adjust the values in the if statements accordingly. In my case when the stick
           was centered, my readings were 1400 to 1470. When the stick was raised, the readings were
           above 1470 and when it was lowered, the readings were below 1300.
*/

14 Responses

  1. Where can I find a link to the code for this wonderful project?

    • RoboCircuits says:

      Sorry for the late reply… I will send you code soon.
      Wait please

      • RoboCircuits says:

        /* This is the code for controlling any R/C car with an airplane transmitter written by Vishnu Chaitanya Karpuram. Enjoy!! */
        int motor1Left = 5;// defines pin 5 as connected to the motor
        int motor1Right= 6;// defines pin 6 as connected to the motor
        int motor2Left = 7;// defines pin 7 as connected to the motor
        int motor2Right = 8;// defines pin 8 as connected to the motor

        int channel1 = 9; // defines the channels that are connected
        int channel2 = 10;// to pins 9 and 10 of arduino respectively

        int Channel1 ; // Used later to
        int Channel2 ; // store values

        void setup ()
        {
        pinMode (motor1Left, OUTPUT);// initialises the motor pins
        pinMode (motor1Right, OUTPUT);
        pinMode (motor2Left, OUTPUT);
        pinMode (motor2Right, OUTPUT);// as outputs
        pinMode (channel1, INPUT);// initialises the channels
        pinMode (channel2, INPUT);// as inputs
        Serial.begin (9600); // Sets the baud rate to 9600 bps
        }

        void loop ()
        {
        Channel1 = (pulseIn (channel1, HIGH)); // Checks the value of channel1
        Serial.println (Channel1); //Prints the channels value on the serial monitor

        if (Channel1 > 1300 && Channel1 < 1500 ) /*If these conditions are true, do the following. These are the values that I got from my transmitter, which you may customize according to your transmitter values */ { digitalWrite (motor1Left, LOW); // Sets both the digitalWrite (motor1Right, LOW);// motors to low } if (Channel1 < 1300) // Checks if Channel1 is lesser than 1300 { digitalWrite (motor1Left, HIGH);// Turns the left digitalWrite (motor1Right, LOW); // motor forward } if (Channel1 > 1500) // Checks if Channel1 is greater than 1500
        {
        digitalWrite (motor1Left, LOW);// Turns the right
        digitalWrite (motor1Right, HIGH);// motor forward
        }
        Channel2 = (pulseIn (channel2, HIGH)); // Checks the value of channel1
        Serial.println (Channel2); //Prints the channels value value on the serial monitor

        if (Channel2 > 1300 && Channel1 < 1500 ) // If these conditions are true, do the following { digitalWrite (motor2Left, LOW);// Sets both the digitalWrite (motor2Right, LOW);// motors to low } if (Channel2 < 1300) // Checks if Channel2 is lesser than 1300 { digitalWrite (motor2Left, LOW);// Turns the left digitalWrite (motor2Right, HIGH);// motor backward } if (Channel2 > 1500) // Checks if Channel2 is greater than 1500
        {
        digitalWrite (motor2Left, HIGH);// Turns the right
        digitalWrite (motor2Right, LOW);// motor backward
        }

  2. Hi RoboCircuits

    I will wait with patience 🙂

  3. ZHENG says:

    Thanks for u share it bro, I am a Diy fans,i can’t find a new PCB board. i really want make a new project.
    My bro always take a newpcb from this site https://www.pcbgogo.com/?code=y,
    Pls tell me what kind of PCB that i need.If the borad is very expensive i can’t afford it.So maybe i can made a simple piano,Use the cheapest board.My bro said it only 5$ for 10pcs
    may be i will try it .

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Skip to toolbar