Controle de relés por Arduino e controle remoto IR (IRremote)

Projeto pra final de semana...

Controlar 24 relés por controle remoto de luz RGB 16 cores

O que é preciso:
- Conhecimento no ambiente Arduino e eletrônica básica
- Arduino Mega 2560 ou adaptar o total de portas para outro
- Controle remoto de fita RGB
- Placa de relés para Arduino e fonte
- Receptor IR módulo Arduino

Este programa foi testado, faça por conta e risco, não me responsabilizo por danos...

//21/09/2014
//Controlador de 24 relés com selo on-off por
//controle remoto IR no Mega 2560
//Adaptação do exemplo na bilioteca IRremote.
//Adaptado por: Josicláudio
//Tamanho após compilado 12.632 bytes
//controle remoto lâmpada RGB
//Códigos do controle em DEC (Decimal)
//
//Tecla travada--------4294967295
//Comando liga-----------16769055
//Comando desliga--------16736415
//Aumenta brilho---------16752735
//Diminui brilho---------16720095
//Cor vermelho-----------16748655
//Cor verde--------------16716015
//Cor azul---------------16732335
//Cor branco-------------16764975
//Laranja 1--------------16756815
//Laranja 2--------------16754775
//Laranja 3--------------16750695
//Amarelo----------------16746615
//Verde 1----------------16724175
//Verde azulado----------16722135
//Azul claro1------------16718055
//Azul claro 2-----------16713975
//Azul claro 3-----------16740495
//Roxo 1-----------------16738455
//Roxo 2-----------------16734375
//Rosa-------------------16730295
//Flash cor rápido-------16773135
//Flash cor lento--------16771095
//Gradual rápido---------16767015
//Gradual lento----------16762935
//
//

//incluir a biblioteca IRremote
#include

// pino 8 entrada receptor IR
int RECV_PIN = 8;

//define pinos
int saida30 = 30;
int saida29 = 29;
int saida28 = 28;
int saida27 = 27;
int saida26 = 26;
int saida25 = 25;
int saida24 = 24;
int saida23 = 23;
int saida22 = 22;
int saida21 = 21;
int saida20 = 20;
int saida19 = 19;
int saida18 = 18;
int saida17 = 17;
int saida16 = 16;
int saida15 = 15;
int saida14 = 14;
int saida13 = 13;
int saida12 = 12;
int saida11 = 11;
int saida10 = 10;
int saida09 = 9;
int saida07 = 7;
int saida06 = 6;

IRrecv irrecv(RECV_PIN);

decode_results results;


void setup()
{

  //seta os pinos 6 à 21 - 8 como saída
  pinMode(saida06, OUTPUT);
  pinMode(saida07, OUTPUT);
  pinMode(saida09, OUTPUT);
  pinMode(saida10, OUTPUT);
  pinMode(saida11, OUTPUT);
  pinMode(saida12, OUTPUT);
  pinMode(saida13, OUTPUT);
  pinMode(saida14, OUTPUT);
  pinMode(saida15, OUTPUT);
  pinMode(saida16, OUTPUT);
  pinMode(saida17, OUTPUT);
  pinMode(saida18, OUTPUT);
  pinMode(saida19, OUTPUT);
  pinMode(saida20, OUTPUT);
  pinMode(saida21, OUTPUT);
  pinMode(saida22, OUTPUT);
  pinMode(saida23, OUTPUT);
  pinMode(saida24, OUTPUT);
  pinMode(saida25, OUTPUT);
  pinMode(saida26, OUTPUT);
  pinMode(saida27, OUTPUT);
  pinMode(saida28, OUTPUT);
  pinMode(saida29, OUTPUT);
  pinMode(saida30, OUTPUT);

 //abre a comunicação serial
  Serial.begin(9600);


  irrecv.enableIRIn();


}
int s06 = 0;//mantém valor inicial para saída 06 desligada
int s07 = 0;//
int s09 = 0;//
int s10 = 0;//
int s11 = 0;//
int s12 = 0;//
int s13 = 0;//
int s14 = 0;//
int s15 = 0;//
int s16 = 0;//
int s17 = 0;//
int s18 = 0;//
int s19 = 0;//
int s20 = 0;//
int s21 = 0;//
int s22 = 0;//
int s23 = 0;//
int s24 = 0;//
int s25 = 0;//
int s26 = 0;//
int s27 = 0;//
int s28 = 0;//
int s29 = 0;//
int s30 = 0;//

