Universal IR remote switch
Use (allmost) any IR remote control to operate this switch.
general
By not trying to decode the IR-code received, but only counting edges and measuring the time between the edges, this device can be used with a lot of different remote controllers. I tested a couple of them (1 known RC5, 2 known NEC, the rest unclear) and all of them were useable.
But if you use an RC5 remote controller you will find that the switch is not allways responding. The reason is the toggle bit in the RC5 code, which changes polarity every time you release and press a button. This means that sometimes a button must be pressed a second time before the code is the same. In pulsed mode this problem can be overcome by storing the same code twice.
hardware
This project can be build using the PCB described here. Because of the simplicity also a piece of veroboard can be used. The schematic diagram and the partslist show the partnumbers as used on the universal PCB. R10 cannot be found on the silkscreen; it is placed between X5 and the nearest via (see PCB photo).
My version operated on 12V because 12V LED-spots had to be switched and that voltage was simply available. Operation on 5V is also possible if IC2 and D1 are replaced by jumpers and a 5V relay is used. In that case an old USB charger can eventually be the power supply.
Resistor array RN1 can be replaced by separate 22k resistors. In that case RN1a and RN1b are not needed, only RN1c and RN1d. R1 is not really needed; it can be omitted if you create your own PCB.
Instead of the TSOP1736 other IR receivers like the TSOP1836 can be used, but beware of the different pinning.
software
The reading of the IR data is done in an interrupt procedure. It is called if timer 0 overflows (every 4 ms) and if the IR signal pin goes from high to low (= becomes active). The interrupt is started as soon as an IR-signal is detected. At every pinchange the value of the timer is stored (max. 48 values). If too many overflows of the timer occur without pinchange or the max. number of samples is reached, the sampling of the IR code is stopped. This way the number of edges and the time between two edges are determined. If in setup mode these values are stored in the EEPROM; if in normal mode the received values are compared with the EEPROM values.
The overflow of timer 0 is also used in the delay_ms() routine and the pinchange is used to detect if still any IR-code is received. This is done in the main program with interrupts disabled; only the interrupt flags are used.
The serial interface of the microcontroller was needed for debug purposes but does not give usefull information for normal operation. It shows the number of edges received and the number of samples equal to the EEPROM values. Because the received data is not interpreted no further information about the contents of the IR-code is available.
operation
In the schematic 2 jumpers are shown: jumper JP1 is for setup and mode selection, jumper JP2 is for reset.
If jumper JP1 is placed before switch on the device operates in on/off mode. If not it operates in pulsed mode. If the jumper is placed after switch on setup is activated.
In setup mode you send code 1; the code is stored and the LED is switched on for indication . Then send code 2; also this code is stored and the LED is swiched off. From this moment the device is locked until the next reset.
In pulsed mode both IR-codes give the same response: the output is activated during a short time and is then switched off again. The length of the output pulse is 500 ms (determined by the parameter: "plslen").
In on/off mode code 1 switches on the output; code 2 switches it off. Code 1 and code 2 can be identical. In that situation the same key will toggle the output on and off. Holding the button on the remote controller has no effect, because after each response there is a waiting time in which no IR-codes may be received. You will have to release the button and press it again.
By not trying to decode the IR-code received, but only counting edges and measuring the time between the edges, this device can be used with a lot of different remote controllers. I tested a couple of them (1 known RC5, 2 known NEC, the rest unclear) and all of them were useable.
But if you use an RC5 remote controller you will find that the switch is not allways responding. The reason is the toggle bit in the RC5 code, which changes polarity every time you release and press a button. This means that sometimes a button must be pressed a second time before the code is the same. In pulsed mode this problem can be overcome by storing the same code twice.
hardware
This project can be build using the PCB described here. Because of the simplicity also a piece of veroboard can be used. The schematic diagram and the partslist show the partnumbers as used on the universal PCB. R10 cannot be found on the silkscreen; it is placed between X5 and the nearest via (see PCB photo).
My version operated on 12V because 12V LED-spots had to be switched and that voltage was simply available. Operation on 5V is also possible if IC2 and D1 are replaced by jumpers and a 5V relay is used. In that case an old USB charger can eventually be the power supply.
Resistor array RN1 can be replaced by separate 22k resistors. In that case RN1a and RN1b are not needed, only RN1c and RN1d. R1 is not really needed; it can be omitted if you create your own PCB.
Instead of the TSOP1736 other IR receivers like the TSOP1836 can be used, but beware of the different pinning.
software
The reading of the IR data is done in an interrupt procedure. It is called if timer 0 overflows (every 4 ms) and if the IR signal pin goes from high to low (= becomes active). The interrupt is started as soon as an IR-signal is detected. At every pinchange the value of the timer is stored (max. 48 values). If too many overflows of the timer occur without pinchange or the max. number of samples is reached, the sampling of the IR code is stopped. This way the number of edges and the time between two edges are determined. If in setup mode these values are stored in the EEPROM; if in normal mode the received values are compared with the EEPROM values.
The overflow of timer 0 is also used in the delay_ms() routine and the pinchange is used to detect if still any IR-code is received. This is done in the main program with interrupts disabled; only the interrupt flags are used.
The serial interface of the microcontroller was needed for debug purposes but does not give usefull information for normal operation. It shows the number of edges received and the number of samples equal to the EEPROM values. Because the received data is not interpreted no further information about the contents of the IR-code is available.
operation
In the schematic 2 jumpers are shown: jumper JP1 is for setup and mode selection, jumper JP2 is for reset.
If jumper JP1 is placed before switch on the device operates in on/off mode. If not it operates in pulsed mode. If the jumper is placed after switch on setup is activated.
In setup mode you send code 1; the code is stored and the LED is switched on for indication . Then send code 2; also this code is stored and the LED is swiched off. From this moment the device is locked until the next reset.
In pulsed mode both IR-codes give the same response: the output is activated during a short time and is then switched off again. The length of the output pulse is 500 ms (determined by the parameter: "plslen").
In on/off mode code 1 switches on the output; code 2 switches it off. Code 1 and code 2 can be identical. In that situation the same key will toggle the output on and off. Holding the button on the remote controller has no effect, because after each response there is a waiting time in which no IR-codes may be received. You will have to release the button and press it again.
Updates from the author