Akshayan Sinha
Published © GPL3+

RC Car using FlySky-i6s RX-TX

Control any Car 2Wheeler/4Wheeler using the FlySky remote, and make the Car smart using Forward and Backward acceleration like shifting gear

IntermediateFull instructions provided4 hours5,159
RC Car using FlySky-i6s RX-TX

Things used in this project

Hardware components

Espressif ESP32 Development Board - Developer Edition
Espressif ESP32 Development Board - Developer Edition
×1
FlySky FS-i6 Transmitter
×1
FlySky FS-i6 Receiver
×1
DC Motor, 12 V
DC Motor, 12 V
×2
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1
Battery Holder, 18650 x 2
Battery Holder, 18650 x 2
×1
Battery, 3.6 V
Battery, 3.6 V
×2

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

FS-i6 RX for RC Car Cirtcuit Diagram

Code

FlySky Remote controlled Car

C/C++
#define GPIO1 33
#define GPIO2 32
#define PWM1_Ch    0
#define PWM2_Ch    1
#define PWM_Res   10
#define PWM_Freq  1000

int PWM1_DutyCycle = 0;

#define CH5 26 // forward/backward
#define CH3 25 // throttle
#define CH2 35 // emergency stop
#define CH1 34 // turn

int ch1Value; // turn left/right
int ch2Value; // emergency stop
int ch3Value; // throttle
int ch5Value; // forward/backward

int ch3_IN_LOW = 0;
int ch3_IN_HIGH = 251;
int ch3_OUT_LOW = 0;
int ch3_OUT_HIGH = 1023;

int PWM_LOW = 0;    // 2**8 bit
int PWM_HIGH = 255; // 2**8 bit

int turn_right = 140;
int turn_left = 120;
int ch1_stop_value = 100;

int readChannel(int channelInput, int minLimit, int maxLimit, int defaultValue){
  int ch = pulseIn(channelInput, HIGH, 60000);
  if (ch < 100) return defaultValue;
  return map(ch, 1000, 2000, minLimit, maxLimit);
}

void setup(){
  // Set up serial monitor
  Serial.begin(115200);
  pinMode(CH1, INPUT);
  pinMode(CH2, INPUT);
  pinMode(CH3, INPUT);
  pinMode(ch5, INPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(27, OUTPUT);

  ledcAttachPin(GPIO1, PWM1_Ch);
  ledcAttachPin(GPIO2, PWM2_Ch);
  
  ledcSetup(PWM1_Ch, PWM_Freq, PWM_Res);
  ledcSetup(PWM2_Ch, PWM_Freq, PWM_Res); 
}

void loop() {
  
  ch1Value = readChannel(CH1, 0, PWM_HIGH, PWM_LOW);
  ch2Value = readChannel(CH2, 0, PWM_HIGH, PWM_LOW);
  ch3Value = readChannel(CH3, 0, PWM_HIGH, PWM_LOW);
  ch5Value = readChannel(CH5, 0, PWM_HIGH, PWM_LOW);

  if (ch5Value == 0){
    if(ch3Value > 0){
      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);
      run(speed1,speed2);
    }
    if(ch1Value > turn_right){   //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 < turn_left){ //left
      
      int speed1=map(ch3Value, ch3_IN_LOW,ch3_IN_HIGH,ch3_OUT_LOW,ch3_OUT_HIGH);
      int speed2=0;
      run(speed1,speed2);
  
    }
    else if(ch2Value < 100){
      stop();
    }
  } 
  else
  {
    if(ch3Value > 0){
      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);
      back(speed1,speed2);
    }
    if(ch1Value > 140){   //right
  
      int speed1=map(ch3Value, ch3_IN_LOW,ch3_IN_HIGH,ch3_OUT_LOW,ch3_OUT_HIGH);
      int speed2=0;
      back(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;
      back(speed1,speed2);
  
    }
    else if(ch2Value < ch1_stop_value){
      stop();
    }
  }
}


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);
}

void back(int speed2, int speed1){

  digitalWrite(13,LOW);
  digitalWrite(12,HIGH);
  digitalWrite(14,HIGH);
  digitalWrite(27,LOW);

  ledcWrite(PWM1_Ch, speed1);
  ledcWrite(PWM2_Ch, speed2);
}

void forward(int speed){

  digitalWrite(13,HIGH);
  digitalWrite(12,LOW);
  digitalWrite(14,LOW);
  digitalWrite(27,HIGH);

  ledcWrite(PWM1_Ch, speed);
  ledcWrite(PWM2_Ch, speed);
}

void stop(){
  ledcWrite(PWM1_Ch, 0);
  ledcWrite(PWM2_Ch, 0);
}

void left(int speed1, int speed2){

  digitalWrite(13,HIGH);
  digitalWrite(12,LOW);
  digitalWrite(14,LOW);
  digitalWrite(27,HIGH);

  ledcWrite(PWM1_Ch, speed1);
  ledcWrite(PWM2_Ch, speed2);
}

void right(int speed1, int speed2){

  digitalWrite(13,HIGH);
  digitalWrite(12,LOW);
  digitalWrite(14,LOW);
  digitalWrite(27,HIGH);

  ledcWrite(PWM1_Ch, speed1);
  ledcWrite(PWM2_Ch, speed2);
}

Credits

Akshayan Sinha

Akshayan Sinha

28 projects • 27 followers
Robotics Software Engineer with a makermind.

Comments