Rustic Engineering

My Mind working on…

Infrared Room Control (with Samsung IR protocol)

with 36 comments

I had ear some time ago that laziness sometimes is the best thing for inspiration. That week I discover that’s true.  Some nights,  I  lay on my bed to watch some thing on TV and doing some electronic research, before sleep. And, I don’t like to put off the lights (effficient ilumination is the best friend for a good reading) . Then, obviously, before sleep, I need to stand up to turn lights off. At my side, on bed, always resides a great remote control TV, with a set of unused buttons, telling “use us to turn the lights off“.

My remote

That’s a project that I was retarding because other, but now I decide to initiate and finish it.

The Basic Idea

The first step is recognize what my remote control is send to TV. It’s a Samsung remote control, with TV, VCR, DVD and STB specific and shared functions. My basic idea is: use some of this unused buttons to turn the lighst ON and OFF. But, why not dimmer the lamp? Why not doing some other useful thing? (Yes, thats because some projects growing up…)

So, the basic idea now is:

  • Make a device that recognize when a command is addressed to it self or not;
  • Recognize different commands;
  • Save usuful states (dimmer regulation);

Samsung Protocol

The Internet has a lot of information about RC5, NEC and Sony IR protocols, but not the same for Samsung. After some search at Google, I found this usefull page with some information about Samsung IR protocol. Resuming Samsung protocol:

  • 37.9KHz carrier wave (ON state is a burst of carrier with some duration, OFF is absense of it);
  • 1 Start bit (4.5ms ON, and 4.5ms OFF);
  • 32 data bits stream (data + address?);
  • bit “1” (590μs ON, 1690μs OFF) (thanks to Islam qabel,  for the more precise bit duration);
  • bit “0” (590μs ON, 590μs OFF);
  • 1 Stop bit (590μs ON, 590μs OFF);

I think that more information only with a test.

Test Circuit

The test circuit is very simple, consisting on a IR receiver (with filter, carrier demodulation and output). My only device available at home is a TSOP2236. Well, let’s go see what hapens.

TSOP2236 is a dedicated IR receiver with PIN diode and preamplifier, assembled on lead frame. The epoxy
package is designed as IR filter, to improve sensibility. The demodulated output signal can directly be
decoded by a microprocessor, but it’s logical reversed:

  • ON state (carrier presence): TSOP output LOW;
  • OFF state (carrier absence): TSOP output HIGH;

To make measures and confirm my suspects, I had use my Logic Analyzer from Saleae on the follow circuit:

Test Circuit

That’s the results for press button “1”:

Received data after pressing “button 1” on remote

Signal stream

Start bit identification (9ms total)

Bit “1” representation

Bit “0” representation

The process to gathering all this information is very easy with Logic Analyzer. The measured times differs a little bit, but this isn’t a problem. I count the transitions after the START bit and there’s 32 bits in.

Look again at the sequence of high and down states. Remember that we have a reversed version of the original IR wave from remote, because TSOP OUT signal is inverted. But actually it’s really doesn’t matter. What I need is: pressing “1” differs from pressing “2” or other buttons on remote. I don’t wanna to create a compatible device.

Decoding the data stream

To decode the data stream I used a PIC18F2520 MCU. I already has working on 16bits and 32bits MCU, but this project is much simple to require a great MCU. My design goals are:

  • Use internal clock (8Mhz, Instructiom Time TCy = 4/8MHz = 500ns);
  • Use Timer0 as counter with 1us increment (Timer0 prescaler to 1:2);
  • Use External Interrup 0 (INT0) to handle incoming IR waves and get the building IR code (final version);

That’s the circuit:

Decoding Test Circuit


The code (for Microchip C18 compiler) consist in a set of functions to detect when the signal change it’s state from DOWN to UP or UP to DOWN. See the sequence (basic):

Basic Algorithm

Note that for data bit identification, only HIGH time is important. It’s the difference between logic “1” and “0”, so you don’t need to be very precise in that differentiation. The red right program branch, needs to run 32 times, for all 32 bits.

I get…

The test was a success! After all, I have a 32bits unique data, that contains (probably) a Address Part and a Data Part. Again, I don’t worry about what is address or data. Only need unique 32 bits codes. If address part repeats (because you are send codes to one device), data should be unique. Ok to me.

The stream is read as it is delivered from TSOP to MCU, from left to right (START BIT to right). I’m considering from LSB to MSB, so when you see the analyzer stream signal, you are viewing the reversed version. See:

IR Data Stream Mapping

After some nights adjusting some things, the code works great!  I’ll publish it here in the next week.

