Introduction: IR Remote Control of PICAXE Micro

About: Happily married man who loves life, nature and technology.

The purpose of this blog is to show how to interface an IR remote control to a PICAXE-18M2 processor for robotics or automation. Universal remotes are cheap (what household doesn't have a few of them?) The code is very simple. I plan on using this to control a little robotic tank.

Step 1: PICAXE Brain and H-Bridge Brawn

A IR receiver module may be had for under $2. TV sets, DVD players and cable boxes all use this device to receive commands from their hand-held remote controls. Its output signal can go into any of the PIC's I/O ports (I chose B.2). The PIC has a function called "irin" that receives the code and stores it in a variable (b0). Using the debug mode on my programming software, I was able to push buttons on the remote control and see the codes being stored in b0. From that I was able to map the remote. It turned out that there were 53 codes between 0 and 52, a unique number for each button on the remote.

Step 2: Remote Decoded

Over the last 50 years, television manufacturers have come up with about a thousand different coding schemes for IR remote controls. The PICAXE-18M2 has built-in encryption for Sony. I set up the universal remote pictured below by depressing the "SETUP" button until it remained red, and entered the code "0152" from their user's guide. Every remote will be different, but any universal can emulate a Sony remote control. Note that on the numeric keypad, the number 1 is received as a zero, 2 as 1, and so forth.

Step 3: Servo, LED and Gear-Head Motor Demo

To demonstrate the capabilities of this circuit, I hooked up a servo, LED and gear-head motor to the breadboard. The PICAXE chip has 2 PWM generators, available on ports B.3 and B.6 (I chose B.3). The signal input to the servo is connected to this port via a 330 ohm resistor. The LED was wired to be driven by port B.4 (high for on). To drive the gear-head motor, the quad H-Bridge driver chip had to be used due to the current demand. It also has the feature of being able to reverse polarity (and direction) of the motor via 2 logic lines from the PIC (B.6 and B.7). If one is high and the other low, we get CW, one low and the other high, CCW, both low, the motor stops.

Step 4: Circuit Diagram

The PICAXE basic code is easy: the main loop keeps looking for a signal from the IR receiver via the "irin" command. When it gets a code, it places in in variable b0. Then that variable is tested with a series of "if...then" statements. If the condition is true, a subroutine is evoked, then the program returns to the main loop.

;IR Receiver Test Circuit
;for PICAXE-18M2
;James Dinsmore 7/01/2011


init: servo 3,140 ; initialise servo
main:



irin [1000,main],B.2,b0 ;wait for new signal
;debug

if b0=16 then motorfwd
if b0=17 then motorbkwd
if b0=20 then stopmotor
if b0=21 then lightLED
if b0=24 then extinguishLED
if b0=19 then servoleft
if b0=18 then servoright
if b0=26 then servomiddle


goto main


;subroutines


motorfwd: high B.7
low B.6
goto main


motorbkwd: low B.7
high B.6
goto main


stopmotor: low B.7
low B.6
goto main


lightLED: high B.4
goto main


extinguishLED: low B.4
goto main


servoleft: servopos 3,200
goto main


servoright: servopos 3,80
goto main



servomiddle: servopos 3,140
goto main




Step 5: Video of the Demo

Step 6: Parts List


Parts list
[Link]

Code
[Link]

Circuit Drawing
[Link]

My other stuff
[Link]

Microcontroller Contest

Participated in the
Microcontroller Contest