Contatnt servo jitter when using remote control

Hello all,

i need your help to solve my problem.

I am using Arduino Nano to control two digital servos to move in different positions depending of combination of two switches. this part is working fine. There is some small glitches time to time , but i can live with that.

My problem came when i tried to use the same Arduino Nano as receiver. When Arduino receive a string trough RX module i want to move the servos in other position. I am using simple 433MHz RX and TX modules like this:
https://www.aliexpress.com/item/Best-Quality-1pair-lot-433MHZ-Superregeneration-Wireless-Transmitter-Module-Burglar-Alarm-and-Receiver-Module/2022377239.html?spm=2114.13010608.0.0.3Kqj4m

First i tried to use Servo and VirtualWire libraries. To start working together i modified the VirtualWire to use Timer 2. On the end is working but with constant servos jitter. The servos was getting hot and the battery quickly down.

Next trial was to use ServoTimer2 and VirtualWire libraries - absolutely the same servo jitter. even when the RX module is not powered.

The only way to stop jitter was to comment "//vw_rx_start();", but unfortunately receiver is not working in this case.

Then i tried to use RadioHead instead of VirtualWire - same problem.

I am sure that many of you face and solve this problem somehow. Unfortunately i didn't found a solution in internet.

PLEASE HELP ME!

Unfortunately i didn't found a solution in internet.

Nor did you post your code. We can not help you without seeing your code.

A schematic is in order, too.

Sorry.

Full RX code is quite long. i tried with simple example like bellow and the result is the same. Even I am not trying to move the servos in loop. They are just attached and i receive the jitter.

#include <Servo.h>
#include <VirtualWire.h>

Servo Elevator;
Servo Rudder;

void setup()
{
  Elevator.attach(2);            // Elevator servo output to pin D2
 // Elevator.write(70);           // tell servo to go to position in variable 'pos'
  delay(300);
  Rudder.attach(3);              // Rudder servo output to pin D3
 // Rudder.write(75);     // tell servo to go to position 'RudderGlide'
  delay(300);
  
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_set_rx_pin(8);
    vw_setup(1000);  // Bits per sec
    pinMode(13, OUTPUT);

    vw_rx_start();       // Start the receiver PLL running
}
    void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
      if((buf[0]=='F')&&(buf[1]=='1')&&(buf[2]=='H')){   
      digitalWrite(13,2);
      delay(1000);
      }  
      }
      else{
  digitalWrite(13,0);
    }

}

Similar code i tried with Servotimer2

#include <ServoTimer2.h>

// RX

#include <VirtualWire.h>

ServoTimer2 Elevator;
ServoTimer2 Rudder;

void setup()
{
  Elevator.attach(2);            // Elevator servo output to pin D2
  delay(300);
  Rudder.attach(3);              // Rudder servo output to pin D3
  delay(300);
  
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_set_rx_pin(8);
    vw_setup(1000);  // Bits per sec
    pinMode(13, OUTPUT);

    vw_rx_start();       // Start the receiver PLL running
}
    void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
      if((buf[0]=='F')&&(buf[1]=='1')&&(buf[2]=='H')){   
      digitalWrite(13,2);
      delay(1000);
      }  
      }
      else{
  digitalWrite(13,0);
    }

}

Schematic explanation:
I am powering the Nano with 2cells LiPo battery (7.2-8.4V) trough 7805 voltage stabiliser connected to GND and 5V. I am using 7805 to power the servos parallel to Nano. Servo signals are connected to pin D2 and D3. RX to pin D8. I have also 2 switches connected to D4 and D5 and buzzer to D9.

      digitalWrite(13,2);

2? Is that REALLY_HIGH?

I can not imagine using cheap radios on anything that has an Elevator and a Rudder. Their range is minimal.

v_peykov:
Schematic explanation:
I am powering the Nano with 2cells LiPo battery (7.2-8.4V) trough 7805 voltage stabiliser connected to GND and 5V. I am using 7805 to power the servos parallel to Nano. Servo signals are connected to pin D2 and D3. RX to pin D8. I have also 2 switches connected to D4 and D5 and buzzer to D9.

In my projects, jittery servos have meant that they are not being supplied with enough power.

IMPORTANT: Take a look at the LM7805 datasheet. The approximate output current of one of those bad boys is 8mA MAX, while a single servo at full load demands somewhere around 250mA! YOU NEED A BETTER POWER SUPPLY.

