IR Light Dimmer v2 (1kB Challenge edition)

Infra-red light dimmer (220V/110V) that sits behind a switch in the wall. Powers itself from the mains, uses triac to turn on the bulb.

Similar projects worth following
This is an infra-red light controlled dimmer that is connected in series with the load (resistive - incandescent light bulb). It powers itself from the mains voltage which can be either 110/220V 60/50Hz and uses a Triac to turn the light bulb ON by short-circuiting its own power supply!

Microcontroller used in this project is either PIC12F629 or F675 that has only 1024 words (14336 bytes of FLASH memory) but the program fits in less than 1kB as required by the 1kB Challenge rules (including the OSCCAL values!).

Features of the device:
- Series connection! (only 2 wires)
- Soft start (gradually turning on the light bulb)
- Soft down (gradually turning off the light bulb)
- Learning IR codes from RC5 and NEC remotes
- Dimming in 10 levels by using only IR remote
- Previous dimm-level remembering when operating with remote
- Sleep timer
- ON/OFF control with wall switch

*** I am waiting for PCBs from the factory. New Year breaks and holidays delayed it... ***

This device is connected to mains power line therefore it requires a lot of respect. If you are not sure in what you are doing, you better leave the installation part to the experienced electrician. Even though this device operates on 5V DC, when connected to mains voltage it can still kill you if you touch any part of it!

You can safely assemble it on your bench, but once it is connected to the mains, DO NOT TOUCH IT!


I recently decided to publish this project on my webpage so I decided to send it to 1kB Challenge here as well. The firmware has been optimized to fit within specs of the challenge and source code is written in Microchip Assembly. You can download MPLAB from and assemble a version with your own modifications! There is much room to spare in PIC (whole additional 1kB!).

How this device works is pretty cool, it powers itself from the mains through the load (usually a light bulb but it can also be a resistive heating element). The way it turns the load ON is by short-circuiting its own power supply! You can control it with your own TV remote controller - all you need is 4 spare buttons (usually those used for Teletext so that they don't interfere with normal TV usage). If you can't spare 4 buttons you can teach the device just 2 buttons, but in this case you either loose the dimming functionality - you can only turn the light on and off, or you loose the OFF button so you would need to dim-down to level 0 in order to turn the lights off. It recognizes two IR protocols: NEC and RC5 (mostly used in the world).

How it works?

Transformerless power supply

The device is powered from the mains voltage using capacitive power supply. You should read all about it on this link: and also this link:

Stand-By (lights Off)

The device powers itself from the mains voltage, through the resistive load (light bulb). It consumes very little power (< 5mA) so the light bulb does not glow during stand-by. The main consumer is the TSOP IR receiver, but you can also use low-power TSOPs such as TSOP38238 if you want to bring this down to under 1mA. In this state, PIC microcontroller is waiting for IR signal from TSOP or a press from the wall switch. Please bear in mind that wall switch must no longer be a classical on/off switch - it must be replaced with a push-button switch that closes the contacts only while you keep pressing it.

In this state the triac is not fired and nothing special happens.

On-State (lights ON or Dimmed)

If a wall switch is pressed or appropriate IR signal is received from the remote, the light bulb will turn ON. Turning the light bulb ON is accomplished by firing the Triac when mains voltage cross the zero point. This is detected with the zero-crossing detector formed with R3 and C6. If we trigger the Triac right after the "zero" has been detected it will turn the lights ON at full intensity. If we delay the Triac firing by some time we can effectively perform dimming as the voltage that appears at the output is smaller than the supply voltage. You can read the app note from ST here: (serial-dimmer such as this one can be found starting from page 16). This app note also contains calculations for the transformerless power supply - so check it out as well!

If we look at the circuit schematics - the power supply part, we can see that when Triac starts conducting it short-circuits our transformerless power supply. At this point entire circuit is powered from capacitor C3. It should be large enough to keep enough power for TSOP (~5mA), PIC (< 1mA) and MOC3023 (~5mA but only for a few microseconds) so don't be shy to use larger-valued capacitor here, such as 220uF/330uF/470uF. If we keep the light turned ON at full brightness it will eventually discharge the C3 completely and restart the PIC microcontroller....

Read more »


Wiring diagram

Portable Network Graphics (PNG) - 78.22 kB - 01/03/2017 at 16:19



Bottom PCB Copper

Adobe Portable Document Format - 5.45 kB - 01/02/2017 at 19:11



Top PCB Copper

Adobe Portable Document Format - 5.12 kB - 01/02/2017 at 19:11



Bottom PCB component placement

Portable Network Graphics (PNG) - 5.07 kB - 01/02/2017 at 19:09



Top PCB component placement

Portable Network Graphics (PNG) - 6.36 kB - 01/02/2017 at 19:09


View all 6 files

  • 1 × PIC12F629 or PIC12F675 Microcontroller with firmware for either 50 or 60Hz operation
  • 1 × Capacitor 0.22uF 400V (X2 rated) Electronic Components / Misc. Electronic Components
  • 1 × Resistor 100ohm - 1k (minimum 2W) Electronic Components / Misc. Electronic Components
  • 1 × TSOP17xx or TSOP18xx IR receiver Opto and Fiber Optic Semiconductors and ICs / Other Optoelectronic ICs
  • 1 × BTA16-600B Discrete Semiconductors / Thyristors (DIACs, SIDACs, TRIACs, SCRs)

View all 13 components

  • Firmware Details

    trax01/02/2017 at 19:05 0 comments

    Firmware details

    Firmware is written in Microchip Assembly and does not require any libraries. It can be compiled for two PIC microcontrollers: PIC12F629 and PIC12F675. If you compile for PIC12F675 the firmware will be 2 words larger because of additional registers that need to be initialized for this PIC.

    50/60Hz choice

    You can compile the code for 50 or 60Hz mains frequency. There is a constant in the code that you need to un/comment for this:

    ;***** Mains frequency in Hz *****
    ; if defined it uses lookup table for 50Hz, else it uses 60Hz lookup table
    #define		FREQ50 1

    PIC12F629 Firmware

    To compile for F629, you need to include appropriate header files like this:

    ;***** Declaration and PIC config *****
            PROCESSOR 12f629
            #include ""

    The resulting code will occupy exactly 559 words (978,25). There is one additional word at the end of program memory which is programmed in the Microchip factory. If we count that in as well, the size of program is 980 bytes.

    PIC12F675 Firmware

    To compile for F675, you need to include appropriate header files like this:

    ;***** Declaration and PIC config *****
            PROCESSOR 12f675
            #include ""

    The resulting code will occupy exactly 561 words (981,75 bytes). If we add that OSCCAL from the end, the size of program is: 983,5 bytes.

View project log

  • 1
    Step 1

    Instructions will be added once I receive official PCBs from the factory.

View all instructions

Enjoy this project?



mockoszhobitocka wrote 02/28/2017 at 10:21 point

In my opinion in the schematic has an problem. The optocoupler 1 pin is anod. therefore is it can not be GND

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates