Science project
I've decided to do a light-following solar panel with an Arduino for my science project. However, I'm kinda stuck. I'm confused on how to get the numbers to compare, then tell the servo to go to that position...
Thanks for the help!
I've decided to do a light-following solar panel with an Arduino for my science project. However, I'm kinda stuck. I'm confused on how to get the numbers to compare, then tell the servo to go to that position...
Thanks for the help!
@ Thu, 2010-02-11 15:11
keep the goal in mind
@ Wed, 2010-02-10 07:27
Another option is to make a
Another option is to make a simple 'proportional' controller.
First you calculate angleChange = K*(Analog1 - Analog2), where K is the proportional constant that you've chosen (it could be quite small if you're using a 10bit ADC, I'd start with 0.05). If Analog1 is on the left and Analog2 is on the right, then a positive angleChange value would indicate the servo needs to turnt he panel to the left, and vice versa for a negative angleChange value.
The next step is to add angleChange to your current servo angle, and then double check to make sure the servo angle is still within the servo limits. If the new servo angle is too high or too low then you can just set it equal to the maximum or minimum angle respectively.
The advantage of this design, even though it's still quite simple, is that the servo will move more quickly if it's further away from the optimum angle, and then it'll slow down as it locks onto the light source. The proportional constant K can be increased to boost the speed of the response, or it can be decreased to increase the accuracy. If the servo doesn't seem to lock onto a stationary light source very well it probably means K is too high.
@ Wed, 2010-02-10 03:35
You really should include
You really should include more detail like what parts you are using, how many adc channels you plan to use, if you are using stationary light tracking devices(photodiodes, LDRs, etc) or if they are attached to the solar panel and rotated when the panel is rotated.
Have you considered reading the voltage level of the panel as well, mind you if the voltage output is above the voltage level for the arduino, you can always use a voltage splitter. With direct input from the solar panel you can do a decent job of finding what direction to best face. You can also assume that you will be going to rotate in one direction(reflected light could throw this off though).
This info would help in figuring out a general algorithm to use for just such a case.
You should think of various scenarios as well that could throw off your readings and how you would react for each. For example overcast, rainy, early morning, late eve, someone walking in front of the panel.
Rough sketches don't hurt as well as a schematic.
Just a thought.
Or you could go with benbo's suggestion....it's simple enough. :)
You could also use a while loop, a switch case or my personal favorite and ever confusing ternary operator. test ? true:false and make that benbo if statement slightly shorter and very confusing.
(Analog1 == Analog2? wait(50):(Analog1 > Analog2? turn_right():turn_left()); //FTW!!!
:D
@ Wed, 2010-02-10 04:45
Whoops
Yeah, sorry man, I forgot all the details, thanks for pointing that out. I'm using 2 photoresistors on opposite sides of the panel (so they move with the panel).
Thanks for the info! I'll definitely try out that.... uhh... ternary operator. Also, since analog readings sorta fluctuate and dance around, could I like put a buffer of 30 on it or something so the servo isn't constantly jittering?
@ Wed, 2010-02-10 07:55
I would suggest testing out
I would suggest testing out benbo's technique as that would get you up and running quickly.
You can use a buffer value so that if it's within that range then it won't move. if you do, remember to define that value as a variable so that it can be changed easily and in one place.
I would define it as the total buffer value say x = 30 and place x where you want the value tested say
example code(this is not usable)
readleft = readadc 1//where readleft is the left sensor connected to pin 1
if x > readleft do whatever()
else if x < readleft do nothing() //or you can test this first this may save cpu cycles if you do as well.
@ Wed, 2010-02-10 02:27
Newb
I'm a newb at Arduino, but here's my theory of how to do it?
Get two Photodiodes, analog output. Use the Analogin on the arduinos to get the resistances from both, and then see which is bigger, like this:
If Analog1 > Analog2 Then turn right
Take an analog reading constantly as you turn, and when analog1 = analog2, you stop turning
If analog1 < Analog2 Then turn left
Take an analog reading constantly as you turn, and when analog1 = analog2, you stop turning