Also, make sure you have large current limiting resistors on your switches.

while a single servo at full load demands somewhere around 250mA!

Or more. Sometimes way more. The usual guideline is 1A per servo.

I thought about power problems, too, but OP said the servos were stable until adding the radios.

It certainly wouldn't be wrong to power the servos properly. OP: Servos do not need regulated power.

Take a look at the LM7805 datasheet. The approximate output current of one of those bad boys is 8mA MAX,

Really? 8mA?

What LM7805 are you looking at? Most are rated for 1 to 1.5A outputs.
http://www.digikey.com/product-search/en/integrated-circuits-ics/pmic-voltage-regulators-linear/2556290?k=lm7805

The batteries, of which not much is said, may not be able to supply that much current, which is a different story.

2cells LiPo battery (7.2-8.4V)

CrossRoads:
What LM7805 are you looking at? Most are rated for 1 to 1.5A outputs.
http://www.digikey.com/product-search/en/integrated-circuits-ics/pmic-voltage-regulators-linear/2556290?k=lm7805

The batteries, of which not much is said, may not be able to supply that much current, which is a different story.

Nvm, misread the datasheet. Still, I don't think 1A nominal is enough to power the servos, switches, Arduino, AND the radio.

PaulS:
I thought about power problems, too, but OP said the servos were stable until adding the radios.

It still seems like a power problem: I imagine the radio unit draws enough power to take the project over power budget.

In my experience, Servo jitter is one of two things:

You forgot to connect the Servo Ground to Arduino Ground.
or
You are using SoftwareSerial or some other library that disables interrupts for more than a couple of microseconds. I would not be surprised if Virtual Wire disabled interrupts while reading pulse streams from the radio.

1 Like

Thank you for all comments.
I will try to answer and enplane what i tried yesterday evening.

PaulS:
I can not imagine using cheap radios on anything that has an Elevator and a Rudder. Their range is minimal.

You are right. The range is minimal and is not naught, but o try my idea is OK. Can you propose me other RX/TX with bigger range - 4 to 6km?

PaulS:
Or more. Sometimes way more. The usual guideline is 1A per servo.

I thought about power problems, too, but OP said the servos were stable until adding the radios.

It certainly wouldn't be wrong to power the servos properly. OP: Servos do not need regulated power.

7805 is more than 1Amp. i measured the compulsion during servos moving. It is not more than 0
.15A. The servos are small.
Your conclusion for power problem is correct. it shouldn't be power problem because when i comment in the program everything related with the Radio there is no jitter.
I was thinking that may be the 7805 is not giving me stable voltage and this put some noise in PWM signal. To test this i power the Arduino directly with 4 MiNh sells (5V) - no difference.

Power_Broker:
Nvm, misread the datasheet. Still, I don't think 1A nominal is enough to power the servos, switches, Arduino, AND the radio.

It still seems like a power problem: I imagine the radio unit draws enough power to take the project over power budget.

Power consumption of the radio is not the problem. I tested with disconnected RX module. The jitter is the same. To have jitter is enough to have Radio related lines in the program and to switch ON receiving in the program (with "vw_rx_start();").

johnwasser:
In my experience, Servo jitter is one of two things:

You forgot to connect the Servo Ground to Arduino Ground.
or
You are using SoftwareSerial or some other library that disables interrupts for more than a couple of microseconds. I would not be surprised if Virtual Wire disabled interrupts while reading pulse streams from the radio.

Servo Ground to Arduino Ground is connected.

I will test this evening if Virtual Wire disabled interrupts while reading pulse streams from the radio.

During my yesterday tests i found that i have constant jitter only when "looping" in some parts of my program. i tried to simplify the program to this:

#include <Servo.h>
#include <VirtualWire.h>


Servo Elevator;
Servo Rudder;

int d_circ	=	75	;
int d_tow	=	61	;

int d_glide	=	87	;
int RudderGlide = 85;
int RudderTow = 96;


