#define pinSwitch 2
#define pinRelay 15
int buzzer=12;
void setup() {
pinMode(pinSwitch, INPUT_PULLUP);
pinMode(pinRelay, OUTPUT);
pinMode(buzzer, OUTPUT);
}
void loop() {
int nilaiSwitch = digitalRead((pinSwitch));
if(nilaiSwitch == 0){
digitalWrite(pinRelay, HIGH);
tone(buzzer,150);
delay(1000);
}
else{
digitalWrite(pinRelay, LOW);
noTone(buzzer);
}
}