Servo Not Working With Arduino

I am new to Arduino. I am trying to make a very basic Servo circuit with Arduino, but it won’t work for some reason. I know my Servo works, because it does the very first line (resetting to 0), but won’t do the rest. Any ideas would be great.

/*

*/
#include <Servo.h>

Servo servo;

void setup() {
   servo.attach(4);
   servo.write(0);


}

void loop() {

   servo.write(90);
   delay(1000);
   servo.write(0);
   
}

Try

   delay(1000);
   servo.write(0);
   delay(1000);

...or

void loop() {

    servo.write(90);
    delay(1000);
    servo.write(0);
    delay(1000);
   
}

You need to remember that at the end of loop(), the processor goes off a does some housekeeping for a few microseconds and then runs loop() again, so the time between you writing (0) and (90) is extremely short. The second delay() gives the servo time to move.

Also, try to learn to use coding techniques that don't involve delay(). It's as bad as goto (and that's bad...)

#include <Servo.h>

Servo servo;

void setup() {
   servo.attach(4);
   servo.write(0);
}

void loop() {
   servo.write(90);
   delay(1000);
   servo.write(0);
   delay(1000);
}

Thank you for your responses. I got it to work by using your suggestions.

Bingo!