int glide	=	5;               // Gliding time
int BuzzerPin = 9;               // set Buzzer pin to 9
int pos = d_glide;
int ledPin = 13;                 // LED connected to digital pin 13
const int TowPin = 4 ;           // TOW switch to pin 4. HIGH-front; LOW-back
const int LockPin = 5 ;          // Lock switch to pin 5. LOW-open; HIGH-lock
int OpenHookStart = 0;           // for start with open hook = 1, for BUNT start = 0
int GlideMin = 0;
int Glideds = 0;
int Glides = 0;
int GlideMinSet = 0;
int GlidedsSet = 0;
int GlidesSet = 0;

// ------------------------
int TowPinState;                 // Current state of the TOW button
int button_delay = 0;
int LockPinState;                // Current state of the Lock button for hold of line - DT
int LockButton_delay = 0;
// ------------------------


void setup() {
  Elevator.attach(2);            // Elevator servo output to pin D2
  Elevator.write(pos);           // tell servo to go to position in variable 'pos'
  delay(300);
  Rudder.attach(3);              // Rudder servo output to pin D3
  Rudder.write(RudderGlide);     // tell servo to go to position 'RudderGlide'
  delay(300);
//  Wiggler.attach(4);           // Wigglerservo output to pin D4
  pinMode(ledPin, OUTPUT);       // sets the digital pin as output
  pinMode(TowPin, INPUT);        // input for TOW button
  pinMode(LockPin, INPUT);       // input for Lock button
  pinMode (BuzzerPin, OUTPUT);

//    PArt of RDT program
    vw_set_ptt_inverted(true);   // Required for DR3100
    vw_set_rx_pin(8);
    vw_setup(4000);              // Bits per sec
    vw_rx_start();               // Start the receiver PLL running */


  if (digitalRead(TowPin) == LOW && digitalRead(LockPin) == LOW)
  {
  OpenHookStart = 1;
  }
}

    
 void loop() {

// Start with open Hook
  if (OpenHookStart == 1 && digitalRead(TowPin) == HIGH && digitalRead(LockPin) == LOW)       // TOW with open hook
  {
    Tow_Open_Hook();
   }
  else if (OpenHookStart == 1 && digitalRead(TowPin) == LOW && digitalRead(LockPin) == LOW)    // Start with open hook
  {
    Serial.println("Start with open hook");
    digitalWrite(BuzzerPin, LOW);                  //Buzz OF
 
         for (int i = 0; i <= glide*10;)
         {
           if (digitalRead(TowPin) == LOW)
           {
            i=i+1;
            Glide_Open_Hook();
           }
           else if (digitalRead(TowPin) == HIGH) {
           Tow_Open_Hook();
           i=0;
           }
         }
   } 
}


void Tow_Open_Hook(){
    digitalWrite(ledPin, HIGH);
      Elevator.write(d_tow);               
      delay(30);
      Rudder.write(RudderTow);               
      delay(30);
   }

void Glide_Open_Hook(){
      Elevator.write(d_glide);               
      delay(30); 
      Rudder.write(RudderGlide);               
      delay(30);
    digitalWrite(ledPin, HIGH);
    delay (15);
    digitalWrite(ledPin, LOW);
    delay (85);

 }

and there is jitter when the program is executing "for (int i = 0; i <= glide*10;)". So every time when i go through the loop I am telling to the servos to go to the same position and may be for some reason (timing or noise) the servos are receiving slightly different position and is trying to go there every time when read "Elevator.write(.....".

Then I decided to try to attach the servos only when i need to move the servos in different position and after that to detach them.
Remark: The servos that I am using is holding the position even that they are detached.
See the code bellow:

#include <Servo.h>
#include <VirtualWire.h>


Servo Elevator;
Servo Rudder;

int elemove;
int rudmove;

int d_circ	=	75	;
int d_tow	=	61	;

int d_glide	=	87	;
int RudderGlide = 85;
int RudderTow = 96;


int glide	=	5;               // Gliding time
int BuzzerPin = 9;               // set Buzzer pin to 9
int pos = d_glide;
int ledPin = 13;                 // LED connected to digital pin 13
const int TowPin = 4 ;           // TOW switch to pin 4. HIGH-front; LOW-back
const int LockPin = 5 ;          // Lock switch to pin 5. LOW-open; HIGH-lock
int OpenHookStart = 0;           // for start with open hook = 1, for BUNT start = 0
int GlideMin = 0;
int Glideds = 0;
int Glides = 0;
int GlideMinSet = 0;
int GlidedsSet = 0;
int GlidesSet = 0;

