Servo opperates when light turned on

Here is the revised code with your added code

[code// Include the Servo library
#include <Servo.h>

Servo myservo1;  //servo1
Servo myservo2;  //servo2

 int pos1 = 0;  //variable for number of degrees for servo1
int pos2 = 0; //variable for number of degrees for servo2

int buttonPin1 = 2; //activating pin 2 for Push Button 
int buttonPin1State = 0; //variable for Push Button
int buttonPin2 = 3; //activating pin 3 for Push Button 
int buttonPin2State = 0; //variable for Push Button

void setup() {  

myservo1.attach(9); //activating pin 9 for servo1
myservo2.attach(10); //activating pin 10 for servo2

 
pinMode(buttonPin1 , INPUT); //setting Push ButtonNo. 1 as an input
pinMode(buttonPin2 , INPUT); //setting Push ButtonNo. 2 as an input
}
void loop() { 
buttonPin1State = digitalRead(buttonPin1); //reading buttonPin1 Pin and storing it as buttonState.
buttonPin2State = digitalRead(buttonPin2); //reading buttonPin2 Pin and storing it as buttonState.

if (buttonPin1State == HIGH)
  { //if button no.1 is pressed...
      myservo1.write(110); //setting servo1 to 110 degrees
      delay(5000); //wait one second

      myservo1.write(0); //setting servo1 to 0 degrees
  }//end of b P1

  if (buttonPin2State == HIGH)
  { //if button no.2 is pressed...
      myservo2.write(110); //setting servo2 to 110 degrees
      delay(5000); //wait one second

      myservo2.write(0); //setting servo2 to 0 degrees
  }//end of if b P2
}//end of loop

]

You have not declared pin 9 and 10 as outputs. I don't know if the servo lib functions do that.
Do I understand that if You press button 1 servo1 is running when it's connected to either pin 9 or 10? Is there a short between pin 9 and 10? Something is really strange here. I will have sime sleep now, 03 Am here...

Hi,
Why do you want to disconnect the servos from power?

Tom..... :slight_smile:

@TG
Not power but the logic signal as I read it.

I want to dissconnet the servos from power becasue its awhile in between uses and I thought that if they had no power I would get a longer life out of the. The other reason is that at random times the servo will operate so if they had no power I thought that would fix that. Random operation wouldnt be a big deal but the servos are going to be in a toilet so I can flush them with google home. so I dont want the toilets flushing at rondom times

Step back and make sure You have a reliable input to the controller. Make sure that no input is floating at any time. You culd use simple LEDs instead of servos for working this out. When using servos the controller uses a logocal signal to controll the servo. Make sure that those outputs are active at all times and never goes into a three state condition.

OK so you think its the pin that sends data to the servo thats telling it to move. To trouble shoot this you want me to place an led from ground to the data pin on the controller and make sure that it does not come on.
Is this right

I firstly think You should make sure that the disturbance is not coming from the buttons making the code issue a "Go" to the output, the servo.
Using an LED instead of the servo was my idea. +5 to the anode of the LED. A resistor, som 270 -10000 ohm resistor to the cathode and the other end of the resistor to the Arduino servo pin, 9/10. That LED will not shine if unless the pin 9/10 issues a Low level. This will show any low logic outputs as blinks in the LED. If the logic for the servo is Active High You need to turn the LED/resistor upside down, resistor to GND and LED to pin 9/11.

with a resistor on the cathode of the led and the cathode side of the led to to pin 9 and the anode to 5v the led lights up bright. If I reverse the anode and cathode the led lights up dim
using the switch does nothing to the led
Right now I have no switch just two wires I touch together

I moved the servo data wire from pin 8 and 9 to pin 50 and 52. Seems to be working ok now could there be something wrong with the PWM pins

Are You sure that the two 10k resistors for the button inputs are connected?
The dim light You see is because of electrical noice triggering the button inputs.
Declare those inputs as "INPUT_PULLUP" and see if that changes anything.

Moved servo data from pin 8 and 9..... Didn't You write 9 and 10 before? Never mind. If it works now it's good.