As I think, some codes changes if you are using TV, DVD, VCR or STB buttons. See the codes for VCR function:

Some codes

If you observe the first pictures, about button “1” stream, you can see the sequence of 1110000 (reverse order, 0x07).

Proof of concept

To test my concept, I programing the device to waiting VCR signal functions (ended with ….0505) as you can see:

  • Buttons 1,2 and 3 turn ON color RED, GREEN and BLUE;
  • Buttons 4,5 and 6 turn OFF color RED, GREEN and BLUE;
  • Button 9 turn ALL ON;
  • Button 0 turn ALL OFF;
  • VOLUME+ increase LED power (PWM duty cycle);
  • VOLUME- decrease LED power (PWM duty cycle);

See my video:

Next Step

Now I need to design a transformerless power supply and the power control circuitry (TRIAC, etc) to control the real lights. Some nice ideas to next version:

  • Store dimming states on internal PIC EEPROM, so you can save desired conditions every time;
  • TV Remote now can act in others projects too (robots, toys, other home automation, etc);
  • With a small LCD, create a small menu, some configuration options, to more advanced projects;

I hope yours enjoy this project. From the first paper to here, I took one week to get it working properly. In a few weeks, I’ll share all the files here, in downloads page. Thank’s!


Written by forrequi

February 9, 2011 at 00:40

Posted in hack's, projects

Tagged with , , , , , , , ,

36 Responses

