/*############################################################################## Author: * Mirko Prosseda (06-2013) * email: mirko.prosseda@gmail.com Description: * Relay Shield test sketch v1.0 * Turns on and off each relay every second. Connections: * SHIELD -> ARDUINO * Relay 1 -> 5 * Relay 2 -> 6 * Relay 3 -> 7 * Relay 4 -> 8 * During programming, switch must be on PRG position ##############################################################################*/ // Define constants and variables const int out1 = 5; // define Arduino pin connected to relay 1 const int out2 = 6; // define Arduino pin connected to relay 2 const int out3 = 7; // define Arduino pin connected to relay 3 const int out4 = 8; // define Arduino pin connected to relay 4 // Initialization void setup() { pinMode(out1, OUTPUT); // initialize the digital pin as an output pinMode(out2, OUTPUT); // initialize the digital pin as an output pinMode(out3, OUTPUT); // initialize the digital pin as an output pinMode(out4, OUTPUT); // initialize the digital pin as an output Serial.begin(9600); // Serial Port initialization } // enable or disable a relay (1 to 4) void setRelay(int relay, int value) { if(relay > 0 && relay < 5) digitalWrite((relay + 4), value); } // main loop void loop() { setRelay(1, 1); // enable relay 1 Serial.print("Relay 1: Enabled ... "); delay(1000); // wait for a second setRelay(1, 0); Serial.println("Disabled"); // disable relay 1 delay(1000); // wait for a second setRelay(2, 1); // enable relay 2 Serial.print("Relay 2: Enabled ... "); delay(1000); // wait for a second setRelay(2, 0); // disable relay 2 Serial.println("Disabled"); delay(1000); // wait for a second setRelay(3, 1); // enable relay 3 Serial.print("Relay 3: Enabled ... "); delay(1000); // wait for a second setRelay(3, 0); // disable relay 3 Serial.println("Disabled"); delay(1000); // wait for a second setRelay(4, 1); // enable relay 4 Serial.print("Relay 4: Enabled ... "); delay(1000); // wait for a second setRelay(4, 0); // disable relay 4 Serial.println("Disabled"); delay(1000); // wait for a second }