Hi there
I am currently busy with a solar tracking project where i use multiple(lets say 7) light dependent resistors and reading the voltage drop across each using the analogueRead(pin number) function and running the motor until the voltage across the middle resistor(position 4) is the highest.
Does anyone have any tips on how to compare the values already received?
e.g Position 2 has the highest voltage reading(i.e the most sunlight) but need to run the motor until position 4 has the highest voltage value.
What is the pattern of the sensors ? In a straight line or some other arrangement ?
You need both the value and the position that it was in.
-
Assume that position 1 has the highest value. Get its value.
-
Compare the value (from position 1) with the value from position 2, position 3, etc.
Use a for loop !
-
If there is a higher value, save the value and its position.
-
Keep going through all the positions, saving a value and its position if the value is higher than the saved value.
The result is the highest value (which you may not need) and its position.
I will not be any more specific until you show the code for reading the values, and you settle on how many positions there are. Also helpful will be knowing the pin numbers that you use. You DO know how to use arrays and for loops?
There are several way of solving this problem.
Due to the minimum of information u gave, I assume u got a matrix of sensor on the panel.
-
You have to know what the highest value is.
Therefore u can put them in an array and find the highest by useing max().
-
Once you know where the highest value is, you want your motor to bring the middle one in that position.
You can either do that by placing the sensors in a way where u know how to turn the middle one in there with a fixed path.
Or you do it by checking the values over and over again.
(A Problem might be an delay of the sensors, which means if you turned in the right position it might overrun, because it still doesn't get the corrected value. Therefore I would recommend to isolate the sensors if that happens.)
- Define a path for all positions to controll the motors in the right direction, which wouldn't be hard if u place the Sensors in a good matrix you will have the same distance and just have to declare how many times you have to go e.g. up and left.
I hope that makes sense. Feel free to ask questions.
As a recommendation: Please upload your code, that makes it easier to help you and we could respond easier with our own version of that code.