const int Button = 25;
const int Relay = 33;
void setup() {
pinMode(Button, INPUT_PULLUP); // Set Button pin as INPUT with internal pull-up resistor
pinMode(Relay, OUTPUT); // Set Relay pin as OUTPUT
digitalWrite(Relay, LOW); // Initially turn the relay off
Serial.begin(9600); // Start serial communication
}
void loop() {
if (digitalRead(Button) == LOW) { // Button pressed (LOW because of pull-up resistor)
Serial.println("Button pressed. Turning on the relay.");
digitalWrite(Relay, HIGH); // Turn the relay on
}
else {
Serial.println("Button released. Turning off the relay.");
digitalWrite(Relay, LOW); // Turn the relay off
}
delay(50); // Small delay for debouncing
}