#define pinSwitch 2
#define pinRelay 5
void setup() {
pinMode(pinSwitch, INPUT_PULLUP);
pinMode(pinRelay, OUTPUT);
Serial.begin(9600);
}
void loop() {
int nilaiSwitch = digitalRead((pinSwitch));
if(nilaiSwitch == 0){
digitalWrite(pinRelay, HIGH);
Serial.println(nilaiSwitch);
}
else{
digitalWrite(pinRelay, LOW);
}
delay(100);
}