Potentiometer to servo

Hello all,

I am doing a project that takes potentiometer input and converts it to servo output, but I have run into a problem where the servos only move when the 'L' light is on, which prevents me from using a 9v battery to power the project.

#include <Servo.h> // servo library

// defing servos
Servo servo1;
Servo servo2;


//defing potentiometers
int pot1 = A0; 
int pot2 = A1;

// pot variables
int potval1; 
int potval2;

void setup(){
// attach servos

servo1.attach(9);
servo2.attach(8);
}

void loop(){
  //pot reading

    potval1 = analogRead(pot1);
    potval1 = map(potval1, 0, 1023, 0, 360);
    servo1.write(potval1);
    delay(15);

    
    potval2 = analogRead(pot2);
    potval2 = map(potval2, 0, 1023, 0, 360);
    servo2.write(potval2);
    delay(15);
}

Any suggestions welcome.

sal_c:
I have run into a problem where the servos only move when the 'L' light is on, which prevents me from using a 9v battery to power the project.

This is an absolute non sequitur. It's like saying "my television only turns on when a dog is barking, which prevents me from eating pancakes".

If the 9V battery is what I know as a PP3 type then it is totally unsuitable for powering a servo as it cannot provide enough current to power the sevo for very long. It also sounds like you are taking the power for the servo from the Arduino which is also a bad idea

thank you for the advice I suspect that could be the problem

And you can’t sensibly power the servo from the 5v pin on the Arduino ..