Shop OBEX P1 Docs P2 Docs Learn Events
Sensor Not Working When Unplugged — Parallax Forums

Sensor Not Working When Unplugged

robomaniacrobomaniac Posts: 4
edited 2007-05-03 04:33 in BASIC Stamp
I'm using the BASICStamp homework board for a school project and I'm having a weird issue. When I run my program which reads a touch sensor made from a radioshack microswitch while the board is plugged in through the serial cable the touch sensor triggers fine, however, when I unplug the board and try to run the same program the touch sensor fails to trigger. Any other part of the program works fine while unplugged. What's going on?

' {$STAMP BS2}
' {$PBASIC 2.5}

touch_detect VAR Bit

DO
  touch_detect = IN2

  IF touch_detect = 1 THEN  'does not work fine unplugged
    HIGH 0
  ELSE
    LOW 0
  ENDIF

  PULSOUT 14, 150  'works fine unplugged
  PULSOUT 15, 750
LOOP

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-03 04:02
    How do you have the touch sensor connected? A microswitch has two terminals ... how are they connected?
  • robomaniacrobomaniac Posts: 4
    edited 2007-05-03 04:17
    The C port is connect to Vss and the NC port is connect to IN1. The touch sensor triggers fine when the board is plugged into the computer via the serial cable.
  • FranklinFranklin Posts: 4,747
    edited 2007-05-03 04:22
    If your switch is connected to IN1 and your program is testing IN2 it won't work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-03 04:23
    You need a pullup resistor from I/O pin 1 (pin 2?) to Vdd (+5V). Somehow, when the board is plugged in, there's enough voltage induced in the wire attached to the I/O pin that the switch will reliably trigger.

    A typical resistor is 4.7K to 10K.
  • robomaniacrobomaniac Posts: 4
    edited 2007-05-03 04:25
    so i put a wire from pin 1 to a row in the breadboard then put a resistor from Vdd to that row and then attach the in wire to that row also?
  • robomaniacrobomaniac Posts: 4
    edited 2007-05-03 04:30
    you sirs are a genious, it works perfectly now, thanks bunches!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-03 04:33
    Well, as Franklin pointed out, your program tests IN2 which is I/O pin 2 so I'm not sure where you've actually connected the switch. You connect a wire from that I/O pin to a row in the breadboard and another wire from that row to the switch. You connect a resistor (4.7K to 10K ... whatever you have available) from that row to Vdd. The other side of the switch still connects to Vss.

    What this does is to provide a high logic (+5V) level at all times except when the switch contacts are closed at which point you get a low logic (0V) level. Probably without the resistor you're getting induced 60 cycle voltage in the wiring when the switch contacts are open and that's enough to trigger the I/O pin (which is high impedance and sensitive to induced voltages).

    Genuses we're not ... We've just come across this problem before and either figured it out (typically with an oscilloscope) or had someone else tell us what to do.

    Post Edited (Mike Green) : 5/3/2007 4:38:50 AM GMT
Sign In or Register to comment.