www.webx.dk Start page
OZ2CPU Radioamateur mainpage
Homemade electronics Stuff old and new
Arduino IR remote code converter Samsung TV to Panasonic Audio Amplifier

Foreword:
Modern TV sets are designed to be thinner and thinner all the time, cooler design is what we want, how ever the speakers also gets slimmer,
and this way the audio quality gets worse, it is that simple, so modern tv sets must use some sort of external audio system,
NO external speaker connectors exist, could end the waranty by open the tv and connect wires to the internal amplifier that drives the small lousy speakers.
NO analog audio line output, only HDMI and optical. I choose to use the optical simply since I got and older spare Panasonic receiver stocked, it deliver fine audio from optical input.
NOW the problem! Samsung those muppets ! choose to deliver full audio level out all the time on the optical, volume and mute features via TV remote is simply disabled !!
while the internal speakers are disabled and optical out choosen, BUMMER !!! so I need TWO REMOTES on my table, one only to handle the lack of simple audio features, NOT ACCEPTED !!
Solution: make own little halve day project, listen to the Samsung TV IR codes, and send out the needed codes in Panasonic format, so Volume Up/Down and Mute buttons are "mirrored"


Working Prototype, OK lets explain all the hardware and software in great detail.


IR receiver unit, new type from ebay, cheap and easy to get, however they all work on slightly different wavelength (the colour of the IR)
and also slightly different modulation carrier, normally from 30-40kHz, Samsung use 37.8kHz and Panasonic use 36.7kHz
this type uses a bit different frequency so it does works, however the range of the samsung remote is poor, simply due to mismatch of specifications,
it is designed to attenuate all the wrong types, this way different types can be used in the same room, at the same time


This was supposed to be a one-night-project, so i had to visit the local junkyard, easy to find samsung equipment, broke off the IR receiver for free.
This one uses the right wavelength and modulation frequency, so it deliver amazing long range, it also is compleetly signal out silent, when no IR signal is in the room, great.
Note C3 positive and GND indications on the PCB, reveal the connections to the RX chip, so no need for datasheets.


The pinout is the same for all the 3 pin IR receivers I could find, Signal, GND, +5V


Note : it is a very good idea to locate a 470uF capacitor as close to the RX as possible,
it contain high gain ultra sensitive analog amplifiers and filters, so a good clean supply is needed.


The IR Diode was also ripped from junkyard, just too bad I could not find any Panasonic remotes,
would have been a good way to be sure the wavelength is right, for longest possible range.
Also note on some IR diodes the internal largest part, is not always GND as shown here, it is best to note the flat edge.
Some phone camera types can see a weak purple glow, this way the diode can be tested.
Else the forward voltage is very low for IR diodes, about 1.1V at 20mA, so if this is right, most likely it emit invisible magic light


Lets see on a scope, what the demodulated IR signal looks like, LOW DATA = IR signal. (Samsung)
First a slow pulse lead in, or start message code what ever you like to call it,
this is a very smart way to do it, now a decoder routine can be ready, and much more accuratly decode the faster data bits.


Zoomed in, on the lead-in


More zoomed, note all low pulses are short, this is where the IR transmission is active, this way the remote uses less battery,
Data information is contained by the long or short time between the signals. here the Data starts with 1 1 1 0 0 0 0

The Software.
I am sorry it is hammered together in a very few minutes, no clean ups, no time out added, no cool data handling, no error handeling.
But at actually works 100% for me, so i care not to waste more time with this.
Paste directly into Arduino:

---

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);  // the arduino board little red smd led
  pinMode(12, OUTPUT);  // red led
  pinMode(11, OUTPUT);  // green led
  pinMode(10, OUTPUT); // blue led
  pinMode(9, OUTPUT);  // IR LED
  pinMode(8, INPUT);
  Serial.begin(115200);
  
  Serial.println();
  Serial.println(F("ir Demo power on"));
}

