# blog.zwotausend.de

## 21.12.14

### A successful way to control infrared equipment via an Arduino and an infrared LED

 Controlling and LED-stripe with IR light
This is the second part of my little tutorial on how to measure an IR pulse sequence from a remote control (see this article) and then copy and send this sequence to control equipment like a TV, a lamp or other IR equipment. The adarfuit.com website gives us once more a possible way on how to implement this, but in the following article we want to discuss on how to make it easier and again somehow more convenient in many cases. We can easily use the comma-separated values we got from our pulse measurements from the previous article to control the LED and output the needed 38 kHz signal sequence.

Again, first the code, and afterwards an explanation:

int irledpin=7;
int pulsmatrix[200]=        { // in the next line we put our pulse sequence, starting with the time of our first pulse:
8990,4540,530,560,510,640,500,590,580,560,520,580,550,580,580,550,520,580,560,1720,520,1780,510,1660,550,1710,530,1710,560,1690,550,1720,530,1720,580,1650,560,570,570,620,480,1770,520,560,520,580,550,640,490,580,530,640,490,1710,530,1720,550,580,530,1720,550,1690,550,1710,540,1710,560,40030,8980,2240,530
};
long matrixsum[200];

void setup()                                                               {
pinMode(irledpin, OUTPUT); Serial.begin(9600);
matrixsum[0]=pulsmatrix[0];
for(int i=1;i<200;i++){matrixsum[i]=pulsmatrix[i]+matrixsum[i-1];}       }   // The values are added, what we get is the ending times in microseconds for pulses and pulse-free times.

void pulse()                        {
digitalWrite(irledpin, HIGH);
delayMicroseconds(9);         // the value can be 10 or 8 also, but 9 should work quite well as it gives us a pulse very near to 38 kHz.
digitalWrite(irledpin, LOW);
delayMicroseconds(9);           }

void loop(){

delay(1000);              // delay between pulses, may not be too little, at best stay over 300.
Serial.println("Pulse sequence starts");
long start=micros();
for(int i=0;i<200;i+=1)                                     {
while(micros()<start+matrixsum[i]){pulse();}                  // here we send our 38 kHz pulse
i+=1;
while(micros()<start+matrixsum[i]){}                      }   // a pause, until we start our next pulse
Serial.println("done");
Serial.println();

}

In the following a little explanation:

The code is easy to understand. We define our pulse sequence at the beginning, where the first time is the length of the first pulse, the next value is the pulse-free time, then the next pulse value and so on. The matrixsum adds all the values in some kind of a ladder, so we have the ending times of the pulses in a very accurate way. That avoids a problematic stretching of the whole sequence and was very accurate in first tests - see the hi-res video on Youtube shown below:

In this video the Arduino sends the command to change the color to red every 1 second, and in between I switch to other colors with the "real" remote.

#### 1 Kommentar:

remote extender

Kommentare verfassen ist hier sehr einfach, man kann sogar ohne Anmeldung anonym Kommentare hinterlassen. Also, zeig' uns deine Meinung ...

Name

E-Mail *

Nachricht *