Servo Motor Signal Problem

Hi, I have a larger project that involves 1 servo controlled by the Arduino. It is a PWM servo. Pretty straight forward application for the Arduino part. Raise and lower a contraption with a pulley. Very little load on the servo. I have ran the signal cable through my projects main board and the servo seems to have a mind of it's own when i switch inputs and outputs on from the PLC (which is in a different circuit). So i tried moving everything to do with the arduino away from the main board, but the servo still rotates randomly when other non arduino components are turned on.

Iv metered what i can with a DMM and it stays at a true 5V going to the servo. The PWM signal however still fluctuates a lot when other devices are used. The only thing i can think of, is all the neutrals and grounds inevitable end up at the same wall outlet. Could a tiny induced voltage in the ground or neutrals disturb the signal from the arduino to the servo?

Thanks for any suggestions.

Code? Schematic?

'Im new to arduino’s but the code seems to do what i what it to. It just doesn’t hold its location when something else is turned on.

The arduino part is just on a breadboard with a push button and a resistor.

#include <Servo.h>
int button1 = 4;
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(9);
  digitalWrite(4, HIGH);
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(0);
    delay(200);
    servo1.write(180);
  }
}

How are you powering the servo? You did not post a schematic as requested. A photo of a pencil drawing will be fine.

The servo should have its own power supply and should NOT be drawing power from the Arduino 5v pin. Also the ground of the servo power supply should be connected to the Arduino ground.

If the servo is powered from the 5v pin and it draws too much current it will cause the Arduino to reset and may overload and damage the Arduino's on board voltage regulator.

...R

Californiacrooked: Could a tiny induced voltage in the ground or neutrals disturb the signal from the arduino to the servo?

yes it can... depending on the circuit. we could answer better if we could see diagram. specially how ardunio is connected to the main project.

sounds like your arduino part is not separate after all. some current might coming from the main board. you have to keep arduino-ground and other higher voltage-ground saperate. you can even try using diode to block un-intentional current.

Here’s a quick paint drawing. I did make a change from what Robin2 said and it seems to be a little better but it still jumps a little (shakes). That might be what Jay was talking about. I’ll have to try the diode to see if we can further stop the shakes.

You don't give the servo much time .

Also you might be driving the servo into it's limits (stops).

servo1.write(0); delay(200); servo1.write(180);

Californiacrooked: It just doesn't hold its location when something else is turned on.

    servo1.write(0);
    delay(200);
    servo1.write(180);

Your sketch will run the code above repeatedly as long as the input is low, and leave it in the '180' position when the input is high. I have no idea whether this is the behaviour you intend - if it isn't I suggest you explain exactly what behaviour you are trying to achieve.

I don't understand why you are showing the servo wiring the way you are. There are 3 wires coming from a regular servo - ground, power and signal. You seem to have the two wires from the servo power supply going to the servo (+) and the Arduino ground but you don't seem to have the power supply ground going to the servo. Instead you seem to have the servo ground connected to the power supply ground through the Arduino.

The normal way is for the power supply (+) to go to the servo and the power supply (-) to go to the servo AND to the Arduino ground. That way the servo gets all its power directly and only gets its signal from the Arduino.

...R

the grounds are all connected internally i don't see how that would matter. I tried the diode and it did not work or help. I also tried powering the servo and arduino off batteries to avoid the common ground all together. That did not work either. The servo still rotates without the input signal.

You must have a common ground so that the Arduino has a common reference point for its servo signal.

Have you tried writing a short sketch that does nothing but control the servo - does that work the way you expect?

You might consider putting a 4700 ohm resistor between the servo signal line and ground if the problem is that the servo is moving before the Arduino gets around to producing a servo signal.

...R