How to get my program to function properly.

What i'm trying to have my program do is check to see if my switch is triggered (Pin 4)
and then trigger my relay to do half a second on half a second off in a loop.

void setup() {
  // put your setup code here, to run once:
  pinMode(2,OUTPUT);
  pinMode(4,INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
if (digitalRead(4) == HIGH) {
  digitalWrite(2,HIGH);
  delay(500);
  digitalWrite(2,LOW);
  delay(500);
}
}

Currently it isn't doing this and isn't checking on my switch. Any help is appreciated.

How is the switch and relay wired?

aarg:
How is the switch wired?

I have 5v running through it to pin 4

donnyk:
I have 5v running through it to pin 4

That's not enough. You need also a pull down resistor on pin 4.

Typical switch wiring for Arduino

aarg:
That's not enough. You need also a pull down resistor on pin 4.

I'm somewhat new to Arduino, how would I wire that in?

donnyk:
I'm somewhat new to Arduino, how would I wire that in?

Honestly, you are better off using INPUT_PULLUP and inverting your logic:

void setup() {
  // put your setup code here, to run once:
  pinMode(2,OUTPUT);
  pinMode(4,INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
if (digitalRead(4) == LOW) {
  digitalWrite(2,HIGH);
  delay(500);
  digitalWrite(2,LOW);
  delay(500);
}
}

Like S3 in reply#4

aarg:
Like S3 in reply#4

I'm still a bit confused by the diagram- Do I connect the resistor to 5v and then to pin 4?

EDIT: Oh nevermind, I've figured it out. I forgot that my relay is wired so that it outputs Ground instead of 5v, so I had to switch my resistor+switch to Ground instead of 5v