//project Pengayaan simulator Blink+Relay+Button
//oleh Miftah Jayadiansyah SMK Bina Bangsa Kab. Tasikmalaya
/*
1. Connect LED anode to Relay dengan digital pin (pin 13)
2. Connect LED catode to resiston (200-ohm) and the to the ground (GND) of the Arduino board.
3. Connect one leg of the push button to the digital pin (pin 2).
4. Connect the 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); // Turn LED on.
} else {
digitalWrite(PinRelay, LOW); // Turn LED off.
}
}