Servo Motors behave differently under similar code

Hey,

Sorry for posting my code all over the place in this post but I wouldn't be able to fit it in the 9000 character limit. One of my programmes cause the servos to spin slowly but I've basically asked them to do the same thing.

So my programes are somewhat similar and borrow from each other. One asks for a users input only and displays it through servos (it ends up being Braille). The other features a mode select button. I am externally powering the motors and powering the button off of the 5V pin. I checked my battery and that's not the problem. I'm not sure if it's a hardware or software issue but I'm just posting here to be safe, but I'm torn between bad code or interference from the button.

(The first programme that works perfectly with the motors)

(This one uses the button and causes problems with my servos)

Regards,
Justin

Please ATTACH your programs to your post if they're too large to post inline. Many of us, me included, don't like having to go off to other websites just so we can download things. Help us to help you by following the instructions in "How to use this forum" which you must surely have read by now.

Steve

@justcunn

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

The other features a mode select button. I am externally powering the motors and powering the button off of the 5V pin. I checked my battery and that's not the problem.

what is the problem?

can you provide a more detailed description of the differences.

Yeah sorry about that, nothing much I can do about it now though and it's all there to view without downloading pretty easily.

Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Well I'm not sure where the problem lies so I decided to post in both. Since there is no 'neutral', per se, topic I just posted twice to make sure everybody from all backgrounds could help me.

can you provide a more detailed description of the differences.

Certainly. The first programme only has one feature: it reads the character from the serial monitor and then checks it against a list of if conditions to find the character that matches it and then certain motors are activated to produce a Braille character, but that side of my project isn't important.

The second programme includes support for a mode select button. Every time the button is pressed it cycles through different modes (functions) and resets once it reaches a certain number. The set up is pretty standard. The servos are connected to an external power supply with only the ground going back to the Arduino. The button is connected directly to the 5v pin with a 10kohm resistor.

The first programme allows the servos to rotate perfectly with no delay. The second has severe delay and the motors rotate extremely slowly. The code that controls the motors (those if statements and the "servo.attach(XX)" and what not were all copied from my first programme so I have no idea as to why the behaviour changes in the second programme.

Thanks,
Justin

by problem i meant what doesn't the program do?

i see some long delays. does the 2nd program appear non-responsive

Most servo problems reported on this forum result from an inadequate servo power supply.

Budget 1 Ampere per servo, more for heavy duty servos. Don’t forget to connect the servo power supply and Arduino grounds.

  • 1 sec in addCounter()
  • 5 sec in printMode() which calls transLit() which calls showData() which calls numSym()
  • 2 sec showData()
  • 1.5 sec numSym()

looks like a 9.5 sec delay is possible each loop iteration

having a 1 sec delay in addCounter() is one way to debounce a button press, but it doesn't capture the event - a change from off to on. holding the button increments the button every sec. Checking for a change and immediately checking for a continued active button press after a 20 ms is a reasonable approach for recognizing a button press.

a single delay in loop() in addition to a 20 msec delay in addCounter() may be reasonable, but waiting a specific amount of time before only calling printMode() w/o affecting other code would be better.

Most servo problems reported on this forum result from an inadequate servo power supply.

I tested the motors in both programmes and they only work correctly in one. So it's not a battery issue, but thanks for the reply :slight_smile:

i see some long delays. does the 2nd program appear non-responsive

It seems really really slow, like the gap between servo rotations seem noticeably slower than in my last program. But like what gciurpita said and yourself, there are a lot of delay functions, I forgot delay() pauses the whole programme completely. That's likely the issue here. I'll likely remove the print function completely and find other ways to cut delay time.

Thanks everyone!