Subscribe to comments with RSS.

  1. Great idea!!!

    This was an excellent project. It’s very useful to “master” IR communication.

    Today I was simulating a Transformerless Power Supply with LTspice. I was having a little trouble and them I asked for help here (

    Do you know eevblog ( It’s wonderful blog too!

    P.S.: I can’t watch your Youtube video. It’s saying that it is a private video…



    February 9, 2011 at 04:56

  2. […] […]

  3. Great job ! Cant wait for documentation.
    I have same remote but want to use it to control volume pot on amp.


    June 1, 2011 at 14:22

  4. a question, why the rc filter on the power supply at the tsop?
    it was meant for what?


    June 4, 2011 at 11:39

  5. Awesome project!! I have been thinking the same. I too have a samsung one. Can i look into ur codes, pls?


    June 21, 2011 at 02:57

    • Yes, of course. I’m finishing the code to post it here. Maybe this weekend. Thanks.


      June 21, 2011 at 12:31

  6. thanks, it’s great..
    because your article i success built IR Receiver with AVR micro controller..


    September 21, 2011 at 06:36

    • Great news! I hope you make more things with it.


      September 27, 2011 at 07:14

  7. mehdi Mofidi

    October 19, 2011 at 07:58

  8. Great write-up on re-using the TV-remote for Non-TV purposes.

    VCsekhar Parepalli

    January 12, 2012 at 22:21

  9. Thank you for the write-up. It’s very helpful! One question, would a IR receiver with different carrier frequency, e.g. TSOP4838 (carrier freq = 38kHz) work with Samsung remote?


    November 24, 2012 at 21:12

    • Thank you for comment. I had never tested this receiver specifically, but I think yes. Some receivers has very wide filters, because the filter curvature is very low and works even with 40KHz.


      November 24, 2012 at 21:22

      • Thank you for your prompt reply. 🙂 I will give it a try.


        November 24, 2012 at 22:00

  10. hello, friend, please can you post your source in basic?, excelent your work, regards

    Pauel Benavides

    November 29, 2012 at 22:20

  11. Hi.. great job…i tried it but unfortunately, it did not work with me…. i tried on my Samsung monitor that can works as TV, PC monitor……i tried sending message of button “1” which is starting bit 4500 us “ON” + 4500 us “OFF” followed by “11100000111000000010000011011111” + “OFF” stopping bit . I generated the previous sequence for logic “1” 650us ON+1500us off and logic “0” 650us ON+650us OFF using PIC16F877A and the compiler is mikroc pro and i checked the code simulating in Proteus software and i found correct code, carrier frequency is 36 Khz, duty cycle around 60% and here is the code
    //————————Starting bit——————————————
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No1
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No2
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No3
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No4
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No5
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No6
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No7
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No8
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No9
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No10
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No11
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No12
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No13
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No14
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No15
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No16
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No17
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No18
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No19
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No20
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No21
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No22
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No23
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No24
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No25
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No26
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(650); //——-“0” No27
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No28
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No29
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No30
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No31
    portd.f7=1;delay_us(650);portd.f7=0;delay_us(1500);//——-“1” No32
    //—————————-End of code——————————-
    portd.f7=0; delay_ms(10); //—-stopping bit—
    the output at pin7 portd (code) is to modulate carrier at freq=36Khz, duty cycle around 64% generated by external circuit using 555 timer
    where is the problem??? i am so upset and frustrated……My TV did not respond please help help

    Islam Qabel

    February 6, 2013 at 17:06

    • where did you connect the 555 timer?


      November 16, 2016 at 10:34

  12. heyyyyyyyyy i got it i got it the problem that you have some mistakes in bit duration for example logic “1” is 560 us not 650us for ON and 1690us not 1500us for OFF also for logic “0” also stopping bit in not mentioned but anyway thanks alot for your great work and has the original useful page..please review bit duration carefully

    Islam Qabel

    February 6, 2013 at 17:32

    • Hi Islam, you are right! I don’t know why my code work with my bit duration, but I’ll correct the article with your tips. Thanks a lot.


      February 7, 2013 at 17:00

  13. where is the rest of codes?
    Power On/off, source input, menu……….thanks

    Islam qabel

    February 7, 2013 at 10:33

    • When I wrote this code I only need some functions. If you can catch the logic behind the protocol, you can easily produce the rest of functions. And you probably has these skills, cause you correct the code for me. Thanks again.

      After these project and some others I give a pause in Microchip PIC projects. Now I really want to abandon PIC and work with ARM, or maybe AVR. I’ll post about that soon.


      February 7, 2013 at 17:04

      • Thanks a lot for reply…but before you left PIC please please give me the rest of codes ….i saw a lot of pages for Samsung…most of them speak raw data codes which i can not realize the code…..Please help & support…. remember …your page was the first step for me to access my home devices.
        …first one was button”1″ and then power on/off found it so hardly……..and simulated it successfully so waiting for rest of codes……………….

        Islam qabel

        February 7, 2013 at 17:55

  14. You do not have to thank me, you embarrassed me Forrequi…….anyway….If you know something, you should not hide it because it is duty to transfer to all people…so from that principle ..let me introduce decoding procedure for raw data codes that i read in one web site pages…it is important…..for example, the captured raw data codes for Samsung TV button “Source” is:
    const unsigned int S_scr[68]={4600,4350,700,1550,650,1550,700,1500,700,450,650,450,700,400,700,400,700,400,700,1550,700,1500,700,1550,700,400,700,400,700,400,700,400,700,400,700,1550,700,400,700,450,650,450,650,450,700,400,700,400,700,400,700,450,650,1550,700,1500,700,1550,650,1550,700,1500,700,1550,700,1500,700};

    Islam qabel

    February 9, 2013 at 11:37

  15. decoding:
    these numbers represents time durations for all bit (ON & OFF) durations…….the first two numbers are for start bit 4600us for ON and 4350us for OFF…..the last number is ON duration for stop bit 700us “ON”…for data is beginning from the third number…each logic “1” & logic “0” takes two numbers (time durations)…
    look at the third & fourth numbers 700,1550 is logic”1″ …..for number 9th & 10th 700,450 is logic “0”…
    so for 700,1550 & 650,1550 are logic “1” which should be 560us for ON & 1690us for OFF
    for 700,450 & 700,400 & 650,450 are logic “0” which should be 560 us for ON & OFF so the final code is
    start + 1110 0000 1110 0000 1000 0000 0111 1111+stop
    for more codes please visit this page:

    Islam qabel

    February 9, 2013 at 11:48

  16. First of all , i appreciate you . I did my system according to your tutorial . I am curios on are there any command definetly shut down television (it does not matter television on which state), or where can i find it ?

    erdem simsek

    August 6, 2015 at 04:00

    • I really don’t know if there is such thing. The Samsung documentation is very poor about inside features.


      August 6, 2015 at 11:07

      • I agree with you , There is little data about samsung. What about the other brands? such as Sony , Philips , LG

        erdem simsek

        August 6, 2015 at 11:09

  17. heyy
    I have a PIC 16F877A, and I want to control my TV through the PIC, I read the protocol of samsung’s, but where shall I found the function table, like what’s the equivalent for volume up in the original remote control.
    In other words what should I send from my IR to raise the volume up,
    thanks in advance,


    October 16, 2016 at 16:40

  18. Thank you for the very well made explanation.
    But why did you want to stop working with PICs?


    January 17, 2017 at 15:10

    • Well, I think that is more about learning new things. I’ve learned about Microchip PIC before graduation. After that, some (much) things change and some kind of interest rise about other plataforms. I still love and apreciate PIC projects, only don’t expend much time with it.


      January 18, 2017 at 16:06

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: