Shop OBEX P1 Docs P2 Docs Learn Events
Control of motors with sensors - Need help!!! — Parallax Forums

Control of motors with sensors - Need help!!!

CentryCentry Posts: 4
edited 2013-02-18 11:58 in BASIC Stamp
Hello,
I'm a german student and i need help on a project I'm doing in school. First, I apologize for my bad English, but I hope I still get quick help. I'd like to control 2 motors via sensors (2 LDRs). For that I use the BS1 and a Basic STAMP1 interface where I connect the two motors and the 2 LDRs. I want to send a signal to the motor when the first sensor lose his resistance. The BS1 should always check the status of the sensor.

(I'm new so I do not even know if that can work ... So if not, it would be good if you could explain it to me in simple words)

Here is my code:
' {$STAMP BS1}
OUTPUT 0
OUTPUT 1
INPUT 6


MP:
POT 6, 90, B0
IF B0>90 THEN MOTORSTART
IF B0<90 THEN MOTORAUS
MOTORSTART:

PIN0=1
IF PIN0=1 THEN ANFANG
MOTORAUS:

PIN0=0
IF PIN0=0 THEN ANFANG
ANFANG:

IF B0>90 THEN MOTORSTART
IF B0<90 THEN MOTORAUS
GOTO MP

END


I hope you can help me!
DSC_0119[1].jpg
1024 x 576 - 53K

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-02-03 07:24
    Why do you test IF PIN0=1 and IF PIN0=0? Isn't pin 0 an output?

    Usually the way people would learn how to do this is to first write a program that would read the LDR value with POT and display the value using DEBUG. Next step would be to add the IF statements for B0 and use DEBUG again to tell you Start or Stop. Next step would be to write a separate program that starts the motor, pauses for 5000 milliseconds, then stops the motor, pauses for 5000 milliseconds, then repeats. Last step would be to take the first program and add the motor start and stop statements and test it out.

    Remember that a BS1 I/O pin can only provide about 20mA, usually not enough to drive a motor. Look at Nuts and Volts Column #6 for a discussion of this.
  • CentryCentry Posts: 4
    edited 2013-02-03 10:46
    Thank you that will help me for sure :)
  • CentryCentry Posts: 4
    edited 2013-02-12 10:18
    I have rewritten the program now. But I still have a little problem. I control the motors with IF Then commands, but this I can only use 2 times in the program. So I can only control one of the two motors. If there is a simple solution it would be nice to contact me.

    Here is the new code:

    ' {$STAMP BS1}
    OUTPUT 3
    INPUT 7
    INPUT 6
    Schleife:
    GOSUB SENSOR1
    GOSUB SENSOR2

    IF B0<90 THEN MOTORAUS
    IF B0>90 THEN MOTORAN
    GOTO Schleife

    MOTORAUS:
    PIN3=0
    PAUSE 2000

    MOTORAN:
    PIN3=1
    PAUSE 2000



    SENSOR1:
    POT 7, 90, B0
    DEBUG B0
    RETURN
    SENSOR2:
    POT 6, 90, B1
    DEBUG B1
    RETURN

    END
  • Mike GreenMike Green Posts: 23,101
    edited 2013-02-12 10:36
    You need a "GOTO Schliefe" after each "PAUSE 2000" and you might try making the PAUSE time smaller.

    Mostly you need to think about what you're trying to do. Obviously, you're reading the resistance of each of the two LDRs. You're turning on and off the motor attached to I/O pin 3 based on the resistance of the LDR connected to I/O pin 6. What do you want to do with the other LDR value? How do you want to control the other motor? Maybe you want to do first LDR 1 and motor 1, then LDR 2 and motor 2? How about making one subroutine with the IF statements and the PIN3=???. You could later add another subroutine for the other LDR and motor. Your main section would call SENSOR1, then the subroutine for motor 1, then SENSOR2, then the subroutine for motor 2, then a GOTO to repeat the whole thing. The PAUSEs could be in the main loop rather than in the subroutine (easier to see and adjust).
  • CentryCentry Posts: 4
    edited 2013-02-18 09:48
    Thanks for your help Mr. Green :), my program works now... I just have one little question. I'm new in this forum and i do not know how i can close a Thread. So it would be good if someone can tell me that.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-02-18 11:58
    Version 2.2 of Robotics with the BOE-Bot has a chapter about using photoresistors with the BOE-Bot. The discussion starts in Chapter 6 which is page 193 of the physical book and page 207 of the .pdf file.

    I'd think a lot of what is shown could be used with a BS1.

    I haven't used Basic Stamps much myself but I do recall having a lot of fun doing the exercises in Chapter 6 the above book.

    You can mark this thread "Solved" by editing your original post. Choose "Go Advanced" and there should be a drop down menu with "Solved" as one of the options.
Sign In or Register to comment.