Wednesday, April 30, 2014

Arduino relay code

OK, I'm publishing Arduino code, which allows you to control relay:
#define RELAY1  0                      
#define RELAY2  1                    
#define RELAY3  2                        
#define RELAY4  3

void setup()
{    
// Initialise the Arduino data pins for OUTPUT
  pinMode(RELAY1, OUTPUT);       
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);
  pinMode(RELAY4, OUTPUT);
}

void loop()
{
   digitalWrite(RELAY1,LOW);           // Turns ON Relays 1
   delay(2000);                        // Wait 2 seconds
   digitalWrite(RELAY1,HIGH);          // Turns Relay Off

   digitalWrite(RELAY2,LOW);           // Turns ON Relays 2
   delay(2000);                        // Wait 2 seconds
   digitalWrite(RELAY2,HIGH);          // Turns Relay Off

   digitalWrite(RELAY3,LOW);           // Turns ON Relays 3
   delay(2000);                        // Wait 2 seconds
   digitalWrite(RELAY3,HIGH);          // Turns Relay Off

   digitalWrite(RELAY4,LOW);           // Turns ON Relays 4
   delay(2000);                        // Wait 2 seconds
   digitalWrite(RELAY4,HIGH);          // Turns Relay Off        

 }

No comments:

Post a Comment