วันเสาร์ที่ 30 กันยายน พ.ศ. 2560

Infared remote control DIY


Wiring 








Library







Code


#include "IRremote.h"

 int RECV_PIN = 11;
 int Relay1 = 2;
 int Relay2 = 3;
 int Relay3 = 4;
 int Relay4 = 5;


 IRrecv irrecv(RECV_PIN);

 decode_results results;

 void setup()
 {
 Serial.begin(9600);
 irrecv.enableIRIn(); // Start the ir receiver
 pinMode(Relay1, OUTPUT); 
 pinMode(Relay2, OUTPUT); 
 pinMode(Relay3, OUTPUT); 
 pinMode(Relay4, OUTPUT);


  digitalWrite(Relay1,HIGH); // set the Relay on 
  digitalWrite(Relay2,HIGH); // set the Relay on 
  digitalWrite(Relay3,HIGH); // set the Relay on 
  digitalWrite(Relay4,HIGH); // set the Relay on 


 } 

 void loop() {


 if (irrecv.decode(&results)) {
 Serial.println(results.value, DEC);


 if(results.value == 16724175) //1 if you want to configure with your remote controll change the results.value
 digitalWrite(Relay1, LOW); // set the Relay on 
  if(results.value == 16738455)  //0
 digitalWrite(Relay1, HIGH ); // 0 set the Relay off

 irrecv.resume(); // Receive the next value

 if(results.value == 16718055)
 digitalWrite(Relay2, LOW); // set the Relay on
 if(results.value == 16738455)
 digitalWrite(Relay2, HIGH); // set the Relay off

 irrecv.resume(); // Receive the next value

 if(results.value == 16743045)
 digitalWrite(Relay3, LOW); // set the Relay on
 if(results.value == 16738455)
 digitalWrite(Relay3, HIGH); // set the Relay off

 irrecv.resume(); // Receive the next value

 if(results.value == 16716015)
 digitalWrite(Relay4, LOW); // set the Relay on
 if(results.value == 16738455)
 digitalWrite(Relay4, HIGH); // set the Relay off

 irrecv.resume(); // Receive the next value

 }

 }



ไม่มีความคิดเห็น:

แสดงความคิดเห็น