char user1=0;
char user2=0;
//char ReadByteCheckTime=0;
int  StartBitLowTime=0;
int  StartBitHighTime=0;
int  DataBitLowTime=0;
int  DataBitHighTime=0;
int  DataBit0HighTime=0;
int  DataBit1HighTime=0;
int  DataBit2HighTime=0;
int  DataBit3HighTime=0;
int  DataBit4HighTime=0;
int  DataBit5HighTime=0;
int  DataBit6HighTime=0;
int  DataBit7HighTime=0;
char ReadBits[16];
char ReadBytes[16];
char TimeOutOfSpec=0;
unsigned char i;
unsigned char what_command_to_send=0;


void NowReadByteLow()
{
  TimeOutOfSpec=0;
  DataBitLowTime=0;
  user1 = digitalRead(8);   // read the IR detector
  while(user1==0)
  {
      user1 = digitalRead(8);   // read the IR detector
      delayMicroseconds(10);
      DataBitLowTime++;  // always about 24-28 just a low pulse
  }
  if((DataBitLowTime>15)&&(DataBitLowTime<60)) TimeOutOfSpec=0;
}


void NowReadByteHigh()
{
  TimeOutOfSpec=0;
  DataBitHighTime=0;
  user1 = digitalRead(8);   // read the IR detector
  while(user1==1)
  {
      user1 = digitalRead(8);   // read the IR detector
      delayMicroseconds(10);
      DataBitHighTime++;  // always about 24-28 just a low pulse
  }
  if((DataBitHighTime>15)&&(DataBitHighTime<160)) TimeOutOfSpec=0;
}

  



void NowReadBytes()
{
  ReadBits[0]=0;
  for(i=1;i<9;i++)
  {
    NowReadByteLow();
    NowReadByteHigh();  
    if(DataBitHighTime>80) ReadBits[0]+=(i*i);
  }
  ReadBits[1]=0;
  for(i=1;i<9;i++)
  {
    NowReadByteLow();
    NowReadByteHigh();  
    if(DataBitHighTime>80) ReadBits[1]+=(i*i);
  }
  ReadBits[2]=0;
  for(i=1;i<9;i++)
  {
    NowReadByteLow();
    NowReadByteHigh();  
    if(DataBitHighTime>80) ReadBits[2]+=(i*i);
  }
  ReadBits[3]=0;
  for(i=1;i<9;i++)
  {
    NowReadByteLow();
    NowReadByteHigh();  
    if(DataBitHighTime>80) ReadBits[3]+=(i*i);
  }
  
  user2=1;
}



void NowStartReading() 
{
  StartBitHighTime=0;
  user1 = digitalRead(8);   // read the IR detector
  while(user1==1)
  {
      user1 = digitalRead(8);   // read the IR detector
      delayMicroseconds(10);
      StartBitHighTime++;  // 358 = High time
  }
  if((StartBitHighTime>300)&&(StartBitHighTime<400)) NowReadBytes();
}


//-------------------------------------------------------------------------------------
void Send_Panasonic_Low_Bit() 
{
  for(i=1;i<18;i++)
  {
    digitalWrite(9, HIGH);    delayMicroseconds(9); // adjusted to 37kHz
    digitalWrite(9, LOW);     delayMicroseconds(9);
  }
}


void S0() 
{
   delayMicroseconds(410);
   Send_Panasonic_Low_Bit();
}

void S1() 
{
    delayMicroseconds(1270);
    Send_Panasonic_Low_Bit();
}



void Send_Panasonic_StartBit() 
{
  for(i=1;i<129;i++)
  {
    digitalWrite(9, HIGH);    delayMicroseconds(9); // adjusted to 37kHz
    digitalWrite(9, LOW);     delayMicroseconds(9);
  }
  delayMicroseconds(1680);
  Send_Panasonic_Low_Bit();
}






