PICAXE-18X sun tracker

Special_k

New Member
I am new to this forum. I was hoping for some help with a project I just started.
I have a SparkFun Electronics - PICAXE-18X Starter Pack. I am using the PICAXE-18X on this board.
I am attempting to make a turret that follows light.
I have 4 LDR’s mounted on a 6”X6” plate in the directions North,South , East and West.
The turret will track the sun.
The problem is that when I debug the LDR outputs I only get three (north,south,east). Is that because the PICAXE-18X can only read 3 inputs.
Is my code wrong any help would be appreciated.
Also I thing my movement code is all wrong but it is a start.
Code is bellow.

Code:
symbol head = 3
symbol neck = 4

symbol NC = 133
symbol HC = 130
b11 = HC
b12 =HC
symbol north = 0
symbol south = 0
pause 100
servo neck,NC
pause 300
servo head,HC 'move servo to centre
pause 300
main:    
gosub testnorth
gosub testsouth
'readadc 0,b0 'read channel 0 into variable b0
'readadc 1,b1
'readadc 2,b2
'readadc 3,b3

if b0 < b1 then gosub thnorth

if b1 < b0 then gosub thsouth

debug b0 'transmit value to computer screen
debug b1 ' transmit value to computer screen

debug b2  ' transmit value to computer screen
debug b3  ' transmit value to computer screen


goto main ' jump back to the start


testnorth:
b5=0
b6=0
b7=0
readadc 0,b5 'read channel 0 into variable b0
pause 2
readadc 0,b6 'read channel 0 into variable b0
pause 2
readadc 0,b7 'read channel 0 into variable b0

b0=b5+b6+b7
b0=b0/3 
return

testsouth:
b8=0
b9=0
b10=0
readadc 1,b8 'read channel 0 into variable b0
pause 2
readadc 1,b9 'read channel 0 into variable b0
pause 2
readadc 1,b10 'read channel 0 into variable b0

b1=b8+b9+b10
b1=b1/3 
return

thnorth:
pause 100

b11=b11+5
servo head,b11 'move servo to centre + 5
pause 100
return
 
thsouth:
pause 100
b12=b12-5
servo head,b12 'move servo to centre + 5
pause 100
return
 

hippy

Technical Support
Staff member
You could probably wire pairs of LDR's as potential dividers, one set N-S, the other set E-W.
 

BeanieBots

Moderator
Pairs as suggested by Hippy is good way of reducing input requirements but be a little careful. Depending on which LDRs you are using, some can get quite low impedance when exposed to strong light and could over-current. Check with the datasheets. If in doubt, maybe fit a 1k resistor in series with each one.
 

KMoffett

Senior Member
Just to throw out a tracker concept. I was putzing with this about a year ago, but never fully implemented it.
I used Beaniebot's idea of a voltage-divider for the 4 photocells. One servo for elevation and one for azimuth. That worked.
One photo cell, in the lower right, was for determining if it's too dark to track.
The MC4427 was to drive the servo signals down three floors to indicate the trackers' positions to a Labview system.

Ken
 

Attachments

Tom2000

Senior Member
Cool project.

I've thought about these, but have never tried to build one. One thing I could never figure out was the best way to acquire the sun at initialization. Do you scan? Or is there a clever, quick way to do so?

Thanks!

Tom
 

papaof2

Senior Member
Most basic way - start out with the panel facing east, then move west until the light level begins to drop.

Something similar works for up/down angle.

Depending on how fast the panel can move, you might hold the previous few readings to be able to move back to the maximum if/when you go past it.

John
 

Special_k

New Member
Thanks for all the help and ideas. any suggestions on tracking code. I think my code is weak (it only goes north and south)- test for now.
I will upload a picture of the rig when the Solar Panels arrive and get mounted.
 

Tom2000

Senior Member
Most basic way - start out with the panel facing east, then move west until the light level begins to drop.

Something similar works for up/down angle.

Depending on how fast the panel can move, you might hold the previous few readings to be able to move back to the maximum if/when you go past it.

John
Thanks, John!
 

stocky6409

Senior Member
Cool project.

I've thought about these, but have never tried to build one. One thing I could never figure out was the best way to acquire the sun at initialization. Do you scan? Or is there a clever, quick way to do so?

Thanks!

Tom
One commercial system uses a GPS engine to work our where to look!
The system uses a fixe elevation and a conventional linear actuator for azimuth control - they have simply worked out acurately the tracking time a run the motor to one extreme or the other once it has got GPS lock then track forward or back certain number of seconds to point at where the sun should be.
 

Tom2000

Senior Member
One commercial system uses a GPS engine to work our where to look!
The system uses a fixe elevation and a conventional linear actuator for azimuth control - they have simply worked out acurately the tracking time a run the motor to one extreme or the other once it has got GPS lock then track forward or back certain number of seconds to point at where the sun should be.
Thanks! That system makes a lot of sense.

And it has a big advantage over a solar tracker: it can work equally well at night. :)
 

Special_k

New Member
now PICAXE-28X1 sun tracker

got the new chip (28X1) and I can now read all inputs. there is a problem with the LDRs or the reading of the LDRs. if there is no direct light source (bright sun or flashlight) the reading go wild, some read 4 others read 77 -50. the LDR's are hooked up is the same as in picaxe manual 1 page 64
one per direction. any suggestions here? (I am getting 4 new LDRs from sparkfun since these are non matched pulled parts)
Movement is a little funky (jittery) any coding help would be appreciated.
Overly commented code right here

Code:
'code for light seeking turret by Kwaku A.
symbol head  = 0
symbol neck  = 1
symbol north = b0
symbol south = b1
symbol east  = b2
symbol west  = b3
symbol dify  = b4
symbol srvhd = b11
symbol srvnk = b12
symbol difx  = b13
symbol timey = b14
symbol timex = b15

