May 03, 2024, 10:46:39 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Serial controlled relay

Started by aquawilly54, September 05, 2018, 09:24:14 PM

Previous topic - Next topic

aquawilly54

Another question folks.  I want to run an external relay from P7 to control a 700W fogger, that supposedly could draw 5.8 amps.  The relay is a Tongling JQC-3FF-S-Z.  It has the pins for serial input, and screw terminals for output.  I thought about using an RC-2 relay, but it might not support the amps.  Anyhow, I'm not able to figure it out.  I'm playing with a program that is not true.  It's for an AP-16+ application.  Obviously it won't work, but I've been substituting commands here and there, only to get a split second activation from the relay.  I have to ask for help on what commands to input, so I'm attaching the program I've been playing with.  Again; I know it's wrong, but it's a working program and I try to build on what I have.

I couldn't get it to load as an attachment.  My apologies.
Thanks for looking.

Steve

       ' =========================================================================
'
'   File......          Screaming Fred II
'   Purpose...       Lunging and screaming
'   Author....       Steve ( Help from Jon)
'   E-mail....
'   Started...      10/01/2017
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------



' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio                = 7                     ' SETUP = UP
SYMBOL  Trigger          = PIN6                  ' SETUP = DN
SYMBOL  Cylinder         = PIN1                  ' activate air cylinder


' -----[ Constants ]-------------------------------------------------------

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400


' -----[ Variables ]-------------------------------------------------------

SYMBOL  status          = B0                    ' status (B0 for bit access)
SYMBOL   playing        = BIT7                  ' 0 = idle, 1 = playing

SYMBOL  timer           = B2                    ' for debounce loop


' -----[ Initialization ]--------------------------------------------------

Power_Up:
  PAUSE 3000                                    ' let AP-16+ initialize

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P5..P0 are outputs

  PAUSE 20000                                   ' PIR warm-up/delay


' -----[ Program Code ]----------------------------------------------------

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                                    ' scan delay
  IF Trigger = TrOff THEN Main                      ' check trigger input
    timer = timer + 5                                     ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

   SEROUT Sio, Baud, ("!AP16", %00, "P?", 2, 1) ' randomize SFX00..SFX03

  Cylinder = IsOn                               ' activate cylinder

Audio_Wait:
  PAUSE 50
  SEROUT Sio, Baud, ("!AP16", %00, "G")         ' request status
  SERIN  Sio, Baud, status                               ' get it from AP-16+
  IF playing = Yes THEN Audio_Wait                 ' check playing bit
    GOTO Reset




Jeff Haas

Steve, can you provide a link to info on the relay itself?  Ideally the datasheet (instructions), which should have info on how to activate it.

You are using the serial commands for the AP-16+, (these are all of the lines that start with SEROUT) which need to be updated to communicate with other devices.

Jeff

aquawilly54

Ideally the datasheet (instructions), which should have info on how to activate it.
       
       Ideally; yes, but nothing was supplied.  Using the "WRONG CODE"  SEROUT and changing the time to 5 seconds allows the relay to flash once, then flash again at the end of 5 seconds whether I'm using DC, or AC external power.

You are using the serial commands for the AP-16+, (these are all of the lines that start with SEROUT) which need to be updated to communicate with other devices.

         EXACTLY.  I don't know what commands to put in.  This is where I need help.
I was able to attach a picture of it, but that's all I got.  Just for gee whiz, I had to change the serial wires, so I do have the white on "in", the black on "grd", and the red on "vcc". 

Thanks much

Steve

Jeff Haas

Ok, this is an easy one.  That's a typical common relay module.  It's not controlled by serial commands, instead you control it like an LED, and you set the relay to HIGH to turn it on, and LOW to turn it off (you can see that at the top of the code with the IsOn and IsOff definitions). 

Use 3 wires to connect from Pin 1 on the Prop 1 like this (Prop 1 connections on the left, relay on the right):

R - VCC
B - GND
W - IN

What happens is that the relay turns on with "Cylinder = IsOn" and then the code goes down to the Audio_Wait section.  There is a brief pause in that part, the AP-16 reports its status, and if the audio file is still playing, then the program loops back to the top of Audio_Wait, pauses for a brief time, then the program checks to see if the audio is still playing, repeating over and over...eventually the audio is done, the AP-16 reports that's it's over, and the program resets - which is when your relay turns off, lowering the prop.

So you need to have both the AP-16 and the relay hooked up for this to work.  You also need to have a few sound files on the memory card on the AP-16 so it can play one of them.  The program is set up to randomly pick one of the files and play it.  No files to play means that the AP-16 will report that it's not playing!

aquawilly54

Hi Jeff.
  Just saw this after posting a new plea.  I can't seem to use Pins 0 thru 5, because they (for some reason) are constantly powered.  As soon as I hit the switch everything is on.  The second problem is I don't want to use the AP.  That code I put in the first post was completely wrong for my application.  I was only using it as at test bed to see if I could make it work on the bench.  I just don't know the proper commands to use for a simple relay. 

I do appreciate the help.  Check out the post "new approach" if you have some time to spare. 

Thanks again.

Steve

JonnyMac

QuoteI do appreciate the help.  Check out the post "new approach" if you have some time to spare.
Please, please, please... don't break up you requests for help into separate threads -- this makes things very difficult to follow for those who may come in late and not read the the first thread first.
Jon McPhalen
EFX-TEK Hollywood Office

aquawilly54

Understood Jon.  I apologize.
 
     Specifically what I wanted to do was create a program to operate a relay from header pin P7 for a fogger.  The fogger is 700W which I figured is between 5 and 6 amps.  Too much for the AP-16+ relay.

     The relay itself uses serial connector pins for input as the picture shows in the above post, so that's why I thought I would be able to learn a new coding trick and use P7 to operate it.  I was not going to use P7 for audio. 

     The perfect scenario would be to use audio and the on board relay, but I think the fogger amps are too high.

     Also P0 through P5 (header pins) are constantly powered weather I change them to 1s or 0s, so I can't use those for relay operation, unless I'm missing something, which is more than possible.  I thought the documentation referenced them as outputs, but I'll have to look again. 


    Since these postings I went ahead and modified a serial cable to be used through the OUT screw terminals.  It works fine; just not as clean as I was expecting.

Thanks for looking.  I won't split posts up again.


Steve