November 22, 2024, 07:00:52 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.


help needed with shaking cellar door code.

Started by meshouse, August 29, 2008, 03:03:44 PM

Previous topic - Next topic

meshouse

August 29, 2008, 03:03:44 PM Last Edit: August 29, 2008, 08:26:51 PM by meshouse
I am new to programming and working with the Basic stamp interface.  I am trying to create a shaking/banging cellar door prop (2 identical doors side by side) that will do the following:
 
  Wait for motion sensor (Parallax Wide Angle IR)
  Pause 4 seconds to allow victim to approach the props
  Trigger red lights in cellar doors to produce a hellish glow
  Pause random seconds
  Start random solenoid shaking effect
  Reset (20 second count before reset takes place)

Issue:
Much of the code I have thus far I have either battled through or borrowed and is not yet complete.  Can any of you experienced code mavins take a look at it for me and explain what I am missing for this to work.

Questions:
1.  I will have two identical cellar doors doing the same thing, each door has one cylinder, the two cylinders (one from each door) wil be powered by one master air valve.  The air cylinders are dual action.  Does a dual action cylinder need to be hooked-up differently than a single action cylinder to a prop-1 (example using another out for reversing the direction of the cylinder)?
2.  what is the best way to hook up a (2) 60 watt lights (the red lights refered to in the code sequence) to the prop-1?

Any help that you can provide would be greatly appreciated.

Thanks,
Mike

Thus far this is what I have:

' {$STAMP BS1}
' {$PBASIC 1.0}
' shaking Cellar Doors
'
'  Wait for motion detector
'  Pause 4 seconds to allow visitor to approach cellar doors
'  Trigger red light
'  Pause (random) seconds
'  Start random solenoid door-shaking (for 15 seconds)
'  Reset
'
' -----[ I/O Definitions ]-------------------------------------------
SYMBOL PIR=PIN7                        ' P7   = Parralax Infrared sensor
SYMBOL VALVE=1                         ' Out1 = Cellar Doors Cylinder
                                                    ' black wire to Gnd, red wire to Out1 terminal
SYMBOL Rlight=3                          ' Out3 = Red Light
                                                     ' black wire to GND, red wire to Out3 terminal
SYMBOL COUNTER=W4
SYMBOL TriggerDelay=0                ' delay between motion detected and start
SYMBOL IdleTime=20000              ' delay between reactivations
SYMBOL  lottery                  = W0  ' random number
SYMBOL  tix                        = W1  ' timer
SYMBOL  shakeTime           = W2  ' time for shaking
SYMBOL  shakeAcc             = W3  ' shake accumulator
' -----[ Initialization ]--------------------------------------------
DEBUG CLS                                   ' Clear DEBUG Screen
FOR counter = 20 TO 0 STEP -1    ' Wait 20 Seconds For PIR Warm-Up
DEBUG 'IR Ready in:', counter       ' Print how much time left
PAUSE 1000                                  ' Display Counter Every Second
DEBUG CLS                                    ' Clear DEBUG Screen
NEXT
lottery = 1031                               ' Seed random generator
counter = 0                                   ' Clear Counter Variable
DEBUG "WAITING FOR VICTIM..."  ' Display Waiting Message
' -----[ Program Code ]-----------------------------------------
WaitForMotion:
    RANDOM lottery                                ' toss random generator
    LOW VALVE
    PAUSE 25
    counter = counter + PIR*PIR
    IF counter<20 THEN WaitForMotion  ' Motion Detected?
    DEBUG 'TRIPPED...'
    counter =0
PropSequence:
' motion detected, wait 'triggerdelay' seconds before shaking doors
    PAUSE triggerdelay
    DEBUG "Red Light Starts"
    SEROUT Rlight
    DEBUG 'Start Shaking'
Pre_Shake_Delay:
  tix = lottery // 31 + 20                                              ' delay 2 to 5 seconds
  GOSUB Run_Timer
  shakeTime = lottery // 200 + 10                                ' shake 1 to 20 secs
  shakeAcc = 0                                                             ' clear accumulator
Shake_Cellar Doors:
  RANDOM lottery                                                         ' toss random generator
  TOGGLE VALVE                                                           ' toggle cylinder control
  DEBUG 'Cellar Door Toggle', CR
  tix = lottery // 5 + 1                                                    ' piston move, 0.1 to 1.5 secs
  shakeAcc = shakeAcc + tix                                          ' update accumulator
  GOSUB Run_Timer
  IF shakeAcc < shakeTime THEN Shake_Cellar Doors   ' done shaking?
    DEBUG 'Stop shaking'
    LOW VALVE
    PAUSE idletime
    DEBUG 'Resetting'
GOTO WaitForMotion
' -----[ Subroutines ]-----------------------------------------------------
' Pass timing units (0.1 sec) in 'tix'
' -- 'tix' is destroyed by routine
Run_Timer:
  IF tix = 0 THEN Timer_Exit                    ' expired?
    PAUSE 100                                         '   no, pause
    tix = tix - 1                                         '   and decrement
    GOTO Run_Timer                               ' test again
Timer_Exit:
  RETURN


As mentioned can anyone help me out on what is missing and rid this code of some bugs??
greatly appreciated thanks,

Mike

Jadams

Hi Mike,

I'm a beginner myself.  I think you should check the wiring of the solenoid valves.  The red wire should go to V+ and the black wire should go to Outx.

Hope this helps.
Jim Adams

JonnyMac

