Hi!, I am making a solar tracker, that uses 4 photoresistors for detecting sunlight.
servo motor is used for vertical movement of the panel.
Direction of rotation of DC motor with 2 relay and Arduino is used for horizontal movement.
I am using Arduino uno.
This is the example I used for code of vertical movement for servo
And this example for horizontal movement of dc motor
https://robojax.com/learn/arduino/?vid=robojax_2_relay_motor
here is my code
int topleft;
int topright;
int downleft;
int downright;
int waittime = 1;
int relay1 = 2;
int relay2 = 3;
void setup() {
pinMode(10, OUTPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
TCCR1A = 0;
TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM11);
TCCR1B = 0;
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS11);
ICR1 = 40000;
OCR1A = 3000;
OCR1B = 3600;
}
void loop() {
topleft = analogRead(A0);
topright = analogRead(A1);
downleft = analogRead(A2);
downright = analogRead(A3);
if (topleft > topright) {
digitalWrite(relay1, LOW);// turn relay 1 ON
digitalWrite(relay2, HIGH); //turn relay 2 off
delay(waittime);
}
if (downleft > downright) {
digitalWrite(relay1, LOW);// turn relay 1 ON
digitalWrite(relay2, HIGH); //turn relay 2 off
delay(waittime);
}
if (topleft < topright) {
digitalWrite(relay1, HIGH);// turn relay 1 OFF
digitalWrite(relay2, LOW);// turn relay 2 ON
delay(waittime);
}
if (downleft < downright) {
digitalWrite(relay1, HIGH);// turn relay 1 OFF
digitalWrite(relay2, LOW);// turn relay 2 ON
delay(waittime);
}
if (downleft == downright && topleft == topright){
digitalWrite(relay1, HIGH);// turn relay 1 OFF
digitalWrite(relay2, HIGH);// turn relay 2 OFF
delay(waittime);
if (topleft > downleft) {
OCR1B = OCR1B - 1;
delay(waittime);
}
if (topright > downright) {
OCR1B = OCR1B - 1;
delay(waittime);
}
if (topleft < downleft) {
OCR1B = OCR1B + 1;
delay(waittime);
}
if (topright < downright) {
OCR1B = OCR1B + 1;
delay(waittime);
}
if (OCR1B > 4200) {
OCR1B = 4200;
}
if (OCR1B < 3000) {
OCR1B = 3000;
}
}
}
Can this be detected by 2relay module, or this will only work with servo. I am not sure what these mean, I am a complete beginner in this.
TCCR1A = 0;
TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM11);
TCCR1B = 0;
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS11);
ICR1 = 40000;
OCR1A = 3000;
OCR1B = 3600;
Can you please help me with my code?
What should I add or delete ?