November 21, 2024, 10:12:58 PM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Prop-1 Program using 2 PIRs and 2 Switches to control 110VAC motor movement

Started by tbelknap, April 26, 2015, 03:46:07 PM

Previous topic - Next topic

tbelknap

I have a ceiling mounted prop that can turn back and forth at a 150 degree radius.  In the past it ran continuously but now I would like it to turn and stop in the direction of the movement.  I have already attached two switches that are triggered when it turns right and one when it turns left.
I am hoping that the code I wrote below would allow the motor to rotate and stop in the direction of the triggered PIR sensor. 

Thank you for your help.  I am new and still trying to learn how to write a program.

Normally open switch (Left) connected to P7.W and P7.R
Normally open switch (Right) connected to P6.W and P6.R
PIR (Left) connected to P5
PIR (Right) connected to P4
Motor is connected to the EFX-TEK SSR-2 Solid State Relay

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

SYMBOL LeftSw = PIN7      'SETUP = DN
SYMBOL LeftPIR = PIN5
SYMBOL RightSw = PIN6         'SETUP = DN
SYMBOL RightPIR = PIN4
SYMBOL Motor = PIN1

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

SYMBOL IsOn = 1
SYMBOL IsOff = 0

SYMBOL Yes = 1
SYMBOL No = 0

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

SYMBOL PIRLeftTimer = B2
SYMBOL PIRRightTimer = B3
SYMBOL LeftSwTimer = B4
SYMBOL RightSwTimer = B5

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

Reset:
PINS = %00000000
DIRS = %00000010

PAUSE 2000

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

Main:
     Timer = 0

Check_Triggers:
     PAUSE 5                                       ' loop pad
     PIRLeftTimer = PIRLeftTimer + 5 * PIRLeftTimer                   ' update timer
     IF PIRLEftTimer = 100 THEN Run_LeftShow             ' wait for 0.1 sec input
     PIRRightTimer = PIRRightTimer + 5 * PIRRightTimer
     IF PIRRightTimer = 100 THEN Run_RightShow
     GOTO Check_Triggers

LeftShow:
     Motor = IsOn
     Check_LeftSw:
         PAUSE 5                                       ' loop pad
         LeftSwTimer = LeftSwTimer + 5 * LeftSwTimer                   ' update timer
         IF LeftSwTimer < 100 THEN Check_ LeftSw            ' wait for 0.1 sec input
      Motor = IsOff

GOTO Main

RightShow:
     Motor = IsOn
     Check_RightSw:
         PAUSE 5                                       ' loop pad
         RightSwTimer = RightSwTimer + 5 * RightSwTimer                   ' update timer
         IF RightSwTimer < 100 THEN Check_ LeftSw            ' wait for 0.1 sec input
      Motor = IsOff

GOTO Main

JonnyMac

You'll need a set of mechanical relays to reverse the motor -- that's what you want, right?
Jon McPhalen
EFX-TEK Hollywood Office

JackMan

Like Jon mentioned, you'll need a set of relays or an RC-2 for this wired like the diagram shows.
Here's an example of how the code will look.



' {$STAMP BS1}
' {$PBASIC 1.0}

' =========================================================================

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

SYMBOL LeftPIR    = PIN7      'SETUP = DN
SYMBOL RightPIR   = PIN6      'SETUP = DN
SYMBOL LeftSw     = PIN5
SYMBOL RightSw    = PIN4
SYMBOL LeftRelay  = PIN3
SYMBOL RightRelay = PIN2

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

SYMBOL IsOn  = 1
SYMBOL IsOff = 0

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

SYMBOL timer = B2               ' for debounce loop

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

Reset:
  PINS = %00000000                ' clear all outputs
  DIRS = %00001100                ' make P2-P3 outputs
  PAUSE 30000                     ' 30 second PIR warm up

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

Main:
  timer = 0

Check_LeftPIR:
  IF LeftSw = IsOn THEN Check_RightPIR
  PAUSE 5                                       ' scan delay
  IF LeftPIR = IsOff THEN Check_RightPIR        ' check left trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_LeftPIR             ' wait for .01 second trigger
  LeftRelay = IsOn
  PAUSE 1000                                    ' give motor 1 second to clear switch
  GOTO Move_Left

Check_RightPIR:
  IF RightSw = IsOn THEN Check_LeftPIR
  PAUSE 5                                       ' scan delay
  IF RightPIR = IsOff THEN Main                 ' check right trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_RightPIR            ' wait for .01 second trigger
  RightRelay = IsOn
  PAUSE 1000                                    ' give motor 1 second to clear switch
  GOTO Move_Right

Move_Left:
  timer = 0

Check_LeftSw:
  PAUSE 5                                       ' scan delay
  IF LeftSw = IsOff THEN Move_Left              ' check left switch input
    timer = timer + 5                           ' update timer
  IF timer < 50 THEN Check_LeftSw               ' wait for switch to close
  LeftRelay = IsOff
  GOTO Main

Move_Right:
  timer = 0

Check_RightSw:
  PAUSE 5                                       ' scan delay
  IF RightSw = IsOff THEN Move_Right            ' check right switch input
    timer = timer + 5                           ' update timer
  IF timer < 50 THEN Check_RightSw              ' wait for switch to close
  RightRelay = IsOff
  GOTO Main

JackMan

tbelknap,
     You asked for help but haven't responded, let us know.  8)

tbelknap

Sorry for the delayed response...
Program works great! I know this would have been easier with a stepper motor or servo but being able to set limit switches on any motor is opening up a lot of options.   

However, I did have a PIR sensor problem and I am wondering if you have any thoughts.  I extended the three pin cord (4ft.) and it stopped working... the only way I was able to get the sensor to work again was by keeping the cord short and moving it to another open PIN. 

As I am reading the PROP-1 section of this forum and learning a lot. I wish there was a more defined area where I could search through a list of troubleshooting or Dos and Don'ts.  I don't want to clog up the forum with simple questions like....

I have another prop-1 controller that doesn't light up in switch position 1 but does light the V+ in position 2.  That means it is dead right?

Best

JonnyMac

That means the 5v supply could be bad (or the LED could have been damaged). Is it new? If yes, please call our sales office so we can get you a replacement. If it's an older board, you can send it to us for repair. Again, call the sales office and John B will sort you out.
Jon McPhalen
EFX-TEK Hollywood Office

JackMan

Glad it worked for you, thanks for letting us know. As for the PIR not working after you extended the wiring, 4' should not have had any effect, are you sure your connections were correct? Did you use a pre-made extension or did you splice the wires? If that I/O PIN is no longer working it sounds like you may have possibly damaged something on the Prop-1.