Help please, servo goes crazy when I run this code.

Hi there, can someone take a look and tell me why my servo starts spinning uncontrollably when I try to run this code? -thanks, CoderPerson123 (sorry if I messed this system up, im new to forums :o )

#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>     //must copy IRremote library to arduino libraries
#include <Servo.h>

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();
  servo.attach(7);     
}

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

    if (results.value == 0xFFE01F)
    {
      cwRotation = !cwRotation;      
      ccwRotation = false;         
    }

    if (results.value == 0xFF906F)
    {
      ccwRotation = !ccwRotation;   
      cwRotation = false;            
    }
  }
  if (cwRotation && (val != 175))  {
    val++;                         
  }
  if (ccwRotation && (val != 0))  {
    val--;                         
  }
  servo.write(val);
  delay(20);          
}

Is the servo's ground connected to the Arduino's ground?

What happens when you run the servo sweep example?

What does your serial output show?

Did you consider that this might not be the most appropriate section of the forum fore your question?