01-03-2014  (1594 ) Categoria: RemotePic

RF-Remote Control Light Switch -Bascom

RF Remote Control Light Switch



RF Remote Control Light Switch



This is a remote controllable light switch that comes with an RF remote. The only light switch is across the room from my PC and it's a pretty large room. (The building's basically a 1-room apartment) so this works out great with the remote. Of course since I'm using the remote to cut the lights when I go to bed I'm basically using the remote from two places which brings with it the unavoidable annoyance of the remote being in the wrong place all the time. Which means I have to get up and look for it which is effectively as much of an annoyance as it was meant to solve. So I wanted a second controller that would basically be a stationary switch by my bed so I could leave the portable remote around the desk.


RF Remote Control Light Switch

I popped the original remote open to see what I was dealing with. After some research I concluded that LP801B is a PT2262 clone which is a remote control encoder chip. Has a few address and data pins and generates a signal on the output pin based on the configuration of those at the time the enable pin is connected to ground.
At first I didn't think much of it and ordered some PT2262s and made a PCB which is basically a clone of the original remote adapted for components I had lying around (or just stupidly large pads where I had no idea what I was going to use when I made the board)

Not being patient enough however I started looking around to see if anyone's emulated this chip on a microcontroller before. Turns out, several people did.
So I took the code at http://www.mikroe.com/forum/viewtopic.php?f=13&t=10832 and ported it over to BASCOM for the ATTINY13.
I think that code has a bug though as the logic low component of the syncbit should be 31 times the short-pulse duration according to the datasheet not 7. (He's basically divided the datasheet units by 4 in case anyone actually looks into this) The decoders may not care as It seems to have worked for him. When I got mine to work I was using the datasheet-correct count so I didn't test with that. It took several modifications to my original board to get it working with the attiny. Had to put in 3 zeners as the PT2262 operates directly from 12v which the attiny can't do. I actually fried an ATTINY2313 the first time around because I forgot the two selector/power buttons that were still at 12v. If I knew in advance that I'd be able to do this I would've designed a much smaller board..

I was trying random numbers for the pulse duration and randomly tuning the white variable capacitor but with none of the parameters actually being correct this method was never going to work. After some wasted time I caved and connected the original remote's encoder chip data output pin to the microphone input of my netbook.

Then with the cool Soundcard Oscilloscope to which I could adapt my pulse duration.
At this point I tested my board and while tuning the variable cap it suddenly became dark in the room :) It took a few more iterations to get the delay "just right" but now it works perfectly.
I put it in a small electrical box with 2 push-buttons and installed it in an easy to reach location from the bed.

Some component leg that I forgot to cut (probably a resistor) must have punctured the battery wire though as it drained to 10v by that night and since the circuit is basically open when none of the buttons are pressed that shouldn't happen at all. I did find a puncture mark on the positive lead so that must have been it.. damn. After reseating the board in the box and making sure the battery wires don't pass under any component legs it hasn't happened again.

Project files:

Board
Very large. But the (somewhat smaller, by about 20%, still fairly large) version is on the browsing/printing PC upstairs and I'm too lazy to get it :) Note below on the jumper blocks:
[1] [2] [3]
No connection: FLOAT bit
1+3: Bit 0
2+3: Bit 1
1+2: Short out the battery
And that this PCB is for the PT2262 (and clones) so it needs modifications to be used with an AVR. At least 1 5.1V zener for the CHIPPWR and 1 per button.

The board runs off a 23A (12 volt) stack battery. Running from lower voltages may be possible but the RF circuit definitely needs to be retuned.

Schematic
The seemingly unconnected wires from the diodes on the data pins are actually connected to CHIPPWR.

PT2262 emulation code in BASCOM


001 $regfile = "attiny13.dat"
002 $crystal = 9600000
003
004 Declare Sub Sendbit(byval A As Byte)
005 Declare Sub Alpha()
006 Declare Sub Longa()
007 Declare Sub Synca()
008
009 Dim T As Integer
010 Dim D As Integer
011
012 Dim Number As Byte
013 Number = 10
014
015 Dim X As Byte
016
017 Dataout Alias Portb.2
018 Dataout = 0
019
020 Config Dataout = Output
021 Config Portb.0 = Input
022 Config Portb.1 = Input
023
024
025 If Pinb.0 = 0 Then
026
027 Do
028
029 Sendbit 1 'a0
030 Sendbit 0 'a1
031 Sendbit 0 'a2
032 Sendbit 2 'a3
033 Sendbit 2 'a4
034 Sendbit 2 'a5
035 Sendbit 2 'a6
036 Sendbit 0 'a7
037
038 Sendbit 0 'btn0 (not on my unit)
039 Sendbit 0 'btn1
040 Sendbit 1 'btn2
041 Sendbit 0 'btn3 (not on my unit)
042 Sendbit 3
043
044 Loop
045
046 End If
047
048 If Pinb.1 = 0 Then
049
050 Do
051
052 Sendbit 1 'a0
053 Sendbit 0 'a1
054 Sendbit 0 'a2
055 Sendbit 2 'a3
056 Sendbit 2 'a4
057 Sendbit 2 'a5
058 Sendbit 2 'a6
059 Sendbit 0 'a7
060
061 Sendbit 0 'btn0 (not on my unit)
062 Sendbit 1 'btn1
063 Sendbit 0 'btn2
064 Sendbit 0 'btn3 (not on my unit)
065 Sendbit 3
066
067 Loop
068
069
070 End If
071
072
073 End
074
075
076 Sub Alpha()
077
078 Waitus 261
079
080 End Sub
081
082
083 Sub Longa()
084
085 Alpha
086 Alpha
087 Alpha
088
089 End Sub
090
091 Sub Synca()
092
093 Local Y As Byte
094 For Y = 1 To 31
095 Alpha
096 Next Y
097
098 End Sub
099
100 Sub Sendbit(a As Abyte)
101 Select Case A
102 ' 0 bit
103 Case 0:
104 Dataout = 1
105 Alpha
106 Dataout = 0
107 Longa
108 Dataout = 1
109 Alpha
110 Dataout = 0
111 Longa
112 ' 1 bit
113 Case 1:
114 Dataout = 1
115 Longa
116 Dataout = 0
117 Alpha
118 Dataout = 1
119 Longa
120 Dataout = 0
121 Alpha
122 ' FLOAT bit
123 Case 2:
124 Dataout = 1
125 Alpha
126 Dataout = 0
127 Longa
128 Dataout = 1
129 Longa
130 Dataout = 0
131 Alpha
132 ' SYNC bit
133 Case 3:
134 Dataout = 1
135 Alpha
136 Dataout = 0
137 Synca
138
139 End Select
140
141 End Sub




RF Remote Control Light Switch


RF Remote Control Light Switch





versió per imprimir