Experiment 20: infrared remote control: 1、Infrared receiving head introduction
Experiment 20: infrared remote control: 1、Infrared receiving head introduction
Experiment 20: infrared remote control: 1、Infrared receiving head introduction
Note: the IRremote folder into the compiler to install the directory under the Arduinolibraries.
1, experimental
device
3、Experimental principle
To decode a remote controller must be aware of the remote control of the
encoding way. This product is used to control the code of the way: NEC
agreement. Following the introduction of the NEC protocol:
·NEC protocol description: features: (1) 8 address bits, 8 bit command
(two) for the 2 time in order to address the reliability address bit and
the command bit
A command sent once, even on the remote control button is still pressed.
When the button has been pressed, the first 110ms of the pulse and the
image above, after each 110ms repeat code transmission.
·repetitive pulse
void setup()
{
pinMode(RECV_PIN, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
int on = 0;
unsigned long last = millis();
void loop()
{
if (irrecv.decode(&results))
{
// If it's been at least 1/4 second since the last
// IR received, toggle the relay
if (millis() - last > 250)
{
on = !on;
// digitalWrite(8, on ? HIGH : LOW);
digitalWrite(13, on ? HIGH : LOW);
dump(&results);
}
if (results.value == on1 )
digitalWrite(LED1, HIGH);
if (results.value == off1 )
digitalWrite(LED1, LOW);
if (results.value == on2 )
digitalWrite(LED2, HIGH);
if (results.value == off2 )
digitalWrite(LED2, LOW);
if (results.value == on3 )
digitalWrite(LED3, HIGH);
if (results.value == off3 )
digitalWrite(LED3, LOW);
if (results.value == on4 )
digitalWrite(LED4, HIGH);
if (results.value == off4 )
digitalWrite(LED4, LOW);
if (results.value == on5 )
digitalWrite(LED5, HIGH);
if (results.value == off5 )
digitalWrite(LED5, LOW);
if (results.value == on6 )
digitalWrite(LED6, HIGH);
if (results.value == off6 )
digitalWrite(LED6, LOW);
last = millis();
irrecv.resume(); // Receive the next value
}
}
5, program function
Experiment screenshot:
note:
Put the