Code, only works with some servos?

Hi, unfortunately I have a servo problem with my arduino, pretty much I have code that will turn the servo to 0 degrees if I get one int value from an LDR and then it will turn it 180 degrees if I get another. The problem seems to be more specific with the servo though. Currently this is my code:

#include <Servo.h> 

int LDR_Pin = A2; 
Servo myservo;

void setup() {
  Serial.begin(9600);
  myservo.attach(3);

  pinMode(49, OUTPUT);
  pinMode(53, OUTPUT);
  digitalWrite(49, HIGH);
  digitalWrite(53, HIGH);

}

void loop()
{
  int LDRReading = analogRead(LDR_Pin); 
  Serial.println(LDRReading);

  if ( LDRReading < 800 )
  {
    myservo.write(180);
    delay(100);
  }
  else
  {
    myservo.write(100); 
    delay(100);
  }

  //delay(1000);
}

The digital write high are just LEDs which are used to control the LDR, the problem is if I use this code with one of my servos it works perfectly, but if I use it on my other two it doesn’t work at all. I get some sort of feed back, for example the servo will not move against its position but it doesn’t move as per the code. I’ve tried all the servos using the sweep code in the examples part, and they all work fine and sweep perfectly. But then this code only works with 1 servo and not the other two.
I guess important things to know is that the servo it does work with seems more expensive while the other two are very cheap servos, which have a label saying 9G on it?
Is there anyway I can get the other two working as well? I tried adding a 1 second delay at the end but doesn’t seem to make much of a difference?

Can You see That When You Write Stuff All over the Page, it

Can Be really

Hard to read?

for example the servo will not move against its position but it doesn’t move as per the code.

Not sure what this means.

What value are you getting for the LDR? If it’s around 800, you may have the servos trying to change rapidly between positions. Try longer delays.

AWOL: Can You see That When You Write Stuff All over the Page, it

Can Be really

Hard to read?

My apologies, when I think things my thought process is all over the place so when I write it down it happens as well. If you would like me to re-clarify or rewrite a part please say so and I would be happy to :).

wildbill:

for example the servo will not move against its position but it doesn't move as per the code.

Not sure what this means.

What value are you getting for the LDR? If it's around 800, you may have the servos trying to change rapidly between positions. Try longer delays.

Hi thanks, basically what I mean is if I try to move the servo horn manually it will refuse to budge as if the arduino is giving it a position to move to, but that position doesn't seem to change at all. I will try it with longer delays now and see how it works out, thanks :). Basically during testing if the LED is on I get values above 800 (close to 1000) and when the LED is covered I normally get values around 200. Which makes sense and I'm assuming why it works with one servo, but weird why it doesn't work with the others.

Also does it matter if the servo is powered by the arduino? I'm using three at once so was wondering if there is some sort of issue with power?


Correction, Dear wildbill you're amazing, if I meet you in real life I will shout you all the drinks :), I changed the delay to 100 and its working perfectly :D, so awesome, cheeers!! and appreciated

Also does it matter if the servo is powered by the arduino? I'm using three at once so was wondering if there is some sort of issue with power?

Solved your own problem! The arduino can sometimes manage to power one servo, three is right out ;)

or rewrite a part please say so and I would be happy to

Please use Tools + Auto Format to fix that code. Logical thought processes, and logically laid out code, work far better than code that looks like poetry.

wildbill:

Also does it matter if the servo is powered by the arduino? I'm using three at once so was wondering if there is some sort of issue with power?

Solved your own problem! The arduino can sometimes manage to power one servo, three is right out ;)

Actually looked at it closer, instead of changing the delay to 100, I accidentally changed my starting point to 100 degrees for the servo, which made it work :D. Further investigation and doing some testing turns out that the dodgy servos I have only work between 21 degrees and 176 degrees, and any other value I place doesn't move the servo at all. Its weird but good to see its working, still a thanks and I totally owe you a beer man Cheers.