Troubleshooting SG90 Servo twitching, buzzing and overheating issues in multi-servo arduino project

Dear @999,
I don't know if you have already solved by applying the other PU's hints, but having a quick look to your .ino I see that you allow readings on the BT line only if you have some characters available on the serial line (the one from the PC, in other words the Serial Monitor of Arduino). Therefore until you don't receive a string on the serial monitor (i.e. terminated with a \n) neither the BT input line is checked. Moreover you've set a timeout on the BT line, and this can produce a sudden interruption in the middle of a receiving if, for some reason, the app is delaying its sending.
As I said, it's just a very quick sight to your Arduino code, but give it a chance, by freeing the BT input readings from the condition that also from the Serial Monitor is coming a string. In other words, don't make all the main loop activities depending on the Serial Monitor.
Hope it helps.
Tschuess.

EDIT: I see that you use plenty of delay() functions: please be aware that depending on the Arduino board you're using, this function completely blocks the CPU and while "delaying" neither the Serial Monitor works (and most often also the "interrupts" probably used by the servo are not serviced), Not all the boards behave in the same way, but to avoid falling in this doubt, please use instead the millis() function.
For example:

void MYdelay(unsigned long interval)
{
unsigned long currentMillis;
currentMillis = millis();
while ((millis()-currentMillis) < interval);
}

when you need a delay do like this:
...
MYdelay(30); // waits for 30 milliseconds without stopping the CPU
...

1 Like

Thank you for your message.
I will try to implent this (hopefully I can manage it).
The problem is not completely solved yet.

Even with the latest codes, the following problems still persist:

  • the servos do not always move when I adjust the slider
  • they ocasionally jitter
  • the gripper arm does not move at all when I adjust the slider

However, I have tested each servo individually using the arduino IDE with tests codes that allow me to control each servo seperately. In those tests, the servos move withput any issues, includig the gripper arm.

But with the new codes, it works much better, and it no longer looks like the robot has Parkinson's.
Thank you very much for your help!

The Parkinson's movement can be really due to the fact that the library that manages the servos is somewhat interrupted in its activity by an unwanted CPU blocking.
I see that you use the SoftwareSerial library to manage the BT line (are you using a UNO board ?) but it would be preferable to use other pins, having PWM capabilities. Probably you can't, because you need PWM for the servo, but also the Serial Line works better with a pin capable of PWM. Anyway, another hypotesis could be: to avoid to use the Serial Monitor (on pins 0,1 in case of a UNO) and to use those pins for the BT comm's.
The annexed ino below, implements what I said. It compiles error free for a UNO board. I didn't test it, obviously, bacause I don't have a HW with servos.

  1. The BT serial line moved to pins 0,1 (i.e. the line normally used for the Serial monitor and for the code downloading),
  2. Therefore no check at all for any incoming string from the serial monitor, neither no messages at all to the Serial Monitor. Your Arduino code is "mute" toward the PC, but at least we can discriminate if it is a bottleneck of transmission that causes the Parkinson.
  3. ddelay() instead of delay()

Please pay attention that if you move the BT line on pins 0,1 you shall remove the connection toward the BT (an HC05/06 ?) before attempting to download a new code into the board, because the Monitor Serial Line is the same that connects the Arduino board to the PC via USB.

:crossed_fingers:
14_1_US_versuch.ino (14.8 KB)

1 Like

I use an Elegoo Mega R3 as a circuit board and an HC-05 Bluetooth module

Ok on the Mega there should be 4 serial lines therefore you don't need to use the SoftwareSerial at all. The 4 serial lines are HW and their comm's capabilities are equal to the SerialMonitor one !!!
In any case, try at least once my code without ANY communication to/from the PC, in order to see where is the bottlneck that could create the parkinson. I remember that I've got crazy by using the delay() on a Mega, that was completely blocked and it was not receiving nor sending anything on any serial line untl the delay() function was elapsed. I don't know whether new versions of the compilers have changed this behaviour but, as a rule of thumb, in any of your codes avoid to use the ready made one and use yours.
If you succeed in this attempt, you can restore to communicate also toward the PC but in any case you shall separate the servos movement from any communication from the PC. Your first if(serial:available >0) must not block any servo movement. You shall not put all the movement within that if.
Best wishes.

1 Like

This code didn't run at all ,but thank you for your help. Maybe it is my fault an I forgot smth to add but I tried it several times .

Sorry for my late reply, but I was not attending the PC.
Have you succeeded ?
Is it still not working for you ?