PDA

View Full Version : Home Theater IR Remote Light Switch



RFEFX
- 5th November 2011, 22:11
Hello all,

I want briefly mention that I had similar code a long time ago.. but since Ivanrosale (http://www.picbasic.co.uk/forum/content.php?r=438-Add-IR-remote-control-capabilities-to-your-next-project%21%21) posted his I will give him the credit.

Its been a while since my last Article. This project was a long time coming for one of my home projects.

I have recently come across a bulk quantity of PIC16F628A in the SSOP package. if you are not familiar with the SSOP package the processor is about the size of your pinky fingernail.

This board was designed for the sole reason to turn on and off an RF switch. The RF lamp switch I acquired years ago was from radio shack and has long been discontinued. but any RF remote wall outlet has potential.
The Board features a Micrel 3.0 Amp adjustable voltage regulator (29302WU) and is set to 5Vdc Output and is also protected by a fuse. The Mini USB jack is not for usb but is ICSP. it allows the board to be programmed through my modified U2 programmer. Pic Kit 3 ICSP pin header was also added.

The PIC16F628A receives input to PORTA.2 from sparkfun Electronics IR Receiver Diode (http://www.sparkfun.com/products/10266). The footprint for the Surface mount IR Receiver (http://www.sparkfun.com/products/8545) is also available in the same location on the board. The PIC's output drives a 7 bit Darlington array (ULN2003). the primary function for this is to close a switch to ground.
By setting any pin on PortB [5:0], PortA.1 to high will cause the output of the array to go to ground in turn lighting the corresponding LED attached to that output.

For this project the Radio shack uses a 12v battery for power. I tried powering the remote from this board but the RF chip requires 12v. Not a problem. I noticed the switches on this remote contact ground. Did i tell you that this board was designed around this remote. By attaching our outputs to both sides of the switches on the remote it basically acts as an extended switch. So instead of pushing the buttons on the remote the IR board is gonna do it. Just keep in mind that since the remote uses a battery a common ground between both systems is needed.

My modified code will learn the First IR code it receives and stores it as long as there is power. the reason for this is because, this is going into my theater room and want to turn off the lights with the button I dedicate. what better way than to learn the Button you want to use.

(the project case is a travel soap container.. LOL)



define osc 20
CMCON = 7

low porta.4
low portb.3
low portb.2
high porta.3

Pulse var byte[12]
Command var byte
Start var byte
Stored var byte
Device var byte
Counter var Byte
Compare1 var byte
Compare2 var byte
LampStatus var byte
X var byte


'*********************** Receive IR Signal *************************************

'The PULSIN resolution is 2uS with PIC running at 20MHz

WaitForStart: 'Wait for Start signal
PuLSIN PORTA.2,0,start 'Check the low pulse width
if start < 180 then WaitForStart 'If the Start pulse < 1.8mS repeat the loop

for counter = 0 to 11 'Get the 12 pulses of the signal
pulsin PORTA.2,0,pulse[counter]
next
if stored = 1 then Verify 'Check to see if any signal has been received.

'********************** Learn First IR Signal **********************************

StoreBits:
command = 0
device = 0
low porta.3
for counter = 0 to 6
if pulse[counter] < 90 then 'Determine if the pulse represents 0 or 1
command.0[counter] = 0
Else
command.0[counter] = 1
endif
next
for counter=7 to 11
if pulse[counter] < 90 then
device.0[counter-7] = 0
Else
device.0[counter-7] = 1
endif
next
stored = 1
goto waitforstart

'********************** Compare to Stored IR signal ****************************

Verify:
compare1 = 0
compare2 = 0
for counter = 0 to 6
if pulse[counter] < 90 then 'Determine if the pulse represents 0 or 1
compare1.0[counter] = 0 'Storing new signal in Compare variable.
Else
compare1.0[counter] = 1
endif
next
for counter=7 to 11
if pulse[counter] < 90 then
compare2.0[counter-7] = 0
Else
compare2.0[counter-7] = 1
endif
next

for counter = 0 to 6 ' Compare incoming signal to the stored signal
if compare1.0[counter] <> command.0[counter] then Bad_signal
next
for counter = 7 to 11
if compare2.0[counter - 7] <> device.0[counter - 7] then bad_signal
next

GoodSignal:
if LampStatus = 1 then LampOff ' Check the Lamp Status

LampOn:
high portb.3
pause 1000
low portb.3
pause 3000
Lampstatus = 1 ' Set the lamp Status to 1 stating the lamp is on.
goto waitforstart


LampOff: 'Lamp Control
High portb.2
pause 1000
low portb.2
pause 3000
Lampstatus = 0
goto waitforstart

Bad_Signal 'Flash the Front LED for bad signal received. This my get annoying
for x = 0 to 10
pulsout porta.3,20000
pause 750
low porta.3
next
goto waitforstart








http://www.gmdii.com/Projects/IMG_7095.JPG


http://www.gmdii.com/Projects/IMG_3556_25.JPG




http://youtu.be/d6Q5vuHbI_4

RossWaddell
- 12th November 2012, 20:23
Hi RFEFX - I'm trying to find some examples of using an IR remote to turn on/off a PCB board, kinda like a stereo receiver/TV/DVD box works (the box's remote power button toggles the power on or off but you can also turn it off with the switch right on the box). Could I adapt your code for that purpose (my board runs on 9V DC so not as serious as your AC house mains)

RFEFX
- 15th November 2012, 22:25
Well it looks like your doing almost the same thing as i have done.. my board, also running off 9v, it is simply closing contacts on another board (the remote). Can you elaborate on the design or your intent?

Regards,
- Gary D.

RossWaddell
- 15th November 2012, 23:43
I have a model with a custom circuit board with controls LEDs and motors. I want to be able to turn it on/off with a button on the model itself, or with a remote - exactly like a TV/DVD/stereo. I've never done IR before, but I imagine there will be a dedicated chip hooked up to an IR receiver (running on a button battery? It has to be small because the space in the model's base is tight) and when it receives the power command it completes a relay (latch?) between the 9VDC power supply and the PCB. Does that make sense?

peterdeco1
- 22nd February 2022, 18:29
I like the way you snuck in that link right after your first word "Well(link).

richard
- 23rd February 2022, 03:17
would that be a trojan horse ?

Ioannis
- 23rd February 2022, 13:14
Gone...

Ioannis

mpgmike
- 23rd February 2022, 19:29
I had removed the embedded link earlier.