Object Detection using 38 kHz Pulsed Infrared - PICAXE-18X

copyright, Peter H Anderson, Baltimore, MD, May, '04


Introduction.

This application note describes how the PICAXE-18X may be interfaced with an Infrared LED pulsed at nominally 38 kHz and an inexpensive infrared receiver. This might be used to detect that an object is between the the IR LED and the receiver. Although, I did not carry this further than simply detecting the presence or the absence of the IR beam, the concept might be used to count interruptions, say the number of people passing through a door.

Trnasmitter.

The transmitter consists if an infrared LED with a series 330 Ohm resistor to limit the current sourced by the PICAXE to nominally 10 mA. A Jameco #172321 is an appropriate IR LED.

                                     IR LED
   Out3 (term 9) -------- 330 -------->|---- GRD
For greater range, the LED may be pulsed with a current closer to its rated 100 mA using an external NPN transistor as illustrated;
                                            +5 VDC
                                              |
                                              47 Ohm
                                              |
                                             IR LED
                                              |

                                          collector  (NPN transistor, 2N3904, TIP41C or similar)
   Out3 (term9) --------- 330 ------ base
                                          emitter
                                              |
                                             GRD

The IR LED may be pulsed at nominally 38 kHz, 40 kHz, 56 kHz or other similar frequencies using the PWMOut command;
          ' PWMOut 3, Period, DutyCycles

          PWMOut 3, 25, 52	    ' 38.4 kHz
          PWMOut 3, 24, 50      ' 40.0 kHz
          PWMOut 3, 23, 48      ' 41.6 kHz
          PWMOut 3, 22, 46      ' 43.5 kHz
          PWMOut 3, 21, 44      ' 45.5 kHz
          PWMOut 3, 20, 42      ' 47.6 kHz
          PWMOut 3, 19, 40      ' 50.0 kHz
          PWMOut 3, 18, 38      ' 52.6 kHz
          PWMOut 3, 17, 36      ' 55.5 kHz
          PWMOut 3, 16, 34      ' 58.8 kHz
Infrared receivers usually operate at 38, 40 or 56 kHz. A Jameco #220628 is a 38 KHz unit. Note that these receivers are actually pretty complex superhet receivers with automatic gain control. Thus, when no IR radiation, modulated at the appropriate frequency, is present, the gain of the receiever is at its maximum. On receipt of radiation, the gain decreases and if the receiver is subjected to continuous IR radiation, the gain will drop such that the radiation is no longer detected. Recall that these IR receivers are used in such remote devices as televisions where the duration of the IR is typically less that a few milliseconds. Thus, the duration of the infrared transmsission must be limited to avoid swamping the receiver. Note that the PWM may be turned off;
		PWMOunt 3, 0, 0

The output of these receivers is typically at a logic high. On receipt of the IR, the output goes low.

Thus, in the following program, the IR LED is pulsed for nominally 5 ms to assure the receiver has time to open its squelch. The output of the IR receiver is read by the PICAXE on input Pin0 (terminal 17) and the program forks to either light or turn off an orndinary LED depending on whether the beam has been broken. The PWM is turned off for 100 ms to assure the IR receiver has time to adjust its automatic gain control.


' IR_1.Bas
'
' copyright, Peter H Anderson, Baltimore, MD, May, '04

Main:

     PWMOut 3, 25, 52	' 26 usec period = 38.4 kHz
     ' for 40 kHz, use PWMOut 3, 24, 50
     Pause 3

     If Pin0 = 1 Then BeamBroken
     ' else
     Pin0 = 0 ' turn off LED
     GoTo Main_1

BeamBroken:
     Pin0 = 1  ' turn on LED

Main_1:
     PWMOut 3, 00, 00  ' turn off the PWM
     Pause 100
     GoTo Main