Servo acting werid

I am writing some code for an IR scanner attached to two 180 degree servos (don’t ask) I would like to turn the servos the opposite direction when the IR sensor gets below a certain analog read value. Whenever I test this value with a variable resistor, instead of the servo turning the way I want it to, it just stops along with the other one. Can someone please help!? My code is below.

#include <Servo.h>

int servopinr = 9;
int servopinl = 10;
int stopdist = 400;
int IRpin = A0;
int angle = 0;

Servo servor;
Servo servol;

void setup()
{
servor.attach(servopinr);
servol.attach(servopinl);
}

void loop()
{
int IRscan = analogRead(IRpin);

if (IRscan < stopdist) {

servor.write(1);

}

else
{

for (angle = 0; angle < 180; angle++)
{
servor.write(angle);
servol.write(angle);
delay(15);
}

}

delay(12);
}

I don't see anything obviously wrong in the code. So, the problem must be related to your wiring. How are you powering the servos?

I am powering my servos by hooking them up to the arduino and hooking the arduino up to my computer.

MrC0829:
I am powering my servos by hooking them up to the arduino and hooking the arduino up to my computer.

That hasn't worked for anyone else.

Servos need a lot of current - far more than the Arduino can provide. Power them with a real power supply, and connect the Arduino's ground and the power supply ground.

So if I connect the servos to a better power source, and the arduino’s ground to the power source ground, my servos will work?

MrC0829:
So if I connect the servos to a better power source, and the arduino's ground to the power source ground, my servos will work?

Only one way to know for sure...

It worked! thank you so much!!