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