srvhd = 130                 'move head servo to centre
srvnk = 130                 'move head servo to centre

pause 100
servo neck,133              'move head servo to centre
pause 300
servo head,130              'move neck servo to centre
pause 300
main:    'START OF CODE LOOP
dify=0                      'Difference between LDR's in y 
difx=0                      'Difference between LDR's in x 

gosub testnorth             'test light levels for north LDR
gosub testsouth             'test light levels for south LDR
gosub testeast              'test light levels for east LDR
gosub testwest              'test light levels for west LDR

                                  'START CODE FROM HIPPY
if north > south then subnthfromsth     'CODE FROM HIPPY
substhfromnth:                          'subtract north from south
dify= south-north                       'this is not north -south
goto difydone
subnthfromsth:
dify= north-south                       'this is not south - north
difydone:                               'END CODE FROM HIPPY


                                      'START CODE FROM HIPPY
if east > west then subestfromwst       'CODE FROM HIPPY
subwstfromest:                          'subtract east from west
difx= west-east                         '
goto difxdone                           '
subestfromwst:                          '
difx= east-west                         '
difxdone:                               'END CODE FROM HIPPY



if dify <= 16 then goto  difxtag    'Negligible difference skip movement


if north < south then gosub thnorth  'track north to get more light
if south < north then gosub thsouth  'track south to get more light
difxtag:
if difx <= 16 then goto  main       'Negligible difference skip movement
if east < west then gosub theast    'track east to get more light
if west < east then gosub thwest    'track west to get more light

'goto nocodetest                     .skip test debug + other code
debug north                          'transmit value to computer screen
debug south                          'transmit value to computer screen
debug east                           'transmit value to computer screen
debug west                           'transmit value to computer screen
debug dify                           'transmit value to computer screen
nocodetest:
goto main                            'jump back to the start


testnorth:                'read inputs several times
   b5=0                   'set test variables to 0
   b6=0                   'set test variables to 0
   b7=0                   'set test variables to 0
  readadc 0,b5            'read analog input 0 into variable b5
  pause 2
  readadc 0,b6            'read analog input 0 into variable b6
  pause 4
  readadc 0,b7            'read analog input 0 into variable b7
   north=b5+b6+b7         'add all variables together
   north=north/3          'get mean of northern light readings
return

testsouth:                'read inputs several times
   b8=0                   'set test variables to 0
   b9=0                   'set test variables to 0
   b10=0                  'set test variables to 0
  readadc 1,b8            'read analog input 1 into variable b8
  pause 2 
  readadc 1,b9            'read analog input 1 into variable b9
  pause 4
  readadc 1,b10           'read analog input 1 into variable b10
   south=b8+b9+b10        'add all variables together
   south=south/3          'get mean of light readings
return

testeast:
   b5=0                   'set test variables to 0
   b6=0                   'set test variables to 0
   b7=0                   'set test variables to 0
  readadc 2,b5            'read analog signal 2 into variable b5
  pause 2
  readadc 2,b6            'read analog signal 2 into variable b6
  pause 2
  readadc 2,b7            'read analog signal 2 into variable b7
   east=b5+b6+b7          'add all variables together
   east=east/3            'get mean of light readings
return

testwest:
   b8=0                   'set test variables to 0
   b9=0                   'set test variables to 0
   b10=0                  'set test variables to 0
  readadc 3,b8            'read analog signal 3 into variable b5
  pause 2
  readadc 3,b9            'read analog signal 3 into variable b6
  pause 2
  readadc 3,b10           'read analog signal 3 into variable b7
   west=b8+b9+b10         'add all variables together
   west=west/3            'get mean of light readings
return


thnorth:
   pause 60
   srvhd=srvhd+3
   if srvhd >= 225 then upnorm     'test to see in new server value out of range
  goto ntsrv
upnorm:                            'new servo value out of range set to upper limit
    srvhd=225  
ntsrv:
   servo head,srvhd               'move servo to servo position + 3
   pause 300
return
 
 
thsouth:
   pause 60
   srvhd=srvhd-3
   if srvhd <= 60 then dnnorm    'test to see in new server value out of range
  goto stsrv
dnnorm:                          'new servo value out of range set to lower limit
    srvhd=60
stsrv:
   servo head,srvhd               'move servo to servo position -3
   pause 300
return


theast:
   pause 60
   srvnk=srvnk-3
   if srvnk <=60 then  rtnorm     'test to see in new server value out of range
   goto etsrv
rtnorm:                           'new servo value out of range set to upper limit
    srvnk=60
etsrv:
   servo neck,srvnk               'move servo to servo position + 3
   pause 200
return


thwest:
   pause 60
   srvnk=srvnk+3
   if srvnk >=225 then  ltnorm     'test to see in new server value out of range
   goto wtsrv
ltnorm:                             'new servo value out of range set to upper limit
    srvnk=225
wtsrv:   
   servo neck,srvnk                'move servo to servo position + 3
   pause 200
return
it works but it could move smother and I know the code could be tighter (this is my first picaxe project) I am learning code as I go.
 

BCJKiwi

Senior Member
Just a few suggestions;
1. calibrate the LDRs;
Try different divider R values so there is a good range of READADC values from light to dark.
Check they are all the same
2. try using readadc10 (and a w variable instead of a b variable) gives 0 thru 1023 instead of 0 thru 255
3. try adjusting the hysteresis (difx and dify <= 16) as this will determine how much/often you move. 256/16=16 gives a movement only when light value changes by 1/16th of total range.
 
Top