Intro: IR Remote Control of PICAXE Micro
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
;James Dinsmore 7/01/2011
init: servo 3,140 ; initialise servo
irin [1000,main],B.2,b0 ;wait for new signal
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
motorfwd: high B.7
motorbkwd: low B.7
stopmotor: low B.7
lightLED: high B.4
extinguishLED: low B.4
servoleft: servopos 3,200
servoright: servopos 3,80
servomiddle: servopos 3,140