Here's a cleaned-up and simplified version of your program.  Note that I moved the PIR to P6 -- this is what we use as a standard to leave P7 open for serial comms if that ever becomes necessary.   You didn't specify the delay after the red light comes on so I set to one to three seconds (random).

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
'  Wait for motion detector
'  Pause 4 seconds to allow visitor to approach cellar doors
'  Trigger red light
'  Pause (random) seconds
'  Start random solenoid door-shaking (for 15 seconds)
'  Reset


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  RedLight        = PIN3
SYMBOL  Valve           = PIN1


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

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400

SYMBOL  TriggerDelay    = 4000


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

SYMBOL  timer           = B2                    ' debounce timer
SYMBOL  tix             = B3                    ' for delays (0.1 secs)

SYMBOL  shakeAcc        = W3
SYMBOL  shakeTime       = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00001010                              ' make P1 & P3 outputs

  PAUSE 20000                                   ' PIR warm-up / delay


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

Main:
  timer = 0                                     ' reset timer

Check_PIR:
  RANDOM lottery                                ' stir random value
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * PIR                       ' update timer
  IF timer < 250 THEN Check_PIR                 ' wait for 0.25 sec input

Prop_Sequence:
  PAUSE TriggerDelay
  RedLight = IsOn

Pre_Shake_Delay:
  tix = lottery // 21 + 10                      ' 1 to 3 seconds
  GOSUB Run_Timer

  RANDOM lottery
  shakeTime = lottery // 51 + 100               ' 10 to 15 seconds
  shakeAcc = 0

Shake_Cellar_Doors:
  RANDOM lottery
  Valve = 1 - Valve                             ' toggle valve output
  tix = lottery // 6 + 1                        ' 0.1 to 0.5 secs
  shakeAcc = shakeAcc + tix
  GOSUB Run_Timer
  IF shakeAcc < shakeTime THEN Shake_Cellar_Doors

  GOTO Reset                                    ' reset everything


' -----[ Subroutines ]-----------------------------------------------------

' Pass timing units (0.1 sec) in 'tix'
' -- 'tix' is destroyed by routine

Run_Timer:
  IF tix = 0 THEN Timer_Exit                    ' expired?
    PAUSE 100                                   '   no, pause
    tix = tix - 1                               '   and decrement
    GOTO Run_Timer                              ' test again

Timer_Exit:
  RETURN

' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

meshouse

August 30, 2008, 10:07:08 AM #3 Last Edit: August 30, 2008, 10:11:14 AM by meshouse
I noticed that you used PIN3 for the valve.  When do you use the "out 1-7" vs the "P 1-7"?  I was under the assumption that the valve that I am using will have to be connected to the V+ and an "out" port.  Can you shed a little light on this for me?  Or point me in the direction of a topic or manual that can?

Thanks for being patient with me.

livinlowe

http://www.efx-tek.com/php/smf/index.php?topic=265.0

Check out this post. It should clarify the confusion. And don't worry - we all had questions when we first started (some like me still do!   :D  )
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

Px pins will power LEDs, like on the Prop-1 Trainer; to control valves you make that connection to the associated OUTx pin and put the power switch into position 2.  It would be a good idea to review the Prop-1 documentation as well.
Jon McPhalen
EFX-TEK Hollywood Office

meshouse

August 30, 2008, 08:13:06 PM #6 Last Edit: August 30, 2008, 08:26:02 PM by meshouse
What is the best way to hook up a 60W flood light (in this case the red lights inside each cellar door) to the prop-1? I assume that it is the same in any case that a device would not be using the same 12V power that is provided through the prop-1. 
From reading other posts I assume that the RC-4 is what is needed unless a series of 12V LEDS are used.  In the case of using the RC-4, does this change the code that is being utilized according to JonnyMac's reccomendations?


Mike

menehune

August 30, 2008, 10:24:00 PM #7 Last Edit: August 30, 2008, 10:28:04 PM by menehune
You could use a FC4 (dimmable) or an RC4 (if you only want on/off) to control 120vac flood lights.  The RC4 can take it's power from the V+ and V- terminals on the green screw terminals.  You will still need to wire the 120vac power  for the lights to the "output" of the RC4 and wire up the light sockets.

If you have a small prop, you could use some "lazer" computer led case lights and drive them off the OUTx terminals of the prop.  The "lazer" lights run off 12vdc.

You would have to modify the code to talk to the RC4 via the serial port.  The prop basically tells the RC4 which channel to turn on/off and the prop can then continue on with the rest of the program.

JonnyMac

You could also use a relay connected to your Prop-1 to switch the flood light.  If you do, the code is ready to go.  If you want to use an RC-4 then the code will need to be updated.
Jon McPhalen
EFX-TEK Hollywood Office

meshouse

sorry to dig further but can you shed more light on what a relay is and how it works?

JonnyMac

Relays are very common; what you want is a coil voltage of 12 and coil wattage of 3 watts or less.  Once side of the coil will connect to V+, the other to the OUTx terminal assigned to control it.  You will use the relay's normally-open contacts to switch the electricity for the lamp.  Here's an inexpensive relay that will work:

http://www.allelectronics.com/make-a-store/item/4PRLY-12/RELAY-4PDT-12VDC-KH-STYLE/-/1.html

Now... let me suggest that if you don't know about relays you should get some help making connections -- if you make a mistake you could damage something and we don't want that.  Working with 120 VAC is not trivial, it can bite you very hard (ask me how I know....); please don't take chances with your safety over a Halloween prop.
Jon McPhalen
EFX-TEK Hollywood Office

livinlowe

If you haven't ever "hacked" with 120 V, may I recommend you purchase a RC-4. I personally have two of these great boards and at $30 + $10 per relay, I think its worth it to not have to worry about soldering 120V lines to a relay. Just my opinion; they also make your prop look alot more professional.
Shawn
Scaring someone with a prop you built -- priceless!