PDA

View Full Version : Need help - Just want to make a simple switch using RF Modules



financecatalyst
- 24th October 2009, 12:02
Hello everyone.
I have two RF modules and I want to make a switch where the receiver should keep a pin high if and untill it is getting a valid signal from the transmitter. Receiver is driving a 12v Relay using 9013 via 1K.
Currenty the relay is producing flickering. My code is attached.

Can some please try to help?

aratti
- 24th October 2009, 12:35
With the code you have posted, you set high gpio.5 when w1 is 24 and gpio.1 when w1 is 51 then you go to label start and you set gpio to 0, this is why relay flickers


start:
gpio=0
serin GPIO.2,N2400,["pl65"],w1
if w1=24 then gpio.5=1
if w1=51 then gpio.1=1
'if w1=90 then gpio.4=1
'if w1=36 then gpio.0=1
pause 500
goto start

Set gpio=0 to the begining of your code, in such a way that is executed at start up only once, than use a condition like :



if w1=25 then gpio.5=0
if w1=52 then gpio.1=0


to switch off your relays.

Al

Jerson
- 24th October 2009, 12:36
Use this as your receiver code



Define OSC 4
intcon=0
cmcon0=7
TRISIO=%001100
GPIO=0
w1 VAR byte
prevw1 var byte
Include "modedefs.bas"

@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _CP_ON & _BOD_ON & _CPD_ON & _IESO_OFF & _FCMEN_ON & _WUREN_OFF

start:
serin GPIO.2,N2400,["pl65"],w1
if w1 <> prevw1 then ' new command not same as prev
prevw1 = w1 ' update the value of prev command
gpio = 0
if w1=24 then gpio.5=1 ' and change the output
if w1=51 then gpio.1=1
'if w1=90 then gpio.4=1
'if w1=36 then gpio.0=1
pause 500 ' you may not need this line now
endif
goto start

Now-Started
- 24th October 2009, 13:14
Thanks for the answers guys, few questions:
I only have two buttons on Tx as an option. I am sorry if I failed to explain that the process has to work with one button only, i.e. if button 1 is pressed relay one should activate and when it is released relay should stop, same with the button 2 and relay 2.

I added gpio=0 at after start to make sure the relays are off if no valid signal is comming otherwise before that statement relay was just left on.

aratti
- 24th October 2009, 16:15
Your transmitter, when you release the push-botton, should Tx ascii(100) or "d" then reciever will reset to zero both relays



start:
serin GPIO.2,N2400,["pl65"],w1
if w1=24 then gpio.5=1
if w1=51 then gpio.1=1
if w1=100 and gpio.1=1 or gpio.5 = 1 then gpio = 0
goto start


Al.

financecatalyst
- 24th October 2009, 17:08
Problem is that the Tx only gets power while the button is pressed once button is released, power is also removed from the pic. Is there any way I can achieve my goal using an capacitor or somthing at the output in the hardware as I dont seem to figure out an solution with software (Unless someone comes up with somthing I can try on my exsisting setup). I already tried using an 470uF at the output pin + replacing 1K wih an diode. I am having problem with timings now BUT flickering seems to have been absorbed by the capacitor. If possible any sugesstion about the cap values I can try to have instant responses by the receiver PIC?

mackrackit
- 24th October 2009, 18:09
Might be able to do what you want by counting. Keeping track of the last push...

But you will only have to count to one. The count VAR could start at 0. When the button is pushed...
IF COUNT VAR = 0 THEN
TX XYZ
COUNT VAR = 1
ELSE
IF COUNT VAR = 1 THEN
TX ZYX
COUNT VAR = 0

EEPROM may be required...

Something like that :)

financecatalyst
- 24th October 2009, 20:51
Might be able to do what you want by counting. Keeping track of the last push...

But you will only have to count to one. The count VAR could start at 0. When the button is pushed...
IF COUNT VAR = 0 THEN
TX XYZ
COUNT VAR = 1
ELSE
IF COUNT VAR = 1 THEN
TX ZYX
COUNT VAR = 0

EEPROM may be required...

Something like that :)

Thanks for the answer, but I am sorry I couldnīt get your point how this will help. Could you explain a bit more please.

mackrackit
- 24th October 2009, 21:26
Thanks for the answer, but I am sorry I couldnīt get your point how this will help. Could you explain a bit more please.
Well I miss read what you are wanting to do... If I am reading it all correctly now just have the receiver activate the relays only if there is a valid RF signal with the correct data coming in. If the data is not correct the relay stays off or goes off....

Sorry to confuse things... It is time for my nap...

BTW you is that in post #4?

financecatalyst
- 25th October 2009, 01:20
Well I miss read what you are wanting to do... If I am reading it all correctly now just have the receiver activate the relays only if there is a valid RF signal with the correct data coming in. If the data is not correct the relay stays off or goes off....

Sorry to confuse things... It is time for my nap...

That is correct. Sorry for the mixup in post #4, its two of us working on the same thing and using the same computer. Hope to find the solution soon to this problem.

Macgman2000
- 25th October 2009, 01:23
I did a design a while back where the TX needed to be completely off for max battery life. I used a n-channel FET and I/O pin to enable the pic to strap itself on while the tx button was pressed, once released the code saw the falling edge and transmitted the off data. After that the pic turned itself off.

financecatalyst
- 25th October 2009, 01:50
I did a design a while back where the TX needed to be completely off for max battery life. I used a n-channel FET and I/O pin to enable the pic to strap itself on while the tx button was pressed, once released the code saw the falling edge and transmitted the off data. After that the pic turned itself off.

In the circuit I have, the Transmitter module gets full 12V(via LR23 battery) and Tx gets 5V via 7805. The circuit only completes upon when button is pressed. Any sugesstion for making any change to the hardware part i.e. at the output pin of the Rx. I am having a feeling now that this problem cannot be solved via software!!

Macgman2000
- 25th October 2009, 02:38
Ok I am missing something......you posted a couple of posts ago the following....


Problem is that the Tx only gets power while the button is pressed once button is released, power is also removed from the pic. Is there any way I can achieve my goal using an capacitor or somthing at the output in the hardware as I dont seem to figure out an solution with software (Unless someone comes up with somthing I can try on my exsisting setup). I already tried using an 470uF at the output pin + replacing 1K wih an diode. I am having problem with timings now BUT flickering seems to have been absorbed by the capacitor. If possible any sugesstion about the cap values I can try to have instant responses by the receiver PIC?

So I came back with my design for a FET transistor supplying power as long as it takes to transmit an off command when you let go of the button. This should solve your issue. Especially since you have two different voltage sources, your N-channel FET would go between your common grounds, to essentially switch ground on or off. Just imagine it as a switch that cuts your circuit off at the ground side.

If you use a 100uF cap at the + side make sure that there is a resistor in parallel with the cap that will discharge it when the FET cuts off ground.

Nick

financecatalyst
- 25th October 2009, 10:38
hello Macgman200, can I please please request you to draw me a simple schematic for what you are saying. I am not very expert in this domain. Looks like you are talking a practical solution! Many thanks