In this tutorial, we will learn How To Make an Arduino Long-Range RC tracked robot tank. For this, a transmitter and a receiver used in connection with Drone and RC are used. A receiver employing the widely popular SBUS Protocol is utilized for this purpose. The SBUS signal is decoded as PWM and connected to the Long-Range RC tracked robot tank. A L298N Motor Driver is used to drive the motor. It can control over a distance of more than a kilometer.
You can watch the following video or read the written tutorial below.
Overview
An Arduino board is used as a grant to build the Arduino Long-Range RC tracked robot tank. A L298N motor driver is used to control the motor. SBUS Receiver and a suitable transmitter are used for control. Since the Sbus signal cannot be used directly, it is decoded into PWM channels using Arduino. How to make it is explained in a previous article. It uses only six PWM channels. Two-speed modes are used here. Switch C (SwC) enables the motor of the car and switch D (SwD) changes the speed mode.
Long Range RC Tracked Robot Tank Circuit Diagram
The next stage is connecting the electronics. You may find this circuit diagram quite complex. The reason for this is that the SBUS to PWM decoder uses the receiver and uses digital pins as well as analog pins on the Arduino board. In addition to the four inputs of the L298N motor driver, the ENA and ENB pins are also used. As depicted in the circuit diagram, the procedure for connecting the module wires is further explained below. You can download this circuit diagram. For that, click on the Download button below and download it.
Connecting the two 9V gear motors to the l298N Motor Driver.
In this way, connect the wires of the gear motors to the motor power connectors of the l298N motor driver.
- Connect the Black wire of the Left motor to the “OUT1” terminals of the L298N motor driver.
- Connect the Red wire of the Left motor to the “OUT2” terminals of the L298N motor driver.
- Connect the Red wire of the Right motor to the “OUT3” terminals of the L298N motor driver.
- Connect the Black wire of the Right motor to the “OUT4” terminals of the L298N motor driver.
Connect power to Arduino UNO, Motor Driver, and SBUS to PWM decoder
Use two 3.7V 18659 li-ion batteries to provide power. Do not use more than two batteries. It cannot use 9V battery. If a 9V battery is used Gear motor not working. The reason for that is that the 9V battery does not have enough amperage.
First solder the switch to the battery holder. Solder the red wire of the battery holder to one end of the switch and solder a red wire to the other end of the switch. Stick the switch to the battery holder with the glue gun.
First, connect power to the L298N motor drive from the battery holder.
- Connect the Battery holder Red wire to the 12V IN connecter on the motor driver.
- Connect the Battery holder Black wire to the GND connecter on the motor driver.
Second, connect power to the Arduino board from the battery holder.
- Connect the Red wire (+) of the battery holder to the VIN pin of the Arduino board.
- Connect the Black wire (-) of the battery holder to the GND pin of the Arduino board.
Third, connect power to the SBUS to PWM decoder from the battery holder.
- Connect the Red wire (+) of the battery holder to the + of the SBUS to PWM Decoder DC jack.
- Connect the Black wire (-) of the battery holder to the – of the SBUS to PWM Decoder DC jack.
Connect the Arduino UNO to the L298N Driver
In this way, connect the digital pins of the Arduino board and the inputs of the L298N motor driver by jumper wires.
- Connect the IN1 pin of the motor driver to digital pin D2 on the Arduino.
- Connect the IN2 pin of the motor driver to digital pin D3 on the Arduino.
- Connect the IN3 pin of the motor driver to digital pin D7 on the Arduino.
- Connect the IN4 pin of the motor driver to digital pin D8 on the Arduino.
- Connect the ENA pin of the motor driver to digital pin D5 on the Arduino.
- Connect the ENB pin of the motor driver to digital pin D6 on the Arduino.
SBUS To PWM Decoder
SBUS, a digital communication protocol prevalent in radio control systems, finds wide application in drones, RC cars and robotics. A previous article described the process of decoding an SBUS signal to extract 18 PWM channels. The description can be obtained through the link below.
Link – How to decode an SBUS receiver signal and obtain 18 channels of PWM output using Arduino
This RC Car needs six PWM outs.
Connect the SBUS To PWM Decoder to the Arduino board
18 channels SBUS To PWM Decoder uses only the first six channels for this purpose. This is used as the receiver of the transmitter. How to make this is well explained in a previous article.
In this way, connect the analog pins of the Arduino board and the first six channels of the SBUS to PWM Decoder with jumper wires.
- Connect the 2,S(Channel 1) pin of the SBUS PWM Decoder to the Analog pin A0 of the Arduino board.
- Connect the 3,S(Channel 2) pin of the SBUS PWM Decoder to the Analog pin A1 of the Arduino board.
- Connect the 4,S(Channel 3) pin of the SBUS PWM Decoder to the Analog pin A2 of the Arduino board.
- Connect the 5,S(Channel 4) pin of the SBUS PWM Decoder to the Analog pin A3 of the Arduino board.
- Connect the 6,S(Channel 5) pin of the SBUS PWM Decoder to the Analog pin A4 of the Arduino board.
- Connect the 7,S(Channel 6) pin of the SBUS PWM Decoder to the Analog pin A5 of the Arduino board.
Upload the Arduino Sketch
Copy the following Arduino code and paste it into the new sketch in the Arduino IDE. Select the board and port and upload the code. If this is difficult to do, watch a tutorial video.
You can download the Arduino code and open it directly through the Arduino IDE. Click the Download button below to download the Arduino code
//Robot Lk YouTube Channel - https://www.youtube.com/@RobotLk
//Robotlk.com - https://robotlk.com/
int enA = 5;
int in1 = 2;
int in2 = 3;
//M2
int enB = 6;
int in3 = 7;
int in4 = 8;
int receiver_pins[] = {A0, A1, A2, A3, A4, A5};
int receiver_values[] = {0, 0, 0, 0, 0, 0};
int res_min = 1100;
int res_max = 1900;
int working_range = 255;// motor driver range
boolean prt = true;
int mode = 0;
//-1 - transmeter not connected or out of range
//0- trans connected and ready
//1 - low speed
//2 = high speed mode
void setup() {
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
Serial.begin(100000);
//Staring delay with LED
setLED(1);
delay(300);
setLED(1);
delay(300);
setLED(2);
delay(300);
setLED(3);
delay(300);
setLED(0);
}
void loop() {
receive();
setModeLED();
int m1 = 0;
int m2 = 0;
int rot = receiver_values[0];
if (mode == 1) {
m1 = receiver_values[1] / 2 + (rot );
m2 = receiver_values[1] / 2 - (rot );
} else if (mode == 2) {
m1 = receiver_values[1] + rot / 2;
m2 = receiver_values[1] - rot / 2
;
}
mpower(1, m1);
mpower(2, m2);
}
int rp = 0;
void receive() {
receiver_values[rp] = map(pulseIn (receiver_pins[rp], HIGH), res_min, res_max, -1 * working_range, working_range);
rp++;
if (rp == 6) {
rp = 0;
}
boolean activevalues = true;
for (int i = 0; i < 6; i++) {
if (prt) {
Serial.print("CH");
Serial.print(i);
Serial.print(" : ");
Serial.print(receiver_values[i]);
Serial.print(",\t");
}
if (receiver_values[i] < -500) {
activevalues = false;
}
}
mode = 0;
if (!activevalues) {
mode = -1;
} else if (receiver_values[4] > -100) {
mode = 2;
} else if (receiver_values[5] > -100) {
mode = 1;
}
if (prt) {
Serial.println("");
}
}
void setModeLED() {
if (mode == -1) {
setLED(-0);
} else if (mode == 0) {
setLED(1);
} else if (mode == 1) {
setLED(2);
} else if (mode == 2) {
setLED(3);
}
}
void setLED(int led) {
for (int i = 1; i < 4; i++) {
if (led == i) {
digitalWrite(10 + i, LOW);
} else {
digitalWrite(10 + i, HIGH);
}
}
}
void mpower(int motor, int spd) {
int rotation = 0;
if (spd > 0) {
rotation = 1;
} else if (spd < 0) {
rotation = -1;
spd *= -1;
}
if (spd > 255) {
spd = 255;
}
int pwm;
int pA;
int pB;
if (motor == 1) {
pwm = enA;
pA = in1;
pB = in2;
} else if (motor == 2) {
pwm = enB;
pA = in3;
pB = in4;
} else {
return;
}
if (rotation == 0) {
digitalWrite(pA, LOW);
digitalWrite(pB, LOW);
} else if (rotation == 1) {
digitalWrite(pA, HIGH);
digitalWrite(pB, LOW);
} else if (rotation == -1) {
digitalWrite(pA, LOW);
digitalWrite(pB, HIGH);
}
analogWrite(pwm, spd);
}
Code language: Arduino (arduino)
Connecting the channel to the switch of the transmitter
Connect channel 5 to the SWC Switch and channel 6 to the SWD Switch. Switch C (SwC) activates speed mode 1 of the car and switch D (SwD) activates speed mode 2.