// ------------------------
int TowPinState;                 // Current state of the TOW button
int button_delay = 0;
int LockPinState;                // Current state of the Lock button for hold of line - DT
int LockButton_delay = 0;
// ------------------------


void setup() {
  Elevator.attach(2);            // Elevator servo output to pin D2
  Elevator.write(pos);           // tell servo to go to position in variable 'pos'
  delay(300);
  Rudder.attach(3);              // Rudder servo output to pin D3
  Rudder.write(RudderGlide);     // tell servo to go to position 'RudderGlide'
  delay(300);
//  Wiggler.attach(4);           // Wigglerservo output to pin D4
  pinMode(ledPin, OUTPUT);       // sets the digital pin as output
  pinMode(TowPin, INPUT);        // input for TOW button
  pinMode(LockPin, INPUT);       // input for Lock button
  pinMode (BuzzerPin, OUTPUT);

//    PArt of RDT program
    vw_set_ptt_inverted(true);   // Required for DR3100
    vw_set_rx_pin(8);
    vw_setup(4000);              // Bits per sec
    vw_rx_start();               // Start the receiver PLL running */


  if (digitalRead(TowPin) == LOW && digitalRead(LockPin) == LOW)
  {
  OpenHookStart = 1;
  }
}

    
 void loop() {

// Start with open Hook
  if (OpenHookStart == 1 && digitalRead(TowPin) == HIGH && digitalRead(LockPin) == LOW)       // TOW with open hook
  {
    Tow_Open_Hook();
 
  }
  else if (OpenHookStart == 1 && digitalRead(TowPin) == LOW && digitalRead(LockPin) == LOW)    // Start with open hook
  {
    Serial.println("Start with open hook");
    digitalWrite(BuzzerPin, LOW);                  //Buzz OF
 
         for (int i = 0; i <= glide*10;)
         {
           if (digitalRead(TowPin) == LOW)
           {
            i=i+1;
            
Glide_Open_Hook();
           }
           else if (digitalRead(TowPin) == HIGH) {
          Tow_Open_Hook();
           i=0;
           }
         }
   } }


void Tow_Open_Hook(){
    Serial.print("TOW with open Hook");
    digitalWrite(ledPin, HIGH);

    if(elemove != d_tow) {
      elemove=d_tow;
      Elevator.attach(2);
      Elevator.write(elemove);               
      delay(30); 
      Elevator.detach(); 
      }

    if(rudmove != RudderTow) {
      rudmove=RudderTow;
      Rudder.attach(3);
      Rudder.write(rudmove);               
      delay(30);
      Rudder.detach(); 
   }
      
    digitalWrite(BuzzerPin, LOW);
    LockButton_delay = 0;
}

void Glide_Open_Hook(){

    if(elemove != d_glide) {
      elemove=d_glide;
      Elevator.attach(2);
      Elevator.write(elemove);               
      delay(30); 
     Elevator.detach(); 
    }

    if(rudmove != RudderGlide) {
      rudmove=RudderGlide;
      Rudder.attach(3);
      Rudder.write(rudmove);               
      delay(30);
      Rudder.detach(); 
    }
    digitalWrite(ledPin, HIGH);
    delay (15);
    digitalWrite(ledPin, LOW);
    delay (85);

 }

And it is working without jitter :slight_smile:

Now the main question. Is it OK to do it in this way? To attach and detach all the time the servos. Can some other problems appear if i do it in this way?

Do you have pullup (or pulldown) resistors on pins 4 & 5? If not the pins are "floating" when the buttons are not pushed and may be causing false inputs.

Hi,
Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Have you got bypass capacitors fitted and the correct capacitors around the LM7805, as close as possible to its legs?

Thanks.. Tom.. :slight_smile:

           if (digitalRead(TowPin) == LOW)
           {
            i=i+1;
            Glide_Open_Hook();
           }
           else if (digitalRead(TowPin) == HIGH) {

Will you eventually be adding code to deal with the other values that digitalRead can return?

      Elevator.attach(2);
      Elevator.write(elemove);

WTF? You do NOT need to keep attaching the servos instances. They do not come detached willy-nilly.

     Elevator.detach();

Oh, wait. That willy-nilly idiot did detach your servo.

Well, THERE is your jitter. Stop detaching the servos!