Shop OBEX P1 Docs P2 Docs Learn Events
Proximity Switch and count Function — Parallax Forums

Proximity Switch and count Function

ArchiverArchiver Posts: 46,084
edited 2002-03-09 17:26 in General Discussion
I am trying to build a wind speed indicator and decided to use a
proximity switch and a Basic Stamp 2 to count the switch closures and
then calibrate the wind speed from the total count. The problem I am
having is I can not get a consistent reading from the proximity
switch. The readings are all over the map (From 0 sometimes up to 150)
as I try and trigger the prox. The code I am using is as follows:

'($StampBS2)
Speed Var Word
Again:
Count 1, 500, Speed
Debug CLS, Dec ?, Speed
Low 1
Goto Again

Note I had to add the Low 1 command to get any type of reading. Any
help would be appreaciated.
Thanks Loren

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-03-08 17:31
    The problem may be in the hardware hookup. If the proximity switch
    you refer to is a magnetic reed switch, it will tend to bounce a
    number of times as it closes and give you multiple counts where you
    expect only one. You can "debounce" it with a resistor and a
    capacitor:

    2.2k switch
    _
    +Vdd ----/\/\
    o o
    o---Vss common
    |
    1k |
    P0 ----o----/\/\
    o
    | |
    ===== 0.1 debounce |
    | |
    `
    '

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com



    >I am trying to build a wind speed indicator and decided to use a
    >proximity switch and a Basic Stamp 2 to count the switch closures and
    >then calibrate the wind speed from the total count. The problem I am
    >having is I can not get a consistent reading from the proximity
    >switch. The readings are all over the map (From 0 sometimes up to 150)
    >as I try and trigger the prox. The code I am using is as follows:
    >
    >'($StampBS2)
    >Speed Var Word
    >Again:
    >Count 1, 500, Speed
    >Debug CLS, Dec ?, Speed
    >Low 1
    >Goto Again
    >
    >Note I had to add the Low 1 command to get any type of reading. Any
    >help would be appreaciated.
    >Thanks Loren
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-08 17:36
    Might want to double check that schematic. I think the intention was to tap in
    on the high side of the switch, not on ground.

    Clark Hughes

    Tracy Allen wrote:
    >
    > The problem may be in the hardware hookup. If the proximity switch
    > you refer to is a magnetic reed switch, it will tend to bounce a
    > number of times as it closes and give you multiple counts where you
    > expect only one. You can "debounce" it with a resistor and a
    > capacitor:
    >
    > 2.2k switch
    > _
    > +Vdd ----/\/\
    o o
    o---Vss common
    > |
    > 1k |
    > P0 ----o----/\/\
    o
    > | |
    > ===== 0.1 debounce |
    > | |
    > `
    '
    >
    > -- regards,
    > Tracy Allen
    > electronically monitored ecosystems
    > mailto:tracy@e...
    > http://www.emesystems.com
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-08 19:35
    >Might want to double check that schematic. I think the intention
    >was to tap in on the high side of the switch, not on ground.
    >Clark Hughes

    Hi Clark, You're absolutely right. Here it is, moved over:

    2.2k switch
    _
    +Vdd ----/\/\--o---o o
    o---Vss common
    |
    1k |
    P0 ----o----/\/\
    o
    | |
    ===== 0.1 |
    | |
    `
    '
    Too early in the morning. A professor I worked with told us always
    to sneak an obvious error onto the blackboard at the beginning of a
    lecture. There was bound to be somebody who would speak up about it,
    and wake everyone up and open up discussion. If not, assume everyone
    is already asleep!

    -- Tracy

    >
    >
    >Tracy Allen wrote:
    >>
    >> The problem may be in the hardware hookup. If the proximity switch
    >> you refer to is a magnetic reed switch, it will tend to bounce a
    >> number of times as it closes and give you multiple counts where you
    >> expect only one. You can "debounce" it with a resistor and a
    >> capacitor:
    >>
    >
    > > 2.2k switch
    >> _
    >> +Vdd ----/\/\
    o o
    o---Vss common
    >> |
    >> 1k |
    >> P0 ----o----/\/\
    o
    >> | |
    >> ===== 0.1 debounce |
    >> | |
    >> `
    '
    > >
    >> -- regards,
    >> Tracy Allen
    >> electronically monitored ecosystems
    >> mailto:tracy@e...
    > > http://www.emesystems.com
    >>
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-08 21:28
    Hi Tracy, I am not understanding your schematic. I have three leads
    coming from the prox switch. Power, ground, and the load, where do I
    put the resistor and the capacitor.

    Thanks Loren

    --- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
    > >Might want to double check that schematic. I think the intention
    > >was to tap in on the high side of the switch, not on ground.
    > >Clark Hughes
    >
    > Hi Clark, You're absolutely right. Here it is, moved over:
    >
    > 2.2k switch
    > _
    > +Vdd ----/\/\--o---o o
    o---Vss common
    > |
    > 1k |
    > P0 ----o----/\/\
    o
    > | |
    > ===== 0.1 |
    > | |
    > `
    '
    > Too early in the morning. A professor I worked with told us always
    > to sneak an obvious error onto the blackboard at the beginning of a
    > lecture. There was bound to be somebody who would speak up about
    it,
    > and wake everyone up and open up discussion. If not, assume
    everyone
    > is already asleep!
    >
    > -- Tracy
    >
    > >
    > >
    > >Tracy Allen wrote:
    > >>
    > >> The problem may be in the hardware hookup. If the proximity
    switch
    > >> you refer to is a magnetic reed switch, it will tend to bounce a
    > >> number of times as it closes and give you multiple counts where
    you
    > >> expect only one. You can "debounce" it with a resistor and a
    > >> capacitor:
    > >>
    > >
    > > > 2.2k switch
    > >> _
    > >> +Vdd ----/\/\
    o o
    o---Vss common
    > >> |
    > >> 1k |
    > >> P0 ----o----/\/\
    o
    > >> | |
    > >> ===== 0.1 debounce |
    > >> | |
    > >> `
    '
    > > >
    > >> -- regards,
    > >> Tracy Allen
    > >> electronically monitored ecosystems
    > >> mailto:tracy@e...
    > > > http://www.emesystems.com
    > >>
    > >
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-08 21:57
    >Hi Tracy, I am not understanding your schematic. I have three leads
    >coming from the prox switch. Power, ground, and the load, where do I
    >put the resistor and the capacitor.


    Okay, it is not a reed relay. What part number is the prox switch?
    Does it need a pull-up or pull-down resistor?
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-09 02:26
    Sounds like an inductive or capacitive proximity
    sensor.

    If it is....
    They usually come in four variants - PNP & NPN
    ....and Normally Open or Normally Closed.
    On an NPN you put the load between load and power.
    PNP types between load and ground.

    How many volts are you applying to its power
    lead?. The ones I use (for wheel speed sensing
    take between 10 & 35 volts DC). They work down to
    8(ish) volts, but no lower.

    Hope that helps
    Les Otter

    >
    Original Message
    > From: Tracy Allen [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=PVbX1ytg2vfEyJEU6u434kRnN5gzImUAFW9D8HlQVri7x3ChaE6qu26orlmLHmdENryeMOKmVeQaviFosew]tracy@e...[/url
    > Sent: 08 March 2002 21:58
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Re: Proximity
    > Switch and count Function
    >
    >
    > >Hi Tracy, I am not understanding your
    > schematic. I have three leads
    > >coming from the prox switch. Power,
    > ground, and the load, where do I
    > >put the resistor and the capacitor.
    >
    >
    > Okay, it is not a reed relay. What
    > part number is the prox switch?
    > Does it need a pull-up or pull-down resistor?
    >
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you
    > subscribed. Text in the Subject and
    > Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-09 12:27
    --- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
    > >Hi Tracy, I am not understanding your schematic. I have three
    leads
    > >coming from the prox switch. Power, ground, and the load, where do
    I
    > >put the resistor and the capacitor.
    >
    >
    > Okay, it is not a reed relay. What part number is the prox switch?
    > Does it need a pull-up or pull-down resistor?

    Tracy, I am using a Allen bradley Prox # 871C-D2NP8 - E2 A and
    presently not using a pull-up pull-down resistor.

    Loren
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-09 14:58
    Hi,

    Normally, you should use a load resistor. The output device of the sensor is
    often a transistor with an open collector connexion. You need to supply this
    collector via a resistor. If it's a PNP output, you must connect a resistor
    between output and negative side of the power supply. If it's a NPN, the
    resistor must be between output and positive side of the power supply. If
    you omit the resistor, the output is like floating, and the Stamp input is
    not properly driven, giving erratic measures.

    Best regards,

    Phil.


    > Tracy, I am using a Allen bradley Prox # 871C-D2NP8 - E2 A and
    > presently not using a pull-up pull-down resistor.
    >
    > Loren
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-09 17:26
    The resistor to ground did the trick!
    Thanks for the help.

    Loren

    --- In basicstamps@y..., "Derenne Philippe" <derennep@s...> wrote:
    > Hi,
    >
    > Normally, you should use a load resistor. The output device of the
    sensor is
    > often a transistor with an open collector connexion. You need to
    supply this
    > collector via a resistor. If it's a PNP output, you must connect a
    resistor
    > between output and negative side of the power supply. If it's a
    NPN, the
    > resistor must be between output and positive side of the power
    supply. If
    > you omit the resistor, the output is like floating, and the Stamp
    input is
    > not properly driven, giving erratic measures.
    >
    > Best regards,
    >
    > Phil.
    >
    >
    > > Tracy, I am using a Allen bradley Prox # 871C-D2NP8 - E2 A and
    > > presently not using a pull-up pull-down resistor.
    > >
    > > Loren
Sign In or Register to comment.