Acest mic proiect pentru incepatori a fost inspirat de acest articol, la care s-a adaugat un ecran LCD care sa afiseze ce buton a fost apasat pe telecomanda, niste relee de 5V, o sursa externa de 5V care sa sustina nevoia de curent a releelor, ca sa nu le alimentam din Arduino, care nu am idee cat ar rezista daca ar alimenta 4 relee.
Descrierea proiectului este in acest video de pe youtube
Codul i-l puteti descarca aici,
Code: Select all
#include "IRremote.h"
#include <LiquidCrystal_I2C.h>
int receiver = 11;
bool isOn1 = false;
bool isOn2 = false;
bool isOn3 = false;
bool isOn4 = false;
/*-----( Declare objects )-----*/
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
LiquidCrystal_I2C lcd(0x27,20,4);
void setup()
{
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Daradici Levente");
lcd.setCursor(7,1);
lcd.setCursor(0,1);
lcd.print(" & Andras");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Infrared remote");
lcd.setCursor(4,1);
lcd.print("Arduino");
delay(3000);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Press a button");
Serial.begin(9600);
Serial.println("IR Receiver Button Decode");
irrecv.enableIRIn(); // Start the receiver
pinMode(13, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
}/*--(end setup )---*/
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
translateIR();
irrecv.resume(); // receive the next value
}
}
/*-----( Function )-----*/
void translateIR() // takes action based on IR code received
// describing Remote IR codes
{
switch(results.value)
{
case 0xFFA25D: Serial.println(" 1"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(7, 1); lcd.print(" 1"); if(isOn1){digitalWrite(2, HIGH); isOn1 = false;}else{digitalWrite(2, LOW); isOn1 = true;} break;
case 0xFF629D: Serial.println(" 2"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(7, 1); lcd.print(" 2"); if(isOn2){digitalWrite(3, HIGH); isOn2 = false;}else{digitalWrite(3, LOW); isOn2 = true;} break;
case 0xFFE21D: Serial.println(" 3"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(7, 1); lcd.print(" 3"); if(isOn3){digitalWrite(4, HIGH); isOn3 = false;}else{digitalWrite(4, LOW); isOn3 = true;} break;
case 0xFF22DD: Serial.println(" 4"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(7, 1); lcd.print(" 4"); if(isOn4){digitalWrite(5, HIGH); isOn4 = false;}else{digitalWrite(5, LOW); isOn4 = true;} break;
case 0xFF02FD: Serial.println(" 5"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(7, 1); lcd.print(" 5"); break;
case 0xFFC23D: Serial.println(" 6"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(7, 1); lcd.print(" 6"); break;
case 0xFFE01F: Serial.println(" 7"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(7, 1); lcd.print(" 7"); break;
case 0xFFA857: Serial.println(" 8"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(7, 1); lcd.print(" 8"); break;
case 0xFF906F: Serial.println(" 9"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(7, 1); lcd.print(" 9"); break;
case 0xFF6897: Serial.println(" *"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(7, 1); lcd.print(" *"); break;
case 0xFF9867: Serial.println(" 0"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(7, 1); lcd.print(" 0"); break;
case 0xFFB04F: Serial.println(" #"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(7, 1); lcd.print(" #"); break;
case 0xFF18E7: Serial.println(" UP"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(6, 1); lcd.print(" Up"); break;
case 0xFF10EF: Serial.println(" LEFT"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(5, 1); lcd.print(" Left"); break;
case 0xFF38C7: Serial.println(" -OK-"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(6, 1); lcd.print(" Ok"); break;
case 0xFF5AA5: Serial.println(" RIGHT"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(4, 1); lcd.print(" Right"); break;
case 0xFF4AB5: Serial.println(" DOWN"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(5, 1); lcd.print(" Down"); break;
//case 0xFFFFFFFF: Serial.println(" REPEAT"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Button pressed"); lcd.setCursor(2, 1); lcd.print(" Repeat"); break;
default:
Serial.println(results.value, HEX);
Serial.println(" other button ");
}// End Case
delay(500);
}
sau din descrierea videoclipului de pe youtube.
Am implicat la maxim copilul in acest proiect, care a fost incantat de rezultatele obtinute in timp relativ scurt.
Fata de proiectul initial, am primit o telecomada care nu era identic cu cel descris in proiect, lucru pentru care a trebuit sa adaugam o linie, pentru a afla codul transmis de telecomanda spre receptor si afisarea acestuia in consola seriala, pentru a putea face lista completa a codurilor, si telecomanda primita sa fie 100% functionala.
Code: Select all
Serial.println(results.value, HEX);
Cu acest mic ajutor, teoretic puteti intercepta codul la orice telecomanda, am si incercat cateva prin casa, astfel sa puteti sa folositi o telecomanda existenta deja in cuplarea deculparea de exemplu a unor lumini sau orice device care este actionata electric.
Cred ca nu este nevoie sa descriu cum se leaga de relee un consumator, sau cum se intercaleaza in alimentarea unui consumator unul din relee.