Hi,
I am new to this forum and to Arduino.
So this question is regarding my first ever Arduino project.
So I am trying to create a sketch to control a linear actuator based off the inputs of two LDRs. I have zero experience with writing sketches for Arduino but I have a good understanding of electronics.
I live off the grid and I build a solar tracking array to complement my existing solar system and it’s all in place including a 36v linear actuator.
I have an Arduino mega and two LDRs and a set of to appropriate transistors and relays to control my actuator.
Basically I am looking for some guidance on writing a sketch to control the the outputs of two pins (non pwm just HIGH or LOW) base on the analog values read off of the two LDR inputs. So if LDR1 input is greater than LDR2 make a given output pin HIGH (tracker moves east) or if LDR2 is greater than LDR1 make a different output pin HIGH (tracker moves west) If LDR1 is equal to LDR2 both pins LOW. If both LDRs input a very low value (nighttime) make a given pin high to move the tracker all the way back to West in preparation for sunrise.
I have found a few sketches online that people have made for solar trackers but everything I have found is based off a pwm output for controling a Servo. I don’t need to worry about any input for the position of the actuator because it has built in limit switches.
Hi,
I helped build a prototype solar tracker a few years ago in Saudi Arabia.
Tell us the physical arrangement of the two LDRs.. Is there a "blade" or "baffle" between the two sensors so the aiming makes a big difference?
Other: Since you are controlling Solar Panels, there does not need to be constant small updates to the position. Think about accumulating position error for several minutes at least before making a movement.
Stepwise Refinement: Get each part working as a separate sketch. The sensors first, send data to the serial monitor so you can test by pointing the sensors to different positions and seeing the output. I think you will find the position where both sensors are illuminated is small, and can be controlled by the length of the "blade". Characterize it's action in direct sunlight, overcast, heavy clouds etc.
Get the control of the actuator working separately. Characterize it: how many degrees of change per second/minute etc.
Then thing about you want to relate the two.
Good thing about this project: it has plenty of time to think...
I agree with aarg. Whenever possible, it is probably better to use calculations based on a real time clock than to use sensors. Using sensors, the Panels can "rattle" around because they are reacting to a temporary cloud. Actuators have a limited lifespan and the more they are used, the faster they wear out so preventing rattle saves maintenance in the Long run. Also, sensors tend to be low voltage and therefore the signals are subject to "noise" over the relatively Long runs between the sensor and the Arduino. A sensor can be radically affected by a nasty bird that decides to .... dirty up your sensor. The RTC is probably not any more expensive than the two sensors...
The logic for tracking the sun with 2 LDRs is simple
read the two LDRs and save the values
compare the values
if there is a significant difference
move a bit towards the brighter one
repeat
else
wait for the sun to move on
repeat
JaBa:
I agree with aarg. Whenever possible, it is probably better to use calculations based on a real time clock than to use sensors. Using sensors, the Panels can "rattle" around because they are reacting to a temporary cloud. Actuators have a limited lifespan and the more they are used, the faster they wear out so preventing rattle saves maintenance in the Long run. Also, sensors tend to be low voltage and therefore the signals are subject to "noise" over the relatively Long runs between the sensor and the Arduino. A sensor can be radically affected by a nasty bird that decides to .... dirty up your sensor. The RTC is probably not any more expensive than the two sensors...
[soapbox]
A correctly built, programmed and maintained array will not "rattle" around.
"Noise" on the LDR signals can be bypassed as system response can be very long, LDRs are not the only radiation sensor.
Actuators have a very long lifetime, you need to invest in reliable units.
The fact that as a cloud or clouds move over you get movement away from the norm, means the system is doing what an RTC cannot, track the panels to the area of the sky that has maximum radiation.
A solar radiation based tracker responds to the environment, an RTC is impervious to the environment. [\soapbox]
[/soapbox]
You need a servo in order to use computed solar position. The hardware that is described has no positional feedback. So for practical purposes, you have to add a panel position sensor or an illumination sensor. You could have both, and implement some interesting optimization and fault detection.
I doubt that the difference in angular illumination due to clouds would make much difference, because the panels themselves do not have a very directional sensitivity, and also because the periods when clouds are present are periods of very low energy output.
If you already have a servo, using computed position could be a useful simplification of hardware vs. using an illumination sensor. If not, then it is a matter of which hardware is easier or cheaper to add. If you have both, it would be possible to log illumination data and evaluate the performance of the illumination sensor. Based on hard data from that kind of experimentation, it would be easier to evaluate the trade offs involved in choosing one, the other, or both techniques.
There are two ways you could do that - track the computed position and log the illumination, or track the illumination and log the position.