Shop OBEX P1 Docs P2 Docs Learn Events
Servo motor control of a small solar panel — Parallax Forums

Servo motor control of a small solar panel

TuhawkTuhawk Posts: 2
edited 2009-03-22 13:47 in BASIC Stamp
I'm new to Basic stamp (I have a BS2 on BOE Rev. C). I'm trying to figure out how to make the servo motor, with solar panel attached mechanically track the sun. I have been able to get the motor to react with the photoresistor. I can make it turn by varying the amount of light but have been unable to make it seek out the brightest light. Any help?

Comments

  • JonathanJonathan Posts: 1,023
    edited 2009-03-17 20:31
    Use two photo-ressitors. Place them a few inches apart. Put a small, short tube on each one. Read the sensors, and have your progam look for the brightest spot on BOTH sensors. Of course, they won't read *exactly* the same, so you will need to add a little fudge factor.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • TuhawkTuhawk Posts: 2
    edited 2009-03-17 20:46
    This is my code:
    DEBUG " Value"
    time VAR Word
    DO
    HIGH 7
    PAUSE 10
    RCTIME 7, 1, time
    time = time */ 170 ' Scale by 0.4 (X 256 for */). This value is max pulses divided by 500
    time = time + 500 ' Offset by 510. (this is to make the value fall between 500 and 1000)
    PULSOUT 14, time ' Send pulse to servo.
    DEBUG HOME, DEC5 time ' Display adjusted time value.

    LOOP

    I Sure i am missing something to help it seek the brightest light. Thank you Jonathan fot the idea of using two photo resistors but I'm not sure what to add. Possibly some type of IF.. Then Else statement?
  • SRLMSRLM Posts: 5,045
    edited 2009-03-18 04:46
    A method would be to use an array of photo detectors on a curve, with individual shields. You calibrate each one to some specific light, then when you place it outside you find each value, calculate the real values based on calibration data, and simply pick the largest. You could also simulate many photo resistors with one mounted on a servo.
  • FearTurtlesFearTurtles Posts: 89
    edited 2009-03-18 13:38
    If using one sensor you would do a sweep by measuring the light at say 10 deg increments. After each measurement compare the new reading to the previous. If the value goes up take the next reading. If the value goes down then reverse direction. So you will need 4 variables "old_reading", "new_reading", "position", and "Direction_to_move"

    Your code will use the If/then statement to compare the new and old readings in order to set the direction. Direction_to_move is a 1 or a 0 for left and right. You use this to add or subtract 10 deg off your position. Then command your servo accordingly. You most likely would not want to loop this process unless you plain on having a charge complete state or factor in a do/until state which would require another reading variable.

    Thinking about this I might have to build a tracker.
  • FearTurtlesFearTurtles Posts: 89
    edited 2009-03-19 20:52
    I wrote this up this morning. I think it offers a good start for a single Photoresister control however it still need to argue whether the servo should turn to the left or right better i think. It would be also good to read the location of the servo and make sure that the servo does not go past 360deg to keep your wires from swisting up too much. The parts needed for my propeller project just arrived so I'm going to get distracted with it.

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

    'This program is to control a Parallax continous rotation servo
    'The Idea is to mount a solar panel on the servo along with a photoresistor.
    'The Program will move the servo about one pulse at a time and compair RCT
    'of the photo resister readings.

    'Flow of the program
    'Main:-which sets pausetime and cushion then jumps to Readlight:
    'ReadLight:-Measures the RTC and debugs the current reading then jumps to CheckValue:
    'CheckValue:-Basically this checks to see if the light level is worth adjusting to and what direction.
    ' If so then it jumps to SwapValue: If not then goes back to main:
    'SwapValue: - replaces the old reading with the new and jump to one of the servomovement subs.
    'MoveRight: and MoveLeft: tell the servo to move

    'Connections
    'Connect the photoresister an Parallax continous servo as described in the
    Servo_pin CON 14 'I/O pin that is connected to servo
    PhotoPin CON 2 'I/O pin that is connected to PhotoResister

    READold VAR Word 'old readin from PhotoResister
    READnew VAR Word 'Now reading rom photoresister
    LeftRight VAR Bit '0 for leftrotation 1 Right Rotation
    cushion VAR Word 'allows for a small amount of fluctuation in resistor without causing the servo to move
    time VAR Word 'sets the delays before reading photoresister again

    'First get reading of currect posistion from Photoresister.
    Main:
    time = 1000
    cushion = 10
    GOTO Readlight
    READnew = READold
    GOTO CheckValue
    '__________________Add additional tasks below__________________________________

    'Now search for more light.
    ReadLight: 'Measures brightness of light when you first power on the stamp
    'It also give the READold varable a value
    HIGH PhotoPin
    PAUSE 100
    RCTIME PhotoPin, 1, READnew
    DEBUG HOME, "current light level = ", DEC5 READnew
    GOTO CheckValue

    MoveRight:
    PULSOUT servo_pin,600
    PAUSE 20
    GOTO Main
    MoveLeft:
    PULSOUT servo_pin, 800
    PAUSE 20
    GOTO Main

    CheckValue:
    '
    IF READnew < 11 THEN
    PAUSE time
    GOTO Main
    ELSEIF READnew > 1000 THEN
    PAUSE time
    GOTO Main
    ENDIF

    IF READnew - cushion > READold THEN
    LeftRight = 1
    GOTO swapvalue
    ELSEIF READnew + cushion < READold THEN
    LeftRight = 0
    GOTO swapvalue

    ENDIF
    swapvalue:
    READold = READnew
    IF LeftRight = 1 THEN 'The 1 and 0 might need switching if tries to move away from light.
    GOTO MoveLeft
    ELSEIF LeftRight = 0 THEN
    GOTO MoveRight
    ENDIF
  • KHARNHKHARNH Posts: 2
    edited 2009-03-21 18:05
    I've been working on a solar tracker project for awhile and the sensor looking through a tube works OK but eventually you start to realize that what you've got is like a big pixel on a digital camera that senses only brightness. How many "pixels" you need and how much of the sky one covers begins to become a question as you realize that conditions are not always going to be optimal. The day may be partly sunny, partly cloudy or overcast so it becomes important to be able to compare measurements between sensors in the context of time so the stamp can use some algorithm to decide what conditions it's observing.

    Put yourself in the stamp's shoes. You're looking at the sky through a piece of material with a given number of holes in it at a given size.·Based on what you see you have to decide whether the sun has moved or a random cloud drifted across it and now the sky is brighter than the spot where the sun was. Not a big problem for the human brain but for a basic stamp it could be a task. Your software has to be able to decide if the·brighter light source is really the sun or not so relative brightness versus time as conditions change becomes a factor. What if it's just the sun reflecting off a shiny object? That's a condition that could persist for awhile. You don't want to waste energy chasing phantoms or have the tracker pointing at your neighbor's car mirror·but you don't want to freeze up because you can't make a decision. You could rely on a time delay and wait for the cloud to pass but what happens on a partly sunny day with clouds randomly drifting across the sun at unpredictable intervals? How long do you let the tracker sit there before you decide the sun has really moved?

    Just tossing out food for thought. These aren't impossible issues but you have to bear in mind that they do exist and the more of them that become apparent the more complex your system starts to become so it's a tradeoff between how accurate you want the tracker to be versus simplicity.
  • FearTurtlesFearTurtles Posts: 89
    edited 2009-03-21 19:40
    Thats true if your trying to track using two axes. If a cloud blocks the sun then the tracker can end up running wild trying to find the bright spot. If only a single axes is uses then this becomes less critical. But by adding a time keeping chip you can limit the range of the tracker and set up a photo resistor to fine tune the panels. Or maybe use it to calculate the amount of light you're receiving. Solar panels have a rather large area of offset to the sun where they still operate at about 85% or better of there max wattage. So a single axes tracker works pretty well. For practical use I guess it would be best to use a Time Keeping chip to determine what direction the panels need to point in and adjust the servo accordingly. Now because we are talking being on a bot I would also adjust the panels so that they move in opposite of the change in the bot heading. The Ideal would be to have a compass, Timing chip, and Photoresister.
  • FearTurtlesFearTurtles Posts: 89
    edited 2009-03-22 13:47
    Thanks PJ,
Sign In or Register to comment.