PDA

View Full Version : microswitch mounting help



ltmhall
11-26-2006, 10:34 AM
I have just connected two micro-switches to my robot. Each switch
has a hinge , so when it pressed it sends a 0 to the micro-controller
to jump to a subroutine to manuver around an object. The problem
i have is when it collides into a object the switch is pressed, but it
doesn't manuver, instead the robot stays stuck on the object it
collided into. If any one has an ideas on how to mount them please
help.

TechnoRobbo
11-26-2006, 11:34 AM
Are you using a pulldown resistor? Or is this a programming question? If it's the latter please upload the code.

Other wise look at this diagram for help.
http://forums.parallax.com/attachment.php?attachmentid=44302
If you're not using a pulldown to get your "0" then you may be shorting your stamp to ground.
·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun


TR

Post Edited (TechnoRobbo) : 11/26/2006 4:39:08 AM GMT

ltmhall
11-26-2006, 09:38 PM
I have the same schematic built except I don't have the 220 ohm resistor connected. Could this be causing my problems.

This is my code. I used a microswitch and connected C to ground
and connected the NO pin to the 10 kohm.

DO
IF(IN15 = 0)THEN
GOSUB BACK:
GOSUB RIGHT:
ELSE
GOSUB FORWARD:
ENDIF
LOOP

'-----[SUBROUTINE]--------------

FORWARD:
PULSOUT 13, 850
PULSOUT 11, 650
PAUSE 20
RETURN

RIGHT:
FOR pulsecount = 1 TO 20
PULSOUT 13, 850
PULSOUT 11, 850
PAUSE 20
NEXT
RETURN

BACK:
FOR pulsecount= 1 TO 40
PULSOUT 13, 650
PULSOUT 11, 850
PAUSE 20
NEXT
RETURN

PJ Allen
11-26-2006, 10:08 PM
I always do switches as you see in the attached drawing.· It's good for HomeWork Board, BoE, N.O., N.C., toggle, any and all applications.

TechnoRobbo
11-26-2006, 10:53 PM
ltmhall (http://forums.parallax.com/member.php?u=47463)·said...
I have the same schematic built except I don't have the 220 ohm resistor connected. Could this be causing my problems.

First of all -I called the resistor a pull-down - it's actually a pull-up resistor, sorry.
It generates a high signal until you push the button which takes the pin low. PJ's shows a pull-down which keeps the circuit low until you push the button and brings the pin high.

According to your code - you want to use my circuit and keep the pin high (pull-up) until you push the button.
Either way it's just how you write the code·after you've wired it.


Itmhall said...
·I used a microswitch and connected C to ground
and connected the NO pin to the 10 kohm.
What is the Vdd connected to, (I'm assuming and hoping·it's also connected to Pin15 through the resistor)?· The 220 ohm will offer protection to the stamp if the pin gets switched to an output if this happens you'll have a short to ground. (Unless you have a home work board then your covered.)

Itmhall said...
I have just connected two micro-switches to my robot.
Did you connect them in parallel??? If they are in series one switch will cancel the other one out.
http://forums.parallax.com/attachment.php?attachmentid=44306
You should have bench tested·the input sequence using DEBUG. How did that work?


·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun


TR

Post Edited (TechnoRobbo) : 11/26/2006 4:18:01 PM GMT

PJ Allen
11-26-2006, 11:36 PM
I hasten to add that you need to Declare/Assign Pin15 as an Input somewhere at the beginning (i.e. INPUT 15.)· I think that PULSOUT automatically makes a Pin an Output, but using IF(IN15 = 0)THEN does not make the Pin an Input.

ltmhall
11-27-2006, 12:52 AM
I'm using the BOE and I a'm not using vdd. I have 4 AA batteries in series, which I use to connect to both my servo motors. Currently I'm connecting both switches to that supply, but i'm planing on changing that in the future. The circuit seems
to work fine but when it runs into an object the switches are pressed, and it if i move the object the robot collides into it, the
switches are depressed and it performs the manuver code written.

I'm not sure how to use the debug terminal to test it.

TechnoRobbo
11-27-2006, 03:08 AM
Could you post a diagram of how the switches are connected. Include all stamp connections and servos please.

Try adding the lines in red to your code:

INPUT 15 ' add this to save your stamp as PJ pointed out, I've screwed myself up before by not adding it.

DO
DEBUG HOME, IN15 ' use the terminal to monitor and·press the switches·to test your code
IF(IN15 = 0)THEN
GOSUB BACK:
GOSUB RIGHT:
ELSE
GOSUB FORWARD:
ENDIF
LOOP


You had me confused with press and depress - they mean the same thing.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun


TR

Chris Savage
11-27-2006, 03:16 AM
Just a quick thing...In the following lines, since there is no code/commands following the GOSUB no : (colon) is needed after the label.· The only time a line should end with a colon is if the line is a Label for a routine by itself, not when following a reference in a command.

GOSUB BACK:
GOSUB RIGHT:
ELSE
GOSUB FORWARD:


Should be:



GOSUB BACK
GOSUB RIGHT
ELSE
GOSUB FORWARD


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support

TechnoRobbo
11-27-2006, 05:33 AM
Oddly enough, I've observed that labels followed by colons·that don't start on column 1, and are·preceeded by a command, don't generate syntax errors and seem to be interpreted correctly .

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun


TR

Post Edited (TechnoRobbo) : 11/26/2006 11:33:54 PM GMT

Chris Savage
11-27-2006, 11:48 AM
TR,
·
·· That is correct since in that context the colon is used to allow more than one command per line.· The following is an example of where you would use the colon when not after a label…I hope this helps.· Take care.


LOW 0 : HIGH 1 : LOW 2 : HIGH 3

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support