2 Number Relay On and Off Arduino Programme
2 Number Relay On and Off Arduino Programme
Code:
cpp
CopyEdit
// Define the relay pins int relay1 = 8; // Relay 1 connected to pin 8 int relay2 = 9; // Relay 2 connected to pin 9 void setup() { // Set relay pins as
OUTPUT pinMode(relay1, OUTPUT); pinMode(relay2, OUTPUT); // Initially turn both relays OFF digitalWrite(relay1, LOW); digitalWrite(relay2,
LOW); } void loop() { // Turn Relay 1 ON and Relay 2 OFF digitalWrite(relay1, HIGH); digitalWrite(relay2, LOW); delay(1000); // Wait for 1 second //
Turn Relay 1 OFF and Relay 2 ON digitalWrite(relay1, LOW); digitalWrite(relay2, HIGH); delay(1000); // Wait for 1 second }
Instructions:
1. Connect:
Relay 1 signal pin to Arduino pin 8, VCC to 5V, and GND to GND.
Relay 2 signal pin to Arduino pin 9, VCC to 5V, and GND to GND.
2. Upload the code to your Arduino board using the Arduino IDE.
3. The relays will toggle ON and OFF alternately with a 1-second interval.