cannot get this my servo to move

Hi all,

I am relatively new to arduino, an the issue is with my code.

<
#include <Servo.h>

Servo myservo;

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(7, INPUT_PULLUP); // pin 7 is input
}
void loop() {
if (digitalRead(7)== HIGH){ myservo.write(0);

}else { myservo.write(90);}}>

All i am trying to do is have the servo move to either position dependant on whether or not the input pin is HIGH or not.

I have a digital servo connected with the PWM pin to pin 9 or my arduino UNO. the servo is also wired to 5v and ground on the corresponding pins.
I am then putting pin 7 high from 5v. This makes no change to the servo position. Any help would be great cheers.

Try pulling pin 7 low.

Also, Servo problems are usually power related. How is your servo powered?

A common mistake is to try to power a servo from the Arduino 5V, which can destroy the Arduino.

Use a separate power supply (4xAA battery pack will work for one or two small servos), and don't forget to connect the grounds.

Thanks for the reply but i was being an absolute fool. I should have been putting pin 7 to ground not 5 volts.
Its now working.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.