Since childhood, we have bought many tiny RC Cars and played for hours with them. Once they stop working, engineer minds (like mine), open them up, and play with the DC motor later.
The idea of the ability to control the Car wirelessly, using a Remote has always been fascinating. We have remotes for various other wireless interfaces, like Bluetooth, TV-Remote(IR), Car Doors, and a lot more.
It was only in the late 2010s that we got introduced to the WiFi technology, and have open-source hardware to build projects on WiFi. One such project has been made using the ESP32 WiFi-Dev Board on this project (link here)
But remember the old Remote Controlled Cars?
In the beginning, we used to have 2 Buttons which could move the Car FORWARD and BACKWARD.
With time, we got Car with the ability to Turn !!
But all these cars are AVAILABLE on the Market, why to make something which already existed a Decade back?
Mi Amigo, that's what Makers do. We make things, just Better of course. And here I am with a BRAND NEW Project on HOW to use the FlySky-FS-i6 Radio Transmitter (below image), to control ANY Car. Also, the Radio has a Transmission range of around 1500 meters (Rural) and below 500 meters (Urban).
This Remote is commonly used for QuadCopter / Drones. But with the PPM (Pulse Position Modulation) output or the Servo channels, the Receiver can provide the readings as we move the stick on the transmitter. We will see EVERYTHING in detail shortly.
All of this can be done with any Microcontroller. I will be using ESP32 Dev Board for the Demonstration purpose.
Let's get started !!
HARDWARE SETUPLet us build the Car with the required components and configurations. Since I am using a Bi-Wheel car with a castor wheel for support, the Car Build will differ from what we usually consider a car. But Your Car could look absolutely the way you wish to look like, the only difference will be in the motor pins in the code.
We need to connect the L298N motor driver and the 2 motors that we will use. Then, we will also use a battery pack with 2 x 18650 Li-ion3.7v and provide a 7.4v supply to the motor driver. It is efficient in cases when we need easy access to the replacement of Cells.
Now, make connections of your L298N - Battery - Motor according to the below Circuit Connection -
Make sure to have a Chassis for yourself. I used an Acrylic Board and cut out parts for the Wheels to fit.
As you can see, the Bot takes good shape on a chassis like this.
Now, let us understand the FlySky - i6 Receiver (RX) and its pinouts. And how the Transmitter (TX) controls the Receiver as the stick is moved.
If you focus on the 1st (left-top) diagram, notice the initials 'S' - Signal, 'V+' - 5V, and 'G' - Ground. Here, the signal gives an OUTPUT of 0 - 180° angle, based on the joystick of the FS-i6 Transmitter. (Watch below GIF)
Using Arduino, the data is converted from angular to PWM as well as Digital for making the Motor move Forward, Backward, Left and Right.
Next, let us connect ESP32 and FS-i6 Receiver with the Car. Connections will look as follows.
Between Motor Driver and Dev Board -IN1 - GPIO13 | IN2 - GPIO12 | IN3 - GPIO14 | IN4 - GPIO27
Between FS-i6RX and Dev Board -CH1 - GPIO35 | CH2 - GPIO32 | CH3 - GPIO25 | CH5 - GPIO26
That's all we need to prepare to have a basic 2-wheeler car running using a Radio Remote.
Move FORWARD - ThrottleHow to use the Channels which has a stick, and make the Arduino provide the Directions or the Speed to the Motor?
Above, the Throttle channel is Channel 3. It has a freewheel so that we can provide thrust to any Robot (As seen in the RX GIF sample). Commonly used for Car/Drone/Locomotive machines.
We shall increase the Speed of the Car, as the throttle increases. For that I will send PWM signal to the ENABLE pin of L298N Motor Driver. (below code)
ledcWrite(PWM1_Ch, speed1);
ledcWrite(PWM2_Ch, speed2);
PWM1_Ch and PWM2_Ch are connected to the ENABLE 1 and 2 pin. While speed1 and speed2 are the converted value from the Radio Receiver into PWM data for Motor. See below.
int ch3_IN_LOW = 0;
int ch3_IN_HIGH = 251;
int ch3_OUT_LOW = 0;
int ch3_OUT_HIGH = 1023;
int speed1 = map(ch3Value, ch3_IN_LOW,ch3_IN_HIGH,ch3_OUT_LOW,ch3_OUT_HIGH);
int speed2 = map(ch3Value, ch3_IN_LOW,ch3_IN_HIGH,ch3_OUT_LOW,ch3_OUT_HIGH);
We would be changing the throttle as we move the Channel 3 on Joystick.
Here, I have designated the LOW and HIGH value of the Channel 3 which is read by the ESP32 Dev board through the FS-i6 RX CH3 pin.
When the stick is completely DOWN, we receive ch3_IN_LOW, in my case 0. and When the stick is completely UP, we receive ch3_IN_HIGH
The INPUT range is then converted to the required OUTPUT range using the map() function. (read more about map).
On the OUTPUT side, we require 2^(10) bit PWM signal. Therefore we have an output range of 0 - 1023 (2^10 = 1024). Which provides the required pulse to the Enable PIN of the Motor Driver and the Car moves Forward with the designated speed.
void run(int speed1, int speed2){
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(14,LOW);
digitalWrite(27,HIGH);
ledcWrite(PWM1_Ch, speed1);
ledcWrite(PWM2_Ch, speed2);
}
run(speed1,speed2);
This is however NOT the best practice. It is only a workaround to make a converter and then provide the required throttle. There are already components present in the market which does the job of controlling speed based on their required power supply. They are called Electronic Speed Controller (ESCs). Commonly used in drones, and for this specific purpose.
Although it is available, there is a difference in the type of ESC we require. Because drones commonly use ESCs for Brushless Motor. They are called BLDC ESCs (Brushless Direct Current Electronic Speed Controller).
However, we can use Brushed ESCs which is a great component but comes with a cost and maintenance. Especially because they can RIDE GOOOOOOOD. They differ by look based on current discharge. (IMG1 - 20A, IMG2 - 60 A)
Using this ESC, your Radio RX channel data can be directly fed to the Motor for the Throttle.
Move BACKWARD - Reverse Gear ModeAfter using Channel 3 for Throttle, we know that it can only provide us the speed in ONE direction. We need a mechanism to switch between Forward and Reverse.
In case you have noticed, we have switches on the FlySky Transmitter, we=hich can work like a shifting mechanism - between Forward and Reverse.
Watch this video to understand how to assign Channel to the Switch we require.
I have assigned Channel 5 to the SwA switch. Therefore when SwA is turned OFF, we get 0. And when ON we get the highest value of the Channel (in my case 251).
Using a simple IF - ELSE program, we can make the throttle either move Forward, or Reverse.
if (ch5Value == 0){
//forward
}
else{
//backward
}
When SwA is switched, the Channel 5 value will also switch between HIGH and LOW. With that, we can assign Forward and Reverse to the Car, while Channel 3 provides only the Throttle for both of them.
Move LEFT / RIGHT - DirectionWe have Channel 1(Aileron) which is in the middle (By Default) and can be used to move it to the RIGHT or LEFT to change the direction of the Car.
To use that, we must find out the default value of the Channel and provide a space at which neither LEFT or RIGHT signal should be provided. A range where the car would go either Forward or Backward.
Then, we must check the value of Channel at which we require the Bot to move either Left or Right.
if(ch1Value > 140){ //right
int speed1=map(ch3Value, ch3_IN_LOW,ch3_IN_HIGH,ch3_OUT_LOW,ch3_OUT_HIGH);
int speed2=0;
run(speed2,speed1);
}
else if(ch1Value < 120){ //left
int speed1=map(ch3Value, ch3_IN_LOW,ch3_IN_HIGH,ch3_OUT_LOW,ch3_OUT_HIGH);
int speed2=0;
run(speed1,speed2);
}
In my case, the safe range for the Channel 1 stick to be in the middle (where the BOT does not turn) is between 120 - 140.
Therefore, when Channel 1 > 140 --> stick moves to the RIGHT. And when Channel 1 < 120 --> stick moves to the LEFT. Turning signal was provided to the Car according to that.
void run(int speed1, int speed2){
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(14,LOW);
digitalWrite(27,HIGH);
ledcWrite(PWM1_Ch, speed1);
ledcWrite(PWM2_Ch, speed2);
}
From the above code when either speed1 or speed2 is 0, then that motor does not move. Making the Car take a curved turn.
That's all !! Use the FINAL CODE and make necessary changes (pins and values) to make your OWN RC CAR.
Video DemonstrationHere is the Final Demonstration after including all the mentioned features. I hope this helps us to innovate and build new things with existing components !!
Comments