Control of motors with sensors - Need help!!!
Centry
Posts: 4
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!
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!
Comments
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.
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
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).
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.