Kronos Robotics and Electronics
Site Map
 
Home Zeus Projects App Notes Downloads Dios Athena Forums
 

AAN102

Interfacing to an IR Module

  By Michael Simpson

Ever wanted to control one of your projects remotely.  How about data entry with out a keypad hookup? With a simple IR module and a bit of programming you can start collecting keystrokes with the best of them. 

I wont go into the theory behind infrared diodes or transistors nor will I get into distance detection. 

I will be concentrating on two particular modules.  The Sharp GP1U58X and the Vishay TSOP1840.  Both these modules operate at 40kHz and are well suited to our applications.  

There are a great number of remotes, and protocols to match but I will be writing about one in particular.  The Sony protocol.  

  • Its an easy protocol.  It is based on a pulse width bit stream which is very easy for microcontrollers to deal with.

  • The remotes are readily available.

The Protocol

Lets start by diving into the protocol.  The IR module will output a pulse stream of bits with varying widths.  The widths are defined as follows. 

Start Bit 2400us
State 1 1200us
State 2 600us

The world is not perfect and to compensate for various manufactures we have expanded the specification a bit as follows.

Start Bit Any pulse greater than 2000us wide.
State 1 Any pulse between 1000us and 2000us wide
State 2 Any pulse less than 1000us

The actual protocol consist of a starting bit followed by 12 data bits.  The data bits can be further broken down into command and device bits as shown.

S C C C C C C C D D D D D

These bits come with the least significant first and will be represented as the command byte and the device byte.  We will get into this further when we look at the code.

OK enough of this.  The Athena has a built-in command that takes care of all the bits and bytes for you.  All you have to do is connect the IR module and your ready.

The Modules

Lets look a little closer at the modules before we wire them up.

The Vishay and sharp modules are interchangeable except for the pin out as shown here.

Sharp
Pin1 Out

Pin2 VCC (+5v)

Pin3 GND

Vishay
Pin1 Out

Pin2 GND

Pin3 VCC (+5v)

 

The metal case can be removed from the Sharp module as shown here. 

 

The Circuit

Wire up the circuit as shown. You can use the Sharp or the Vishay module. 

 

Schematic 1

 

The Athena has a command called irin  this command returns both the cmd and device codes.  If the device code is 0 the command has timed out.   You can set the timeout by setting the register PULSEINTIMEOUT.  The closer this register is to 255 the faster the timeout. 

Program  (download it here)

'irin demo

   dim cmd,device

loop:
   irin 0,cmd,device
   if device = 0 then
     goto loop
   endif

   print cmd
   goto loop

 

The program is straight forward however there is an IRMODE register that will allow you to receive raw IR data from an Athena using the irout command in the same mode.  However that's another application note.

Parts List

Easy RS232 Driver  

Athena

Vishay IR Module

 

 

Copyright © 2001 - 2007 Kronos Robotics