This is an idea I had to control lights in my room. I like light when I am getting into the bed, but I hate getting up to turn off the light. With this system I can turn the light off without getting up. The only problem that I have is that I did not allow enough room for the infrared receiver to receive a signal from all angles.
This program was written in C for Microchip’s PIC12F629 MCU ($1.75EA). Here’s an explanation of the programs:
The remote first sends a 1mS pulse to wake the receiver, then the remote sends one of 2 different infrared pulses that correspond to the plug that I want to control: #1 is a 15mS pulse and #2 is a 20mS pulse. The pulses are NANDed together with a 38kHz “carrier” pulse from a 555 timer to create a standard infrared signal. The infrared receiver drops the 38kHz carrier pulse leaving only the data.
The receiver receives the first pulse and moves to a different section of the program and waits for the second pulse. Once the second pulse comes in it starts a 16-bit timer that is stopped as soon as the pulse ends. Then the timer result is divided by 1000 and stored in an 8-bit integer. The two pulse lengths can range from 13mS to 17mS and 18mS to 21mS. I use a SWITCH to test for the result. Once the signal is received the program toggles the outputs that correspond.