Hi,
I have been trying to control five servos via HC12 modules but they are jittering. I created a remote consisting of three potentiometers and five buttons. they are prefectly fine and I get the perfect outputs whikle testing on the serial monitor. I also recieve what I want to get on the second arduino. Also the servos work as they should do without connecting the HC12 module. I think the module somehow disrupts the timer of the arduino. Can you help? The test code is below. The for loop in setup function works properly if the mentioned line is inactive.
#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial HC12(10, 11); // HC-12 TX Pin, HC-12 RX Pin
Servo myservo;
int pos = 0;
void setup() {
myservo.attach(3);
Serial.begin(9600);
HC12.begin(9600); // <--- this line
for (pos = 0; pos <= 180; pos += 1) {
myservo.write(pos);
delay(5);
}
}
void loop() {
int a = HC12.read();
if (a > -1 && a < 19) {
Serial.println(a);
myservo.write(a * 10);
delay(15);
}
}
1 Like
Jittering servos usually indicates an inadequate servo power supply. Use a separate, 5-6V supply, capable of supplying at least 1 Ampere per servo for small servos, or 2-3 Amperes per servo for large ones. Don't forget to connect the grounds!
The other common issue is that the software serial library conflicts with the servo library. That can often be fixed by using the servoTimer2 library.
2 Likes
Thank you for the solutions. How can I get servoTimer2 and how can I exactly learn the pulse widht needed for my servos?
1 Like
In the Arduino IDE, go to Tools>Manage Libraries and select any libraries you need.
Trial and error works to determine pulse width versus servo position.
1 Like
#include <ServoTimer2.h> // the servo library
#include <SoftwareSerial.h>
SoftwareSerial HC12(10, 11); // HC-12 TX Pin, HC-12 RX Pin
ServoTimer2 servo1; // declare variables for up to eight servos
void setup() {
Serial.begin(9600); // Serial port to computer
HC12.begin(9600); // Serial port to HC12
servo1.attach(3);
}
void loop() {
int a = HC12.read();
if (a > -1 && a < 19) {
Serial.println(map(a * 10, 0, 180, 750, 2250));
Serial.println("----------");
servo1.write(map(a * 10, 0, 180, 750, 2250));
delay(30);
}
}
I wrote this code. This is much better than the previous one but it still jitters. I would be happy if you can help.
1 Like
Please post a link to your servos, your wiring diagram, and give the details on the servo power supply.
Please use code tags when posting code. You can edit your post to add them
1 Like
Is the information in the folder above enough?
1 Like
By the way this is not the actual circuit (a part of it). I use this to test and if I can find a solution I will apply it for the actual circuit.
1 Like
Sorry, I and many other forum members can't be bothered to look at an off-site posting. If you want help from this forum, post the requested product links and your images on this forum.
1 Like
Your wiring looks good, but you forgot to post a link to the servos, and the details of the servo power supply.
Required info: the stall current of the servo, and the voltage and amperage characteristics of the servo power supply. See reply #2.
A USB-output phone charger will NOT be able to power 5 servos of any sort, and not even one of the larger servos.
1 Like
Ya, I've had some problems in the past with jittering servos.
Use a 5-6V 2A or higher power supply. I'm assuming that's an SG90 Servo and those need more than 1A to run properly.
This is a note from the manufacture where I bought my SG90's:
- NOTE: The Starting Current of The Analog Servo Motor Should Be Over 1A and Miuzei Servo SG90 are Analog Servos Need to Continuously Provide a PMW Signal, Then it Will Be Work Normally;
If that doesn't help, try a different servo.
Also, make sure the servo has enough torque to move whatever it's moving (if you attached something to the servo). If the servo has barley enough torque to move whatever it needs to then it will cause some jitter.
If that doesn't work I use a Maestro Control Board from Pololu. It allows me to easily smooth out the servo movements, control the speed, acceleration, pause time, ect...
1 Like
Tower Pro SG90 RC Mini (9gr) Servo Motor
Properties
Dead band width: 7usec
Stall current: 650 ± 80 mA
Dimensions: 23.1 x 12.2 x 29mm
Weight: 9g
Operating voltage: 4.8 - 6.0 VDC
Speed @4.8V: 0.1 sec/60°
Strain Torque @6V: 1.8 kg.cm
Gear box: Plastic
Rotation angle: 0-180°
Working PWM signal: 500-2400 μs
Cable Length: 15 cm
Hopefully these will be enough.
1 Like
Required info: the stall current of the servo, and the voltage and amperage characteristics of the servo power supply. See reply #2.
A USB-output phone charger will NOT be able to power 5 servos of any sort, and not even one of the larger servos.
You need a 5 Ampere power supply for 5 SG-90 servos.
1 Like
You're going to need a 10A or higher power supply for 5 servos. (At least 2A/servo)
Something Like this
1 Like
It says it needs 100-250mA typically and I do not have any load on them yet. I am creating a prototype before creating the final product. Also the adapter is 2A on 5v and 1.67 on 9v. Also is it fine to connect more 5v adapters parallel while testing.
In the final product I am planning to use 4000mah 7.4 v lipo. And mg995 motors. (mg995 properties)
1 Like
I would use 6V so you get the full torque of the servo and it should help with the jitter. I personally always use 6V and I haven't had much problems with my servos (I also use a high amperage power supply 6V 60A to ensure all my servos get enough power).
Yes, they do say 100-250ma but they will draw a bit more on startup.
1.67 on 9v
Just curious, what's the 9v 1.67A for?
I do not know. Probably to just tell it can do that.
A good rule thumb I use is 1-2A for a micro servo (1kg). 2-3A for standard servos (13-25Kg) and 3A or higher on bigger servos (35-60kg) at 6V
1 Like