-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathIR Remote kit Arduino Due using Phototransistor
More file actions
89 lines (79 loc) · 2.47 KB
/
Copy pathIR Remote kit Arduino Due using Phototransistor
File metadata and controls
89 lines (79 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Original Library from - https://github.com/enternoescape/Arduino-IRremote-Due
// Sketch modified by Electromania Dec 2015
// http://theelectromania.blogspot.it/2015/12/home-built-ir-remote-receiver-or.html
// https://youtu.be/mwgnsFCX03E
//#include "global_def.h" // These don't seem to work. They should.
//#include "ms_remote_map.h" // These don't seem to work. They should.
#include <IRremote2.h>
// first check Hex code of each key of your remote and then modify the definations below
#define k3 0xFD40BF // we will define the HEX code for each key of remote (these codes are for my remote)
#define k4 0xFD20DF
#define k5 0xFDA05F
#define k6 0xFD609F
#define k7 0xFD10EF
#define OK 0xFDA857
#define RECV_PIN 11 // pin 11 used to receive IR code
IRrecv irrecv(RECV_PIN); // reads signal at pin 11
decode_results results;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(3, OUTPUT); // declare LED as output
digitalWrite(3, LOW); // to keep LED off by default in the begining
pinMode(4, OUTPUT); // declare LED as output
digitalWrite(4, LOW);
pinMode(5, OUTPUT); // declare LED as output
digitalWrite(5, LOW);
pinMode(6, OUTPUT); // declare LED as output
digitalWrite(6, LOW);
pinMode(7, OUTPUT); // declare LED as output
digitalWrite(7, LOW);
pinMode(RECV_PIN, INPUT); // declare LED as output
}
void loop() {
if (irrecv.decode(&results)) { //If IR receive results are detected
Serial.println(results.value, HEX); // print HEX code of pressed key at serial port
int Code = results.value; // HEX code is passed to variable Code
switch (Code) {
case k3: // if number 3 key is pressed it will switch ON LED at pin 3
{
digitalWrite(3, HIGH);
}
break;
case k4:
{
digitalWrite(4, HIGH);
}
break;
case k5:
{
digitalWrite(5, HIGH);
}
break;
case k6:
{
digitalWrite(6, HIGH);
}
break;
case k7:
{
digitalWrite(7, HIGH);
}
break;
case OK: // loop to reset all LEDs to OFF after pressing OK
{
for (int PinNo = 3; PinNo < 8; PinNo++)
{
delay(10);
digitalWrite(PinNo, LOW);
}
}
break;
default:
Serial.println("Waiting for commands"); // default case
break;
}
delay(200); // 1/5 second delay for arbitrary clicks.
irrecv.resume(); // Receive the next value
}
}