Hey guys, new to the whole forum business. Currently i'm working on a dual axis solar tracker for college, it consists of 4 LDRs to tell the arduino what to do. I've been simulating it on 123dcircuits and it runs fine with the code, but it doesn't want to do its job IRL. Below is the code I am using, and the circuit too. If you have any idea where i'm going wrong please let me know, i'm going mental here.
The issue is that the whole thing isn't running, and when I check the serial monitor it's saying that something is happening with ports A3 and A4, even though there is no light change to the LDRs. It's also reading that the position of the servo is changing, when in actual fact it's not even turning.
Any help would be really appreciated, i've very new to this.
sketch_mar09a.ino (2.65 KB)
Hi. Some corrections
if((abs(val1 - val2) <= tolerance) || (abs(val2 - val1) <= tolerance)) {
abs(val1-val2) = abs(val2-val1)
so use only one
if((abs(val1 - val2) <= tolerance){
If your are going to do nothing, then then do it.
Try this way
if (abs(val1 - val2) > tolerance) {
//do nothing if the difference between values is within the tolerance limit
if(val1 > val2) {
pos = --pos;
}
if(val1 < val2) {
pos = ++pos;
}
}
if (abs(val4 - val3) > tolerance2) {
if(val4 > val3) {
pos2 = --pos2;
}
if(val4 < val3) {
pos2 = ++pos2;
}
}
I believe that your tolerance is too close.
Check the modifications and then rise tolerance to 5 for instance.
Thanks for the quick reply.
I've altered the code as you said. After running through the circuit with a multimeter i've found that some of the wires are faulty, i'll have to just change a few of these, also think the breadboard isn't doing what it's meant to. Once again, thanks for the reply
Hi,
How are you powering the servos?
The 5V from the UNO will not be enough, especially for two servos.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Not the fritzy, it is not a circuit diagram.
Thanks.... Tom...... 
Hey man, yea i'm running them through an Arduino Genuino, will it not be able to handle them? The diagram I have up is just a rough guide of the circuitry (i'm assuming my technical terms are all wrong, but god loves a trier eh? :P) I can't seem to get the servo to turn in conjunction with the signal between the two LDRs now though. [I reduced the circuit just so I can get it working first]. Any help?
You can't power servos from the Arduino 5V pin. Use a separate power supply and connect the grounds.
Find attached you will see what I am using. I don't have the wires attached as it looks like a mess and is hard to tell what is happening.
1st image = What components i'll be using.
2nd image = A single LDR set up with resistor in series.
3rd image = LDR+Resistor with a servo attached.
This images are stripped of all extras to make it easier to see what I am doing.
I'm using 2 continious servos. When I used a sample code from the internet they were both able to run, so I'm not sure why I would need another power source.
The promblem I think is in my code, i'm assuming the fact that the servo is not constrained to 180 matters, would I be right in saying so?
they were both able to run, so I'm not sure why I would need another power source.
You WILL damage or destroy the Arduino doing that. It is just a matter of time.
Looks like I'll have to put in another power source so, shouldnt be much of a problem though