View Full Version : help with servo

09-16-2011, 12:09 AM
Hi I recently made a sun tracker with solar panels and all that good stuff but when nearly completed I couldn't figure out how to make the servo go in reverse if it's just code fine, if it's just that I need to tweak the servo fine. Thank you for your help. by the way I'm using the basic stamp 2 with the board of education.

Beau Schwabe (Parallax)
09-16-2011, 12:32 AM
Can you post the code that you are currently using, along with a schematic or a description of how you have things connected? That would help give us a better picture of your set-up and what you have tried.

09-16-2011, 12:39 AM
I just need to know how to get the servo to go the opposite way. But here's the code. The timeTop, Bottom, and Middle are just the photo resistors to tell it were the sun is most concentrated. The servo is plugged into p12

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

timeTop VAR Word
timeBottom VAR Word
timeMiddle VAR Word

RCTIME 1,1,timeBottom
RCTIME 6,1,timeMiddle
RCTIME 10,1,timeTop

DEBUG HOME, "timeTop = ", DEC5 timeTop, "timeBottom = ", DEC5 timeBottom, "timeMiddle = ", DEC5 timeMiddle

IF (timeTop+30<timeMiddle) THEN
PULSOUT 12, 625
ELSEIF (timebottom+30<timeMiddle) THEN
PULSOUT 12, 625 'this is were i'm having trouble with getting the servo to go the opposite way

09-16-2011, 12:49 AM
What values do you get in the Debug window in the different lighting situations? When do you want it to change directions?

BTW "I just need to know" is not a good way to get an answer. "I'd like to know" would be more appropriate.

Beau Schwabe (Parallax)
09-16-2011, 12:54 AM
Let me direct you to the PDF "What’s a Microcontroller"...


... Specifically Chapter 4 Activity #2 "ACTIVITY #2: SERVO CONTROL TEST PROGRAM"

09-16-2011, 12:57 AM
I want it to turn so light is more direct on the solar panels it works going one way but it won't go the other ways everything else works perfectly. If there is more light on the bottom it turns so there is more light on the middle however I want it so when there is more light on the top it will spin the other way so the light is more direct on the middle. But it only spins one way so if there's more light on the bottom it wants to spin all the way back around instead of just going backwards.

Matt Gilliland
09-16-2011, 01:12 AM
Hi piezyxw-
As Beau suggested - Specifically check out:
Figure 4-18: Servo Horn Positions, PULSOUT Commands, and ms Pulse Duration
on page 109.

That should get you started, plus by entering different values for the duration of the pulses, you'll get a feel for how a servo works.

In other words, make mistakes and see what happens :-)

That's the way I learn best - and remember that "letting the smoke out" isn't always bad - I've learned a lot by doing exactly that :)

Oh, and BTW, welcome to the Forums!

09-16-2011, 01:33 AM
thanks for the help however just telling me that I had to enter a value lower than 350 or whatever would have made this go much faster. But it's working so thanks I can now track the sun so my solar panels are more efficient. keep up the good work!

09-16-2011, 02:35 AM
Less than an hour after you posted code,and its fixed.Thats not a bad turn around.

Matt Gilliland
09-16-2011, 05:56 AM
however just telling me that I had to enter a value lower than 350 or whatever would have made this go much faster.

That is absolutely true, piezyxw!

However, a "head full of answers" isn't nearly as good as a "thinking head". :-) You asked a question, got some advice on where to find the info you needed, did the research yourself - and came up with the answer you were looking for.

Well done! Build upon this and the sky's the limit ;-)


Matt Gilliland
09-16-2011, 05:57 AM
Hey piezyxw -

Could you post a pic of what you've done? It sounds pretty cool :-)