November 23, 2024, 05:37:36 AM

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.


Traffic Light revisited

Started by peroberts, November 16, 2008, 05:28:35 PM

Previous topic - Next topic

peroberts

Is it possible to use a PIR motion detector, the Parallax PING Ultrasonic Range Finder, and the Prop-1 (or Prop-2) to control a traffic light (120VAC)? Would I want to use the RC-4 or separate relays for each of the three lights?

By way of example: an object would trigger the motion detector which would trigger the green light, then, when the object reached a distance of 7 meters, the green light would turn off and the orange light would turn on, and finally, at a distance of 1 meter, the orange light would turn off and the red light would turn on for 20 seconds and then turn off. And I would like to avoid re-triggering until, let's say, 60 seconds after the the red light turns off.

Moreover, what if the object moved backward? Could the light turn orange if greater than 1 meter, or green if greater than 7 meters?

Thanks for any help here.

JonnyMac

The Ping sensor is only good for 3 meters, so you cannot use that.  If you have a sensor that will work at the distances you suggest then we can assist with a program.
Jon McPhalen
EFX-TEK Hollywood Office

peroberts

What about the Devantech SRF08 range finder, which has a maximum range of 6m. The maximum distance is arbitrary. Let's say, using this range finder, the maximum distance I would use would be 5m.

JonnyMac

The Devantech SRF08 uses I2C which is not available on the Prop-1 and tricky to do on the Prop-2.
Jon McPhalen
EFX-TEK Hollywood Office

peroberts

This is information I found on the LV-Maxsonar-EZ1.

Runs on 2.5-5.5V

Three interfaces (all are active simultaneously):

     Serial output: asynchronous, logic-level, inverted, 9600 bps
     Analog output: (Vcc/512) / inch (10 mV/inch when input voltage Vcc = 5 V)
     Pulse width output: 147 us/inch

Possible?

JonnyMac

I suppose you could use the pulse-width output as the Prop-1 does have a PULSIN function (resolution is 10 microseconds). 
Jon McPhalen
EFX-TEK Hollywood Office

peroberts

Good. So how does the Parallax PIR, The LV-Maxsonar-EZ1, and the RC-4 sound? Workable? Or better yet, for the sake of practicality, how about limiting the initial distance to 3 meters, everything else being the same, and using the PING. The main goal of this project is to get a good grasp of how to set up this kind of programming, so working within the limitations of the range finder is fine. Thanks for your help.

JonnyMac

As soon as you settle on the parts you want to use and decide exactly how the program is to work, I'll happily bang it out for you -- it should be difficult at all, once I have a specification.  I don't know anything about the LV-Maxsonar-EZ1 so if you want to use that you'll need to get me a spec sheet.
Jon McPhalen
EFX-TEK Hollywood Office

peroberts

1. Parallax PIR
2. Maxbotix  LV-Maxsonar EZ1 sonar range finder
3. RC-4 relay control board
4. Traffic light (120VAC) with 3 standard 60w bulbs

All lights are off:

1. PIR detects movement, triggers green light
2. At 4 meters, range finder triggers:
   a. green light turns off
   b. orange light turns on
3. At 1 meter, range finder triggers:
  a. orange light turns off
  b. red light turns on, stays on for 20 seconds, then turns off.

PIR motion detector does not activate again until 60 seconds after red light turns off.

If substituting the PING, the distances are 3 meters and 1 meter respectively.

This is the link for the LV-Maxsonar-EZ1:
http://www.maxbotix.com/uploads/LV-MaxSonar-EZ1-Datasheet.pdf

JonnyMac

November 18, 2008, 11:07:13 AM #9 Last Edit: November 18, 2008, 11:11:29 AM by JonnyMac
Here you go.

' =========================================================================
'
'   File...... Peroberts_Traffic_Light.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 18 NOV 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN; PIR sensor
SYMBOL  Sonar           = 5                     ' LV-Maxsonar EZ1


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  lights          = B0
SYMBOL   Green          =  BIT0                 ' K1 on RC-4
SYMBOL   Yellow         =  BIT1                 ' K2 on RC-4
SYMBOL   Red            =  BIT2                 ' K3 on RC-4

SYMBOL  timer           = B2

SYMBOL  inches          = W4
SYMBOL  rawDist         = W5                    ' raw sonar measurement


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000000                              ' set outputs

  SEROUT Sio, Baud, ("!!!!!RC4", %00, "X")
  lights = %0000

  PAUSE 60000


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  Green = IsOn
  GOSUB Set_Lights

Green_Hold:
  GOSUB Get_Sonar
  IF inches > 157 THEN Green_Hold               ' 4 meters = 157 inches
    Green = IsOff
    Yellow = IsOn
    GOSUB Set_Lights

Yellow_Hold:
  GOSUB Get_Sonar
  IF inches > 39 THEN Yellow_Hold               ' 1 meter = 39 inches
    Yellow = IsOff
    Red = IsOn
    GOSUB Set_Lights

Red_Hold:
  PAUSE 20000                                   ' hold red for 20 seconds

  GOTO Reset                                    ' clear everything


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

Get_Sonar:
  PULSIN Sonar, 1, rawDist
  inches = rawDist * 10 / 147
  RETURN

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

Set_Lights:
  SEROUT Sio, Baud, ("!RC4", %00, "S", lights)
  RETURN


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

peroberts

Thanks Jon. I'll give it a try and let you know. Appreciate it!