void setup() {
pinMode(2, INPUT); // pin 2 connect into button and detect change from button
pinMode(4, OUTPUT); // pin 4 connect into relay and change Relay situation
}
void loop() {
int pb = digitalRead(2); // Read/detect change from button
if (pb==LOW){
/*
pb==LOW (Pull down) GND connect to push button and VCC/5V connect into resistor
pb==HIGH (Pull UP) VCC/5V connect to push button and GND connect into resistor
*/
digitalWrite(4,HIGH); // Set Relay On
}
else{
digitalWrite(4,LOW); // Set Relay Off
}
}