Shop OBEX P1 Docs P2 Docs Learn Events
LOW switch — Parallax Forums

LOW switch

ice-egozice-egoz Posts: 55
edited 2004-09-23 16:46 in BASIC Stamp
Hi.. I want assign the pin to be LOW. SO when the pin becomes HIGH, then carry on the next step.


LOW switch ' does this assign the pin to be low?

IF NOT switch THEN start······· 'over here: IF the switch is on, it becomes a HIGH and den goes to start..
········································· 'but then it is not supposed to go to start if the switch is not ON yet.
start:
...

We have made a switch and used a jumper wire to put at pin 12 of the BS2p.
The switch looks like in the pic.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I need all ya guidance Masters. [noparse]:)[/noparse]
959 x 628 - 14K

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-21 02:32
    LOW makes the pin an output -- so you don't want to use it.· What you want to do is make the pin an input (the Stamp does this by default), then use a pull-up on the pin to hold the input high until the button is pressed.· The attached schematic shows the proper connections.· Don't leave out the 220 ohm resistor -- it will save the BASIC Stamp pin if you make a programming error.

    Here's a quick test you can run, using P12 as the input:

    Main: 
      DEBUG HOME 
      IF (IN12 = 0) THEN 
        DEBUG "Pressed", CLREOL 
      ELSE 
        DEBUG "Not Pressed", CLREOL 
      ENDIF 
      PAUSE 100 
      GOTO Main
    


    BTW ... these a very basic input circuits and fully covered in our "What's A Microcontroller?" textbook.· You can download it for free.· You really should.

    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 9/21/2004 2:36:02 AM GMT
    290 x 284 - 10K
  • ice-egozice-egoz Posts: 55
    edited 2004-09-21 03:29
    what's a pull-up on a pin?
    And our switch is not a push button.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I need all ya guidance Masters. [noparse]:)[/noparse]
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-21 03:31
    A pull-up "pulls" the connected IO pin to Vdd; typically a 10K resistor is used. This keeps the pin at a known state (1) until the button (or switch -- both work) connected to ground is pressed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • ice-egozice-egoz Posts: 55
    edited 2004-09-21 03:38
    so i don need to assign the pin as high? As u mentioned, the switch is Input. That is correct. So i need a wire from the switch to ground? I only have 1 wire.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I need all ya guidance Masters. [noparse]:)[/noparse]
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-21 03:44
    No, do not use HIGH or LOW -- that will make the pin an output and depending on how you connect the switch, could lead to damage.· I promise, if you connect the circuit shown above, it will work.· If you don't trust me, find a friend who understands electronics and that friend will confirm that I'm telling you the truth.·smile.gif

    In fact, just to be safe, I want you to do this in your code:

    Setup: 
      INPUT 12 
    
    Main: 
      DEBUG HOME 
      IF (IN12 = 0) THEN
        DEBUG "The switch is closed.", CLREOL 
      ELSE 
        DEBUG "The switch is open.", CLREOL 
      ENDIF 
      PAUSE 100 
      GOTO Main
    


    The INPUT instruction will guarantee the P12 is an input and you won't have any problems.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • ice-egozice-egoz Posts: 55
    edited 2004-09-21 03:46
    so how many wires shud I have??

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I need all ya guidance Masters. [noparse]:)[/noparse]
  • ice-egozice-egoz Posts: 55
    edited 2004-09-21 04:12
    did u look at my circuit?
    The switch is such that, when i On it, it will sound the buzzer and the LED is ON also.
    How do I figure this out?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I need all ya guidance Masters. [noparse]:)[/noparse]
  • ice-egozice-egoz Posts: 55
    edited 2004-09-21 04:24
    the above u mentioned is to be done on the breadboard? cos the alarm we have made is a separate box.

    the buzzer needs 12V. One wire just needs to touch any wire in the alarm circuit and it will be able to ON the alarm. And i want to automatically switch off the alarm without moving the switch. can it be done?

    when it is time to OFF the switch:
    LOW alarm ' is this able to oFF the switch?

    the alarm has a switch, LED, buzzer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I need all ya guidance Masters. [noparse]:)[/noparse]
  • Ken GraceyKen Gracey Posts: 7,387
    edited 2004-09-21 05:01
    Ice-egoz,

    As Jon mentioned, you need to download the What's a Microcontroller? text from our web site. This text covers your exact question in detail. There's a picture of the circuit and a schematic. The picture shows you where the jumper wire goes, where to put the resistor, and how to place the pushbutton switch across the breadboard.

    It couldn't be easier for you - all you need to do is look in the What's a Microcontroller? text for some fantastic, well-designed examples using switches (or pushbuttons).

    Please take a look at this book. Within 10 minutes you should find the example and put it to use. If you don't have 10 minutes to do this then your future learning the BASIC Stamp is in jeopardy.

    Ken Gracey
    Parallax, Inc.
  • ice-egozice-egoz Posts: 55
    edited 2004-09-21 05:04
    Hi. I am looking at the book. Just that I cant finish reading it now.. SO i am continually asking for questions. Im sorry if im causing troubles.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I need all ya guidance Masters. [noparse]:)[/noparse]
  • ionion Posts: 101
    edited 2004-09-21 05:12
    Ice-egoz,
    I follow the tread for the switch and I think the initial concept is wrong.
    From what you describe , you want to have a switch , acting as an INPUT to the stamp,
    and have the stamp to turn on an OUTPUT which will drive your buzzer and led. After a preset time , you want to turn the buzzer and led off without any intervention from your part. What you forgot to mention are few facts.
    Is the contact on the switch permanent, or just a momentary closure ?
    What you do , is after your preset time, the switch is still closed?
    Are you keeping the alarm on or turn it off ?
    Next point is your two voltages and currents.
    Stamps work on 5Vdc, the buzzer as mentioned is 12 Vdc, and the LED usually is 1.2 Vdc. For currents point of view, you can not put in series the led with the buzzer because the buzzer it might not work on the 0.02 A which flows through your LED.
    You must put them in parallel. For the LED you need a 510 Homs at ¼-watt resistor in series with it to make it works at 12 Vdc.
    To save yourself some pins, you can use a 2222 transistor to drive a small relay and use the contacts to drive the 12VDC for buzzer and led. You can also use a line driver like ULN2003 chip and drive the buzzer from one pin and the led from other pin. But, if it is a mechanical buzzer , the relay works better.
    Program side, use Jon’s advice to download the book from Parallax, and as a bonus use his portion of code as start. It is already half of your program there.
    Good luck
    Ion
  • ice-egozice-egoz Posts: 55
    edited 2004-09-21 06:18
    hi... yes I had the 10 minutes, Thank you. I also had some help from some1 in the forum. Thank you for ya help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I need all ya guidance Masters. [noparse]:)[/noparse]
  • Jim ForkinJim Forkin Posts: 5
    edited 2004-09-23 16:46
    On the image you posted, the LED is installed backwards and a resistor is necessary to limit the current. I think everyone answered the programming issues already.

    Jim
Sign In or Register to comment.