One out of two servo motors will not run

Hi, I have started teaching myself to do projects with arduino and raspberry pi from the start of this year, so am still learning a lot. I've been working through the mind-controlled arduino robot project (the MakerPress book) since June and and stuck on one aspect of it: I have printed the chassis, wired it up and loaded the first two pieces of basic code on it, but only one servo motor runs. I will attach photos of the robot in its current state, top and bottom (had some trouble doing this, so will attach the photos to a reply to this thread).
Some key parts of the unit:

  • Arduino Leonardo
  • Proto-Screwshield (Wingshield) R3 Kit for Arduino
  • Spring SM-S4303R JR Interface 360 Degrees Continuous Rotation Servo

Some of the troubleshooting that I've tried so far:

  • Swapping the leads for the two servos with each other (you'll see the connector halfway along the cable). When I did this, the other servo ran.
  • Using digital output 4 instead of 2 (wiring and code). Before I did this, the left wheel ran well and the right didn't run at all. After I swapped, the right ran poorly (maybe 5 degree turns intermittently) and the left wheel stopped. When I went to set it back, as soon as I disconnected the digital output from 4, the left wheel started again.
  • Put the two servos into separate grounds rather than the same. No change.
  • Tried running with two other servos and got the same issue.
  • Tried running using a different arduino (uno) and got the same issue.

So I think it must be something to do with the screwshield, but can't work out what. I'm new to soldering (and everything else!), but I fixed any soldered pieces where two inputs/ outputs were touching. I can't see what else it could be.

Would be interested to know any thoughts anyone has on what the next steps should be for troubleshooting.

Thanks!

My code for making the wheels run is below and photos of top of robot is attached!
Robot_Top_16Oct21

// forward.pde

const int servoLeftPin=3;
const int servoRightPin=2 ;

void setup()
{
  pinMode(servoLeftPin, OUTPUT);
  pinMode(servoRightPin, OUTPUT);
}

void loop()
{
  forward();
}

void forward()
{
  for (int i = 0; i < 10; i++) {
    pulseServo(servoLeftPin, 1500-500);
    pulseServo(servoRightPin, 1500+500);
  }
}

void pulseServo(int pin, int microseconds)
{
  digitalWrite(pin, HIGH);
  delayMicroseconds(microseconds);
  digitalWrite(pin, LOW);
  delay(5);
}

Thanks for any troubleshooting tips!

Always post your code using code tags. Please edit your post above and fix that.

void forward()
{
for (int i = 0; i < 10; i++) {
pulseServo(servoLeftPin, 1500-500);
pulseServo(servoRightPin, 1500+500);
}
}

I don't understand why code to make the robot move forward would send different values to the two servos? EDIT: ok, I get it now. The servos are mounted opposite each other and must run in 'opposite' directions to make the wheels go in the same direction.

However, from your description of the things you have tried, I think this is not a code problem.

Your dark blurry picture does not allow us to spot any problems. What we need to see is close-up, bright clear photos, and a schematic.

Try slowing down the frame rate to 50Hz

Hi, @trevelyan77
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

Can you please post your code in tags and can you please post a circuit diagram of your project.
Please include power supplies and component and pin labels.

Have you got the gnd of all the servos connected to the gnd of the Leonardo?

void forward()
{
for (int i = 0; i < 10; i++) {
pulseServo(servoLeftPin, 1500-500);
pulseServo(servoRightPin, 1500+500);
}
}

What if you did this;

void forward()
{
for (int i = 0; i < 10; i++) {
pulseServo(servoLeftPin, 1000);
pulseServo(servoRightPin, 1000);
}
}

They should turn at the same speed but in different directions.

This worries me.

void pulseServo(int pin, int microseconds)
{
digitalWrite(pin, HIGH);
delayMicroseconds(microseconds);
digitalWrite(pin, LOW);
delay(5);
}

As you change microseconds HIGH you do not change how long LOW is to compensate and keep the PPM servo signal at constant frequency.

Case1;
When you have a 1000us high you have a 5us low, period of signal == 1005us.
Case2;
When you have a 2000us high you have a 5us low, period of signal == 2005us.

Your pulse frequency changes by a factor of 2:1.
It should be constant.

You should be using Servo library.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

It's PWM.
PPM is just the stream between transmitter and receiver

If that is really a .pde file then it is VERY old. It would make more sense to modify it to use the current Servo library (or find an already updated version).

But your problem seems more likely to be wiring/connections or maybe insufficient power. How is everything powered?

Steve

Hi,

To much blood in the caffeine stream.
But you can see what the problem with changing frequency can cause?

Thanks for responses. Am going through them. I put my code into code tags and have attached a schematic picture. I'll attach some better pictures of the units.

Hi all,
Multiple queries there, so will answer them below:

  • Unit is being powered from a raspberry pi
  • Something I forgot to mention before is that I've gotten multiple low voltage alarms on the raspberry pi once the robot was connected. I found a 5V and ground wire which were stripped too far and crossed each other. So I fixed this, but still got one or two low voltage alarms since so think there's also an issue elsewhere.
  • Am building this from a book [Make a Mind Controlled Arduino Robot: Use Your Brain as a Remote by Maker Press](https://Make a Mind Controlled Arduino Robot)
  • The book includes code which I've included above for running the servos. It does mention the servo library and points to the pluses and minuses of this bespoke code. I really don't think the code is the issue and is straight from the book - I posted it to help people understand how it works. I very much see this as an electronic/ wiring issue and am interested in views of how I could troubleshoot it further to get to the root cause.
  • I'm attaching a closer picture of the left side following a comment that the pic I posted was hard to see detail in. I will post another in a moment of the right side.

And a picture of the wiring on the right side:

In theory, yes, in practice no.

Hi,

Servo is expecting a constant frequency, variable duty cycle.
eLZ88
In fact 50Hz, the code above changes the frequency as well as the duty cycle.

Tom... :smiley: :+1: :coffee: :australia:

Hi, @trevelyan77
Can you please try this code, it uses the Servo library, which should already be in the IDE.

#include <Servo.h>

Servo Leftservo;  // create servo object to control a servo
Servo Rightservo;  // create servo object to control a servo


void setup()
{
  Leftservo.attach(3);  // attaches the servo on pin 3 to the servo object
  Rightservo.attach(2);  // attaches the servo on pin 2  to the servo object
}

void loop()
{
  forward();
}

void forward()
{
  Leftservo.write(180);
  Rightservo.write(0);
}

Tom... :smiley: :+1: :coffee: :australia:

What do you mean by this - what's powering the Pi?

Servos pull quite a lot of current and in consequence, the vast majority of issues that involve them are power related. Your low voltage alarms tend to suggest that that's the case for you too.

Hi, I tried the code changes you suggest with setting them both to 1000 microseconds in the pulseservo routine and keeping the two delays the same. The issue persists where the left wheel runs and not the right.

Both servos are grounded to the arduino through a screwshield.

The two servos are connected to the same 5V supply point as per the photos. I disconnected the left wheel from the 5V supply to see if the right started to run, but it didn't.

Hi, I tried that. The left wheel runs backwards and the right doesn't run.

Hi,
The longer term plan is to run the robot on a battery, but for now is powered by a pi that I'm writing the Arduino code on. That pi is powered from the house mains (220V) supply.
Regards,

Hugh

Hi;
Change this bit;

void forward()
{
  Leftservo.write(180);
  Rightservo.write(0);
}

to;

void forward()
{
  Leftservo.write(180);
  Rightservo.write(180);
}

Tom... :smiley: :+1: :coffee: :australia:

Right wheel still not running after making that edit!