ServoMoteur jerks with HC12

Hello everyone, I am encountering an issue using an HC12 transmitter receiver, a Servo and an ESC.
I use them to communicate with my RC car, remotely.
Issue: On the receiving end, my servomotor jerks and strange characters appear on my serial monitor.
Here is the wiring diagram :


here's a photo of the assembly:

Here is the code I use for reception:

#include <Servo.h>
#include <SoftwareSerial.h>

// Pins for HC-12
const int HC12_TX_PIN = 3; // HC-12 TX to Arduino D3
const int HC12_RX_PIN = 2; // HC-12 RX to Arduino D2

// Pin for ESC and Servo
const int SERVO_PIN = 5;

SoftwareSerial HC12(HC12_TX_PIN, HC12_RX_PIN);
Servo esc; // Create a Servo object for the ESC

void setup() {
  // Start the serial communication with HC-12
  HC12.begin(9600);
  // Start the serial communication with the computer (for debugging)
  Serial.begin(9600);

  // Attach the servo to the pin
  myServo.attach(SERVO_PIN);
  // Attach the ESC to the pin
}

void loop() {
  if (HC12.available()) {
    // Read the incoming string
    String dataReceived = HC12.readStringUntil('\n');
    Serial.println(dataReceived);
    
    // For debugging

    // Parse the string to get the motor power and servo position
    int commaIndex = dataReceived.indexOf(',');
    if (commaIndex > 0) {
      int motorPower = dataReceived.substring(0, commaIndex).toInt();
      int posServo = dataReceived.substring(commaIndex + 1).toInt();

      // Set the servo position
      myServo.write(posServo);
      delay(100);
    }
  }
}

I receive a string whith this format : "x, y" with x the motor power (we don't care) and y the servo position
When no servo is connected, I receive well the data like this (serial monitor):

91,22
91,22
91,22
91,22

But when the servo is connected, the data start to jerk like this (serial monitor):

����91,22
��������������������91,22
91,22
91,22
������91,22
91,22
91,22
91,22
�������91,22
91,22
91,22
91,22
��������

whenever I receive these weird caracters, the servo starts to jerk and i want to avoid that. I checked the voltage of the servo and it oscillates between4.2 and 4.8 V
Have you ever encountered such an issue ? Feel free to ask me further information.
Thank you in advance !

Where does the U1 5 volt come from? Not enough of current is suspected.
Please post a link to the servo datasheet.

@Railroader in this case, the U1 5V comes from USB. I tried with my ESC connected to a LiPo 3S which outputs 5.9V but the issue is still here.
Here is the datasheet:

USB is specified to 500 mA so the powering is not in order. Give the servo a better 5 volt supply.
ESC? What did that wiring look like?

I tried this assembly:


Basically, I powered my Servo with my Electronic Speed Controller, powered by a lipo 3s battery.
:arrow_forward: the jerk is still here but I no longer have the strange characters appearing in the serial port.

Look at the little signal current flowing from the UNO to the servo. It must have some way to return to tbe controller. That spells GND.

You are using BEC to supply servo. Just verify it can supply 2.5A, it can be lower even if you have high amp ESC.

But first fix issue that @Railroader mentioned.

I'm not sure I understand why the servo must also be grounded with the arduino. I tried it anyway, plugging GND from Servo to GND of Arduino, issue is still here. I also trieds using 3 capacitors 100µF in parallel to smooth the current, but nothing helps.

Thanks for your reply, from the datasheet : "It is built-in 5.5V/3A BEC which can power receiver or other suitable equipment". So it should deliver 3A.

What @Railroader said:

You need a return path for the servo signal.

Then You have one more mistake to find.
If You don't understand the need of both signal and ground You really need to step bak to basic circuitry studying.

Does the BEC have a source delivering the current needed?

I don't quite get how bad this assembly is :

The source is a Lipo 3s battery 11.1V

But for some reason it can't. Battery?
If the voltage drops from 5.8V to 4.2V, either or is not capable...

Battery works well
Voltage doesn't drop with the ESC connected. It supplies a clean 5.8V
I would have liked to look at the current supplied by the BEC, but the fuse on my multimeter is dead at the moment.

Quite misleading from you!!
If there is big voltage drop when servo starts, it is definitely powering issue. Whole different story, if there is not.... Then problem is somewhere else.

where is that myServo coming from? You defined:

I agree it is misleading : I have voltage drop when it was only powered with 5V from arduino USB. Now that it is ESC powered, no voltage drop.

You're right about the code. I wanted to remove the part that contributes to the brushless motor to make it clearer. Anyway, here's the full code I should have provided earlier:

#include <Servo.h>
#include <SoftwareSerial.h>

// Pins for HC-12
const int HC12_TX_PIN = 3; // HC-12 TX to Arduino D3
const int HC12_RX_PIN = 2; // HC-12 RX to Arduino D2

// Pin for ESC and Servo
const int ESC_PIN = 6;
const int SERVO_PIN = 5;

SoftwareSerial HC12(HC12_TX_PIN, HC12_RX_PIN);
Servo myServo;// Create a Servo object for the brushless motor
Servo esc; // Create a Servo object for the ESC

void setup() {
  // Start the serial communication with HC-12
  HC12.begin(9600);
  // Start the serial communication with the computer (for debugging)
  Serial.begin(9600);

  // Attach the servo to the pin
  myServo.attach(SERVO_PIN);
  // Attach the ESC to the pin
  esc.attach(ESC_PIN);
}

void loop() {
  if (HC12.available()) {
    // Read the incoming string
    String dataReceived = HC12.readStringUntil('\n');
    Serial.println(dataReceived);
    // Parse the string to get the motor power and servo position
    int commaIndex = dataReceived.indexOf(',');
    if (commaIndex > 0) {
      int motorPower = dataReceived.substring(0, commaIndex).toInt();
      int posServo = dataReceived.substring(commaIndex + 1).toInt();

      // Set the ESC position (motor power)
      esc.write(motorPower);
      // Set the servo position
      myServo.write(posServo);
      delay(100);
    }
  }
}

I'm sorry but I can't help you if your setup is changing continuously.
There can be only one exact setup at a time to investigate (hardware, wiring, code).
I suggest you to download a demo sketch to drive your servo without anything else.
When that works, add that other motor. When they both work, add that softwareserial code and HC12.

I understand, but the problem is isolated: no motor is connected. I'll add it once I've solved the vibration problem.
Would using a 470µF capacitor help smooth the current?

I might be wrong, but i believe there is an incompatibility between servo.h and softwareserial.h because of sharing the same interrupt. There are other librarys that dont interfere with each other.

1 Like