Hi,
I am currently doing a project. I used an array of LDR sensors (8 of them), installed them stationary around the lightcrafter. These LDRs are use for a wake-up system, if they sensed any strong light, it will trigger the relay and turn on the lightcrafter.
On the rotating platform, there will be another 3 LDR sensors to track the light source. Please find the attached code and image below to have better understanding what I am doing
I have tried out my code but it seems to have some problems.
Can anyone help me with that? I believe is my coding problem.
relay i using - http://www.sgbotic.com/index.php?dispatch=products.view&product_id=1717
motor i using - http://www.01mechatronics.com/sites/default/files/docs/SuperModified.V3.Datasheet.pdf

circuit diagram

how i install those LDR
#include <ZerooneSupermodified.h>
#include <Wire.h>
ZerooneSupermodified motor(ZO_HW_WIRE);
int sens1 = A0; // LDR 1 pin
int sens2 = A1; // LDR 2 pin
int sens3 = A2; // LDR 3 pin
int array1 = A3; // LDR pins for wake up
int array2 = A4;
int array3 = A5;
int array4 = A6;
int array5 = A7;
int array6 = A8;
int array7 = A9;
int array8 = A10;
int relay = 7; // relay pin
int tol = 40; // tol difference
int pos = 0; // initial position
void setup()
{
pinMode(relay,OUTPUT);
}
void loop()
{
int val1 = analogRead(sens1);
int val2 = analogRead(sens2);
int val3 = analogRead(sens3);
int val4 = analogRead(array1);
int val5 = analogRead(array2);
int val6 = analogRead(array3);
int val7 = analogRead(array4);
int val8 = analogRead(array5);
int val9 = analogRead(array6);
int val10 = analogRead(array7);
int val11 = analogRead(array8);
int diff1 = abs(val1-val2);
int diff2 = abs(val3-val2);
int diff3 = abs(val1-val3);
int avgT = (val4 + val5 + val6 + val7 + val8 + val9 + val10 + val11)/8;
if(avgT < 400){ // when the LDRs sense strong light
digitalWrite(relay,HIGH); // turn on the relay
if((diff3 > tol)||(diff3 < -1*tol)){ // check the left and right LDR difference
motor.start(4);
if(!motor.getCommunicationSuccess()){
motor.resetErrors(4);
}
if(val1 < val3){ // smaller value means stronger light
pos = pos + 91; // 91 ticks mean 1 degree
}
if(val3 < val1){
pos = pos - 91;
}
if((diff1 < -1*tol)&&(diff2 < -1*tol)){
if((val2 < val1)&&(val2 < val3)){ // if the middle one senses strongest light than the other two, stop the motor
motor.halt(4);
}
}
motor.moveToRelativePosition (4,pos); // move the motor
delay(50);
}
}
else{
digitalWrite(relay,LOW); // if no strong light sense, off the relay
motor.stop(4); // stop the motor, cut off communications
pos = 0; // initialize the position
}
}