Hello, i’ve been trying to write some code for the use of 4 continuous rotation servomotors and i still haven’t figured it out. I’ve written some stuff but they continiously twitch and do strange things and don’t follow the code or they restart de loop before it has ended. Here is one example of the code i’ve done, i would much apreciate if you could give me any tips or tell me what is wrong because i haven’t found any information on the intenet about multiple servos control, so i’m a little bit lost about it. I’m building a robot and i need to be able to control the 4 servos independently because each one does a thing at different times, so the first servos runs while they all stop then servo number three has to turn and so on. But ii haven’t beeen able to figure it out. Here is my best attempt of the code but in the first paragraph of code it stops and starts the loop al over again. The notes are in Spanish because it’s my native language but these notes are irrelevant to understant the code, they are just for my robot.
It looks to me like what you posted is incomplete. Can you post it including the entire sketch?
99% of the time, when servos are misbehaving and restarting the sketch, the cause is pulling too much power from the arduino.
Are you powering the servos from the arduino? Don't.
Servos pull more current than the regulator on the arduino can supply. This is bad.
Much better to provide a separate power supply for the servos. Make sure the grounds are connected.
I usually have a picture I post showing how it can be done but I am on my iPad rather than my PC so have no access.
joanro4:
but they continiously twitch and do strange things and don’t follow the code or they restart de loop before it has ended.
Twitch and do strange things does not convey what actually happens.
The restarting of loop() makes me wonder if you are trying to power the servos through the Arduino (which you should not do) which is causing the Arduino to reset when the voltage drops. Servos (and any motor) should be powered separately from the Arduino and should have a common GND with the Arduino.
If the problem exists even though you do have separate power for the servos it may be useful to make a short video of the problem and upload it to YouTube so we can view it.
It is always a good idea to include Serial.print() statements in your program so you can see which parts are active.
Finally, please modify your post and use the code button </>
Don'tcha love those F**ing diagrams where you have to put labels next to the pictures to explain that you didn't really mean to use that component in the picture.