Relays
From Reef Projects
Relay Testing
- This is just some code to test the relay using a push button.
- I modified [this code] and used [this wiring] for the button.
- Made sure the polarity on the relay is correct.
Code:
int relay = 11; // choose the pin for the relay
int inPin = 1; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
void setup() {
pinMode(relay, OUTPUT); // declare relay wire as output
pinMode(inPin, INPUT); // declare pushbutton as input
}
void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(relay, LOW); // turn relay OFF
} else {
digitalWrite(relay, HIGH); // turn relay ON
}
}

