Power for servo motor?

Hello again,

Apologies - I have copied the code again via the 'copy for forum' button below. I hope this is better. The rotation values were funny before because we were just playing around with the settings before it stopped working. However, the code functioned fine and the hand cast turned to a thumbs up and thumbs down and middling position, as we wanted it to. The problem I need help with is the power issue. The servo motor beeped continuously, then worked erratically (the remote sensor flashed ok) and then it stopped working. So I will not plug it into my laptop again for power and 8 x AA batteries wired in did not work, so how should I power it and then wire the power into the circuit? Do I need a resistor in the circuit too? And if so, how should I add that to the circuit? I am a complete beginner. I have only done a few arduino starter kit circuits, so I would really appreciate your help and patience with my knowledge-void. I need beginner-level instructions on how to do it.

Thank you very much.

// Written by: Mohamed Soliman
// This code is for controlling servo motor with IR remote control
// When clicking at any of two buttons the motor is toggling between the rotation and stop

#include <IRremote.h>      //must copy IRremote library to arduino libraries
#include <Servo.h>
#define plus 0xFF52AD   //clockwise rotation button
#define minus 0xFF6897  //counter clockwise rotation button

int RECV_PIN = 2;       //IR receiver pin
Servo servo;
int val;                //rotation angle
bool cwRotation, ccwRotation;  //the states of rotation

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  servo.attach(9);     //servo pin
}

void loop() 
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value

    if (results.value == plus)
    {
      cwRotation = !cwRotation;      //toggle the rotation value
      ccwRotation = false;         //no rotation in this direction
    }

    if (results.value == minus)
    {
      ccwRotation = !ccwRotation;   //toggle the rotation value
      cwRotation = false;            //no rotation in this direction
    }
  }
  if (cwRotation && (val != 170))  {
    val++;                         //for colockwise button
  }
  if (ccwRotation && (val != 5))  {
    val--;                         //for counter colockwise button
  }
  servo.write(val);
  delay(20);          //General speed
}