void loop() {
  StartBitLowTime=0;
  user1 = digitalRead(8);   // read the IR detector
  while(user1==0)
  {
      user1 = digitalRead(8);   // read the IR detector
      delayMicroseconds(10);
      StartBitLowTime++;  // 358 = low time
  } 
  if((StartBitLowTime>300)&&(StartBitLowTime<400)) NowStartReading();  // First Low Start Found
  
  



    if(user2==1)
    {
      DataBit0HighTime=ReadBits[0];      DataBit1HighTime=ReadBits[1];      DataBit2HighTime=ReadBits[2];  DataBit3HighTime=ReadBits[3]; 
      //Serial.print(DataBit0HighTime);  Serial.print(',');  // debugging
      //Serial.print(DataBit1HighTime);  Serial.print(',');
      //Serial.print(DataBit2HighTime);  Serial.print(',');       
      //Serial.print(DataBit3HighTime);  Serial.print(',');         
      //Serial.println();
      what_command_to_send=0;
      if((DataBit0HighTime==14)&&(DataBit1HighTime==14)&&(DataBit2HighTime==14))  what_command_to_send=1; //digitalWrite(10, HIGH); // vol up
      if((DataBit0HighTime==14)&&(DataBit1HighTime==14)&&(DataBit2HighTime==21))  what_command_to_send=2; //digitalWrite(11, HIGH); //vol down
      if((DataBit0HighTime==14)&&(DataBit1HighTime==14)&&(DataBit2HighTime==30))  what_command_to_send=3;  //digitalWrite(12, HIGH);  // mute

      if(what_command_to_send==1) digitalWrite(10, HIGH);  // led indicators if needed
      if(what_command_to_send==2) digitalWrite(11, HIGH);
      if(what_command_to_send==3) digitalWrite(12, HIGH);      
      delay(20);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);      
      user2=0;

      Send_Panasonic_StartBit();
      S0(); S1();
      S0(); S0(); S0(); S0(); S0(); S0(); S0(); S0(); S0(); S0(); S0(); //11   
      S1();  
      S0(); S0(); S0(); S0(); S0(); S0(); S0(); //7
      S1(); S0(); S1();
      S0(); S0(); S0(); S0(); S0(); S0(); S0(); S0(); //8  this is the common stuff
      if(what_command_to_send==1)
      {
         S0(); S0(); S0(); S0(); S0();
         S1(); 
         S0(); S0(); S0(); S0(); S0(); S0(); S0(); S0(); S0(); //9 
         S1(); 
      }
      if(what_command_to_send==2)
      {
         S1(); 
         S0(); S0(); S0(); S0(); 
         S1(); 
         S0(); S0();
         S1();         
         S0(); S0(); S0(); S0(); S0(); S0(); //6
         S1(); 
      }
      if(what_command_to_send==3)
      { 
         S0(); S1();  
         S0(); S0(); S1(); S1();        
         S0(); S0(); S0(); 
         S1(); S0(); S0();
         S1(); S0(); S0(); S1(); 
      }
      
    }

}


---


The panasonic format is slightly different, and it is ofcourse intended to be different, this way they dont jamm each other.


Zoomed in on the lead-in


Here blue is IR data input in Samsung format, and Yellow is IR LED signal out in Panasonic format.


Since the transmit part is 100% made in software, by lame busy loops, the receiver part will loose the next pakage in burst mode,
in case you hold down the button, no big deal anyways. Also note its own IR diode will jamm the RX if located near it,
no problem for me, since the panasonic equipment is located in closed cabinet.

OK, now it is working, lets make it nice:


RX to cap, painted black, not the detector eye.


Hot glue is heatshrink, makes it ready for install.


The compleete hardware ready for a little box, or maybe just heatshrink, and throw it in closet.
The IR diode, pcb got double side tape, stick on panasinic, bend the stiff wires, so the diode hit the location where the IR receiver is located.
this way very little current is needed for this IR led, and this way it dont jamm anything else.

-----------------------------

Thomas Scherrer OZ2CPU 2018
If you found this page usefull, why not consider donate a bit.. see my contact page please.