void loop() {
 
  //Decodifica os dados recebidos para decimal e envia para pc
  if (irrecv.decode(&results)) {
    Serial.println(results.value, DEC);

    //pega próximo valor
    irrecv.resume();

   if(results.value == 4294967295){ //botão pressionado por muito tempo
     Serial.println("Favor pressionar o botao e soltar!");
     Serial.println("***************************");
    }
   
   if(results.value == 16752735){ //comando aumenta brilho
     s06 = !s06;
     digitalWrite(saida06, s06 ? HIGH : LOW); //possibilita usar um botão para ligar e desligar
 
    }
     if(results.value == 16720095){ // comando diminui brilho
     s07 = !s07;
     digitalWrite(saida07, s07 ? HIGH : LOW);
      }
      if(results.value ==16736415){ //comando desliga
     s09 = !s09;
     digitalWrite(saida09, s09 ? HIGH : LOW);
      }
      if(results.value ==16769055){ //comando liga
     s10 = !s10;
     digitalWrite(saida10, s10 ? HIGH : LOW);
      }
      if(results.value ==16748655){ //comando red
     s11 = !s11;
     digitalWrite(saida11, s11 ? HIGH : LOW);
     }
      if(results.value ==16716015){ //comando green
     s12 = !s12;
     digitalWrite(saida12, s12 ? HIGH : LOW);
      }
      if(results.value ==  16732335){ // comando blue
     s13 = !s13;
     digitalWrite(saida13, s13 ? HIGH : LOW);
      }
      if(results.value ==16764975){ // comando branco
     s14 = !s14;
     digitalWrite(saida14, s14 ? HIGH : LOW);
      }
      if(results.value ==16756815){ //comando laranja 1
     s15 = !s15;
     digitalWrite(saida15, s15 ? HIGH : LOW);
      }
      if(results.value ==16724175){//comando verde 1
     s16 = !s16;
     digitalWrite(saida16, s16 ? HIGH : LOW);
      }
      if(results.value ==16740495){ //comando azul claro 3
     s17 = !s17;
     digitalWrite(saida17, s17 ? HIGH : LOW);
      }
      if(results.value ==16773135){//comando flash rápido
     s18 = !s18;
     digitalWrite(saida18, s18 ? HIGH : LOW);
      }
      if(results.value ==16754775){// comando laranja 2
     s19 = !s19;
     digitalWrite(saida19, s19 ? HIGH : LOW);
      }
      if(results.value ==16722135){ //comando verde azulado
     s20 = !s20;
     digitalWrite(saida20, s20 ? HIGH : LOW);
      }
      if(results.value ==16738455){ //comando roxo 1
     s21 = !s21;
     digitalWrite(saida21, s21 ? HIGH : LOW);
      }
       if(results.value ==16771095){//comando flash lento
     s22 = !s22;
     digitalWrite(saida22, s22 ? HIGH : LOW);
      }  
      if(results.value ==16750695){//comando laranja 3
     s23 = !s23;
     digitalWrite(saida23, s23 ? HIGH : LOW);
      }  
      if(results.value ==16713975){//comando azul claro 2
     s24 = !s24;
     digitalWrite(saida24, s24 ? HIGH : LOW);
      }  
      if(results.value ==16734375){//comando roxo 2
     s25 = !s25;
     digitalWrite(saida25, s25 ? HIGH : LOW);
      }  
      if(results.value ==16767015){//comando gradual rápido
     s26 = !s26;
     digitalWrite(saida26, s26 ? HIGH : LOW);
      }  
      if(results.value ==16746615){//comando amarelo
     s27 = !s27;
     digitalWrite(saida27, s27 ? HIGH : LOW);
      }  
      if(results.value == 16713975){//comando azul 2
     s28 = !s28;
     digitalWrite(saida28, s28 ? HIGH : LOW);
      }  
      if(results.value ==16730295){//comando rosa
     s29 = !s29;
     digitalWrite(saida29, s29 ? HIGH : LOW);
      }  
      if(results.value ==16762935){//comando gradual lento
     s30 = !s30;
     digitalWrite(saida30, s30 ? HIGH : LOW);
      }
   
   }
 
 }

Obs: O controle pode ser adptado para outros tipos, basta copiar os códigos
pelo Serial Monitor...

Aprender é divertido, executar é melhor ainda...

Comentários

Postagens mais visitadas deste blog

JVC Compulink, COMPU LINK, JVC, Tape Deck, Arduino, DCS Codes

JVC Compu Link Final

RTTY, PSK31, FT8, JS8CALL, NBTV, RDS FM, OLIVIA, SSTV, SSTV AUTO,CW, ASCII Encoder / Decoder