// Materi blink LED + Relay + Button
// Tugas nechiyana
/*
1.Connect LED anode to Relay dengan digital pin [pin 13]
2.Connect LED catode to resiston [200-ohm] and the ground [GND] of the Arduino board.
3.Connect one leg of the push button to the digital pin [pin 2].
4.Connect thr other leg of the push button to the ground [GND] of the Arduino board.
*/
//Define variables
int PinRelay = 13; // Digital pin relay
int buttonPin = 2; // Digital pin where the button is connected.
bool buttonState = true;
void setup() {
pinMode(PinRelay, OUTPUT); // LED pin as an output.
pinMode(buttonPin, INPUT); // Button pin as an input.
}
//LOOP
void loop() {
// Read the state of the button
buttonState = digitalRead(buttonPin);
// Check if the button is pressed
if (buttonState == HIGH){
digitalWrite(PinRelay, HIGH); //Trun LED on.
} else {
digitalWrite(PinRelay, LOW); // Trun LED off.
}
}