Mg966R chattering

Hi guys , completely new to arduino. i have played around with a program from the internet.
I have a watering system controlled with a siemens LOGO ( my background)
The water is gravity feedingfrom the pumps designed a 3d print for a ball valve holder workes well but the servo chatters when at either "90" degrees or "0" degrees.
also i can only get one servo to run as i want it . if i uncommenet the the other inputs and servo i get strange things happening to the first / second servo

<#include<Servo.h>
Servo servo1;
Servo servo2;
int pos=0;
void setup()
{
pinMode(2,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
servo1.attach(9);
servo2.attach(10);
}

void loop()
{
// if(digitalRead(2)==LOW){
if(digitalRead(3)==LOW){
// servo1.write(90);
servo2.write(90);
}
else
// servo1.write(0);
servo2.write(0);
}

Any idea what i'm doing wrong
Regards
Dave

Please provide a wiring diagram; a photo of a hand drawn one is fine (limit the size to something like 300k). It should clearly show all power connections as well.

A wild guess is that you're powering the servos from the Arduino (which one?).

Please edit your post, select all code and click the </> button above the edit textbox; next save the post.

@shrekanddonkey66, your topic was moved to a more suitable section on the forum.

Probably insufficient power. How are the servos powered? They should have their own power source separate from the Arduino.

Steve

Servos are powered from a seperate PSU in parall with the Nano. The servos complete the "0" or "90" degrees but still seem to be tyring to move , if i turn the servo by ahand a slight amount the noise stops. its as though the servo is just not making it

You didn't say what voltage/current of the supply.
Can it deliver the 2.5Amp stall current that servo requires.

Which pin of the Nano is the supply connected to,
and which Nano (there are several completely different ones).
Leo..

my apologies im using an UNO not nano
i have a voltage and current read out on my PSU the voltage is 5.3 volt current goes to .45 when the srvo is moving

We still don't know how you are powering the setup.

Measure the peak current when it starts moving, with a scope.
Only then you see the 2.5Amp peaks.
The supply must be able to provide that.
If it can't, you get jitter.
Leo..

the servo moves from 0 towards 90 degrees with no problems until the last degree or so. if i move it by hand the servo is ok

Not all servos can reach zero degrees (or 180 for that matter) but ninety shouldn't be a problem. Does it work ok if it is disconnected from the valve?

As already noted though, lack of power is the usual cause of servo issues.

I'm running the servos in fresh air with no mechanical connection driven from a 2-3 amp psu

Does the other servo act the same? What happens if you go to 85 degrees instead? Have you tried using write microseconds instead?

I still suspect power though - the PSU may not actually be able to provide nameplate current. How long are your wires and how thick? Is there a breadboard involved?

WildBill , i have disconnected the 2nd servo ,
using a breadboard to connect power to UNO and servo, wires 2 inches long.
Changed PSU to 5 volt 2.0 Amp
still the same problem
Tried several diifernt servos of the same type
chaged angle to 85 Degrees
if i move the sevo by hand a little the servo stop buzzing
I'm completely lost
Many Thanks For you help

Breadboards are notorious for their thin traces and inability to manage large amounts of current. Try to attach the servo without using it.

WildBill My Bread board has just been throw in the bin.
It works with one servo no chattering :slight_smile:
Next problem I promise i will leave you alone then
If i uncomment my program to work with 2 servos and 2 inputs
i connect pin 2 to Gnd
servo 1 goes back an forth
im deffinetly missing something ( maybe a brain cell or too getting old)

Post the code you're using now.

#include<Servo.h>
Servo servo1;
Servo servo2;
int pos=0;
void setup()
{
pinMode(2,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
servo1.attach(9);
servo2.attach(10);
}

void loop()
{
if(digitalRead(2)==LOW){
servo1.write(90);
if(digitalRead(3)==LOW){
servo2.write(90);
}
else
servo1.write(0);
servo2.write(0);
}
}

I'm not exactly sure what you're trying to do but having 2 ifs and only one else looks wrong. Shouldn't the two servos be independent e.g.

if 2 is low servo1.write 90 else servo1 write 0
if 3 is low servo2.write 90 else servo2 write 0

Steve

Steve what im try to do is move servo 1 to 90 degrees if input on pin 2.
if no input on pin 2 go to 0 degrees
same for servo 2 if input on pin 3 go to 90 degrees
ig no input go to 0 degrees
its for a watering system for the wife
and she's give me hassle :slight_smile: