RC-Switch with RC car isn't outputting control signals correctly

So I have tried to create a remote control car controlled by a joystick (two potentiometers) but am failing to get it to work correctly. I am using an L293 H-Bridge motor driver to control one motor and also have a basic 180 degree servo connected straight to the arduino. The transmitter and receiver are 433Mhz modules and that was the first thing I checked when I started troubleshooting my code.
The modules send and receive fine a string of numbers on their own. I do not know where to start troubleshooting the motor control and servo control. Basically when I am moving the potentiometers, I can notice that the motor control changes but instead of a nice speed change or reversing, the motor kinda just turns on and off randomly every few seconds. I can’t find a pattern other than that it changes when the potentiometer is completely one way or another. The servo control doesn’t do anything. Thank you for any ideas y’all may have!

Transmitter Code

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

int drive;
int steer;

void setup() {

  Serial.begin(9600);
  
  // Transmitter is connected to Arduino Pin #10  
  mySwitch.enableTransmit(10);

}

void loop() {

int steer = analogRead(0) + 10000; //"encodes" the joystick x
// steering value into a distinquishable number on the reciever end.
int drive = analogRead(1) + 5000; //"encodes" the joystick y
// steering value into a distinquishable number on the reciever end.
  /* Same switch as above, but using decimal code */
  mySwitch.send(steer, 24); // sends "encoded" steering value
  mySwitch.send(drive, 24); // sends "encoded" motor control value
  delay(100);  

  
}

Receiver Code

#include <Servo.h>
#include <RCSwitch.h>

Servo myservo;

RCSwitch mySwitch = RCSwitch();

int drive;
int steer;

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
  myservo.attach(8);
  }

void loop() {
  if (mySwitch.available()) {
    
    int value = mySwitch.getReceivedValue();

    if (value == 0) {
      Serial.print("Unknown encoding");
    } 
    if (value < 10000){ // takes motor speed value encoded
      int drive = value - 5000; // "decodes" motor speed value
      int drivevalue1 = map(drive, 1, 1023, 0, 255); // maps value to PWM value
      if (drive < 512){ // for forward drive
      analogWrite(9, drivevalue1); // 9 will be high
      digitalWrite(10, LOW); // 10 will be low
      }
      if (drive >= 512){ // for backward drive
      analogWrite(10, drivevalue1); // 10 will be high
      digitalWrite(9, LOW); // 9 will be low
      }
    if (value > 10000){ // takes servo position value
      int steer = value - 10000; // "decodes" steering value
      int steervalue = map(steer, 1, 1023, 30, 150); // maps steering value to servo position
      myservo.write(steervalue); // writes servo position value to servo
      delay(15);
    }
    
    
    
    
    else {
      Serial.print("Received ");
      Serial.print( mySwitch.getReceivedValue() );
      Serial.print(" / ");
      Serial.print( mySwitch.getReceivedBitlength() );
      Serial.print("bit ");
      Serial.print("Protocol: ");
      Serial.println( mySwitch.getReceivedProtocol() );
    }
delay(50);
    mySwitch.resetAvailable();
  }
}
}

There are problems with the receive code.

  • It does not handle a value of 10000. (drive speed of 0)
  • It does not handle values of 1, 2, 3, ... up to 5000. (should be part of the unknown encoding error)
  • It does not print the received value.

There are probably additional problems as well. I do not know the RCSwitch library so I cannot be of further help. Sorry.

vaj4088: There are problems with the receive code.

  • It does not handle a value of 10000. (drive speed of 0)
  • It does not handle values of 1, 2, 3, ... up to 5000. (should be part of the unknown encoding error)
  • It does not print the received value.

There are probably additional problems as well. I do not know the RCSwitch library so I cannot be of further help. Sorry.

Thank you for the reply. I do not think that the problem lies within RC-Switch or the wireless transmission however because on the serial monitor on the receiver side, it prints the correct values sent from the transmitter (5001-6023) and (10001-11023). I think it is in my controller code or the (if) statements but I could be wrong.

Thank you

I believe the Servo library disables PWM on pins 9 & 10, try pins 3 & 11.