Hi everybody...
I'm here to get some advices and help to finish my college final course project... It's a Arduino Solar Tracker for a small dimension solar panel using LDR sensors.
You can check the video of the L297/L298/L6210 test:
The actual code that I'm usign:
#define NAME "SOLAR TRACKER"
#define VERSION "0.1"
//ANALOGIC PINS
int pinLdr_1 = 3;
int pinLdr_2 = 4;
int pinLdr_3 = 5;
// ENABLE, HALF-FULL, CW-CCW, CLK - TO L297
int pinEnable = 2;
int pinCwCCW = 4;
int pinCLK = 5;
int ldr1 = 0;
int ldr2 = 0;
int ldr3 = 0;
void setup(){
Serial.begin(9600);
pinMode(pinEnable, OUTPUT);
pinMode(pinCwCCW, OUTPUT);
pinMode(pinCLK, OUTPUT);
}
void steps(int nro){
int i;
for(i=0;i<nro;i++){
digitalWrite(pinCLK,LOW);
digitalWrite(pinCLK,HIGH);
delayMicroseconds(2000);
}
}
void loop(){
//tone(pinCLK,50); //100Hz -> gerador de onda
ldr1 = analogRead(pinLdr_1);
ldr2 = analogRead(pinLdr_2);
ldr3 = analogRead(pinLdr_3);
delay(1000);
//ldr1 - right
//ldr2 - middle
//ldr3 - left
if ((ldr1 > ldr2) && (ldr1>ldr3)){
//move right
digitalWrite(pinCwCCW,LOW);
digitalWrite(pinEnable,HIGH);
steps(1000);
digitalWrite(pinEnable,LOW);
} else if ((ldr3 > ldr2) && (ldr3>ldr1)){
//move left
digitalWrite(pinCwCCW,HIGH);
digitalWrite(pinEnable,HIGH);
steps(1000);
digitalWrite(pinEnable,LOW);
} else {
digitalWrite(pinEnable,LOW);
}
}
The problems that I'm having:
-
What's the better way to read the LDR sensors and compare then to take decisions (because of the LDR delay) ***
-
As I'm doing a solar tracker, I don't need fast response, so how can I make a function to send 4 steps for example to L297 ? The actual function "steps" I based on EasyDriver example... ***
-
I was using the tone() function to send CLOCK signal to L297 but it was too fast to move the panel and on changing the rotation (clockwise/counter-clockwise) the motor stucks...
The LDRs
Arduino Uno at Work
Any suggestions or advices to improve my code ?