Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.3 kB
6
Indexable
Never
#define ON LOW
#define OFF HIGH

int relay1 = 16; //D1 on ESP Board
int relay2 = 5; //D2 on ESP Board
int relay3 = 4; //D3 on ESP Board
int relay4 = 00;  //D4 on ESP Board


void setup() {
  pinMode(relay1,OUTPUT);pinMode(relay2,OUTPUT);
  pinMode(relay3,OUTPUT);pinMode(relay4,OUTPUT);     // Memfungsikan LED_BUILTIN atau pin D0 sebagai output

  digitalWrite(relay1, ON);digitalWrite(relay2, ON);
  digitalWrite(relay3, ON);digitalWrite(relay4, ON);
}

// kemudian akan masuk ke void loop dan akan terus berulang langkah pada void loop
void loop() {
  digitalWrite(relay1, ON);         
                                    
  delay(2000);                      
  digitalWrite(relay1, OFF);       
  delay(1000);                      

  digitalWrite(relay2, ON);        
                                    
  delay(3000);                      
  digitalWrite(relay2, OFF);        
  delay(1000);                      

  digitalWrite(relay3, ON);         
                                    
  delay(4000);                      
  digitalWrite(relay3, OFF);        
  delay(1000);                      

  digitalWrite(relay4, ON);        
                                    
  delay(5000);                      
  digitalWrite(relay4, OFF);       
  delay(1000);                     
}