Flysky FS-i6 transmitter and receiver FS-iA6B not able to handle Left stickX left/right motor movement

Please find code below where Flysky transmitter is used to control dc motors with L298N motor driver and Flysky receiver FS-iA6b connected to DOIT ESP32 DEVKIT VI.
I used the Flysky channel2 right stickY control motor movement forward/reverse using up/down stickY. The Flysky channel4 left stickX control the motor direction left/right. I'm using a 12v power supply to power up my motors hence plenty of amps and voltage to run my motors.
My problem is when I power up the complete project one of the motors is continously ON. It only stops when the Flysky trasnmitter is connected to the receiver. The right stickY of the transmitter is controlling forward/reverse movement of the dc motors no problem. However the transmitter left stickX is working and changing values when I move it left/right using the serial monitor but not moving the motors left/right.
When I code this individually using the left/right stickX on its own its working fine. When I combined it with the right stickY it will not work but showing values on the serial monitor when moving it left/right. This is one of the problem, the other one is when I power up the project one side of the motor is continously ON, it stops when the transmitter is connected. I tried changing the threshold but up/down it still no effect.
Can anyone help to solve my issues with this project.
Chito

/* RC Flysky Left stickX moves motor left/right direction (channel4)
Up/Down Right StickY moves motor forward/backward direction (channel2)
*/

const int channel4Pin = 34; // ChannelPinD for left/right (leftt StickX)
const int channel2Pin = 35; // ChannelPinF for forward/backward (right StickY)

const int motorPin1 = 22; // IN1
const int motorPin2 = 23; // IN2
const int enablePin1 = 25; // EN1

const int motorPin3 = 18; // IN3
const int motorPin4 = 19; // IN4
const int enablePin2 = 26; // EN2

const int speedPin = 100;

void setup() {
Serial.begin(115200);

pinMode(channel4Pin, INPUT);
pinMode(channel2Pin, INPUT);

pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(enablePin1, OUTPUT);

pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
pinMode(enablePin2, OUTPUT);
}

void loop() {
int ChannelPinD = pulseIn(channel4Pin, HIGH, 25000); // Channel 4 (left StickX for left/right)
int ChannelPinF = pulseIn(channel2Pin, HIGH, 25000); // Channel 2 (right StickY for forward/backward)

// Print PWM values for debugging
Serial.print("ChannelPinD PWM Value: ");
Serial.println(ChannelPinD);

Serial.print("ChannelPinF PWM Value: ");
Serial.println(ChannelPinF);

// Control motor Left/Right directions
if (ChannelPinD > 1500) { // Right
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
analogWrite(enablePin1, 100);

digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
analogWrite(enablePin2, 0);
Serial.println("Moving Right");

}
else if
(ChannelPinD < 1400) { // Left
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
analogWrite(enablePin1, 0);

digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
analogWrite(enablePin2, 100);
Serial.println("Moving Left");

}
else { // Stop
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
analogWrite(enablePin1, 0);

digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
analogWrite(enablePin2, 0);
Serial.println("Stopping");

}

// Control Forward/Backward
if (ChannelPinF > 1700) { // Forward
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
analogWrite(enablePin1, speedPin);

digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
analogWrite(enablePin2, speedPin);
Serial.println("Moving Forward");

}
else if
(ChannelPinF < 1500) { // Backward
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
analogWrite(enablePin1, speedPin);

digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
analogWrite(enablePin2, speedPin);
Serial.println("Moving Backward");

}
else { // Stop
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
analogWrite(enablePin1, 0);

digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
analogWrite(enablePin2, 0);
Serial.println("Stopping");

}

delay(20); // Further reduced delay for immediate responsiveness
}

You seem to have forgot about the correct way to post your code.

It's not the transmitter & sender combo- these are working perfectly. Your code is to blame.

Hi Jim-p,
Below is I hope the proper code and correct way to post a reply. Hope you can help me. Thanks

const int channel4Pin = 34;                             // ChannelPinD for left/right (leftt StickX)
const int channel2Pin = 35;                             // ChannelPinF for forward/backward (right StickY)

const int motorPin1 = 22;                               // IN1
const int motorPin2 = 23;                               // IN2
const int enablePin1 = 25;                              // EN1

const int motorPin3 = 18;                               // IN3
const int motorPin4 = 19;                               // IN4
const int enablePin2 = 26;                              // EN2

const int speedPin = 100;

void setup() {
  Serial.begin(115200);

  pinMode(channel4Pin, INPUT);
  pinMode(channel2Pin, INPUT);

  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(enablePin1, OUTPUT);

  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(enablePin2, OUTPUT);
}

void loop() {
  int ChannelPinD = pulseIn(channel4Pin, HIGH, 25000);  // Channel 4 (left StickX for left/right)
  int ChannelPinF = pulseIn(channel2Pin, HIGH, 25000);  // Channel 2 (right StickY for forward/backward)

  // Print PWM values for debugging
  Serial.print("ChannelPinD PWM Value: ");
  Serial.println(ChannelPinD);

  Serial.print("ChannelPinF PWM Value: ");
  Serial.println(ChannelPinF);

  // Control motor Left/Right directions
  if (ChannelPinD > 1500) {                             // Right
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    analogWrite(enablePin1, 100);

    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
    analogWrite(enablePin2, 0);
    Serial.println("Moving Right");
  } 
  else if 
    (ChannelPinD < 1400) {                              // Left
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    analogWrite(enablePin1, 0);

    digitalWrite(motorPin3, HIGH);
    digitalWrite(motorPin4, LOW);
    analogWrite(enablePin2, 100);
    Serial.println("Moving Left");
  } 
  else {  // Stop
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    analogWrite(enablePin1, 0);

    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
    analogWrite(enablePin2, 0);
    Serial.println("Stopping");
  }

  // Control Forward/Backward
  if (ChannelPinF > 1700) {                             // Forward
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    analogWrite(enablePin1, speedPin);

    digitalWrite(motorPin3, HIGH);
    digitalWrite(motorPin4, LOW);
    analogWrite(enablePin2, speedPin);
    Serial.println("Moving Forward");
  } 
  else if 
    (ChannelPinF < 1500) {                              // Backward
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
    analogWrite(enablePin1, speedPin);

    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, HIGH);
    analogWrite(enablePin2, speedPin);
    Serial.println("Moving Backward");
  } 
  else {  // Stop
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    analogWrite(enablePin1, 0);

    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
    analogWrite(enablePin2, 0);
    Serial.println("Stopping");
  }

  delay(20);                                            // Further reduced delay for immediate responsiveness
}

You nearly got it right. Code tags are three back ticks (```) on their own line before and after the the code. Where you went wrong was with ```Hi jim-p where the ``` where not on its own line

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.