Light tracking system - IR or torch light

I know there are plenty of light tracking system guide which can be easily found online.
I am doing a light tracking system with a mems mirror on top of a rotating platform, and with 8/12 LDR surround it. The idea is to place the mirror to the light/IR source once either of the 8/12 LDR sensors sense something. The rotating platform will be using either stepper/ servo motor, but I will need a continuous servo. Anyone can help me with the code ?

I tried look online, most of them use analog I/O pins to check which side have the stronger light source then rotate the motor accordingly.

To add-on, I need the platform to stop at the respective light source direction.
THANKS LOT GUYS

So you want the mirror to find the light source and reflect it to a receiver? Is the receiver position fixed? Is the mirror only rotating on one axis or does it need to look up and down too?

How does "mems" apply to the mirror? What does this mean?

No you don't need a continuous servo. That would be a bad idea. A servo that rotates a full 360 degrees is a little difficult to find but not impossible. But do you really need 360 degrees?

Is the light source continuous? Does it need to be continuous at the receiver? I'm thinking that the mirror could rotate at a fixed speed (100rpm or something) and then it will reflect the source to the receiver, just not all of the time. No, you said it must stop. What if it rotates until the receiver gets a signal and then it stops?

since you state 360 degrees, your LDR's will each have to 'see' behind their heads.

if sensor #1 is higher than sensor #2, move the motor one way. if sensor #2 is higher than sensor #1, move the other way.

if sensor #3 has a reading, move at least 90 degrees. then look at steps 1 and 2.

sensor #3 being the rear facing sensor, and I would flip a coin to pick which way to move to get the mirror turned to pick up the light. it really does not matter as the two front facing will be the key, that is if they move with the mirror.

if you are going to have multiple LDR sensors that are fixed, and try to move the mirror only, you will need to use a different approach to positioning.

I would use a stepper for this and Robin2 had a great intro into steppers. I hope he can post the link.

for the stepper code, I would have three levels or windows. if LDR1 is move than 20% higher/lower than LDR2, then move at 100 pulses per second. if the difference is 5% to 20% move as 20 pulses per second if the difference is less than 5%, move at 2 pulses per second.

this will get you really close really fast, then slow as it gets closer, then tweaks itself into that final balance.

you can adjust the pulse rate for your application.

MorganS: So you want the mirror to find the light source and reflect it to a receiver? Is the receiver position fixed? Is the mirror only rotating on one axis or does it need to look up and down too?

How does "mems" apply to the mirror? What does this mean?

No you don't need a continuous servo. That would be a bad idea. A servo that rotates a full 360 degrees is a little difficult to find but not impossible. But do you really need 360 degrees?

Is the light source continuous? Does it need to be continuous at the receiver? I'm thinking that the mirror could rotate at a fixed speed (100rpm or something) and then it will reflect the source to the receiver, just not all of the time. No, you said it must stop. What if it rotates until the receiver gets a signal and then it stops?

MEMs mirror basically just the device I used for communication, just MLP

It must be 360 degree cause the light source with be coming from all different directions. For this stage, I am just gonna try doing one axis first which is just panning.

Hmm.. the light source is not continuous but might be given in a very short interval. I am thinking to have a fixed platform and rotate just the mirror itself because I realized that if I were to stick to original plan I need to use encoder as well to give a more precise angular position.

dave-in-nj: since you state 360 degrees, your LDR's will each have to 'see' behind their heads.

if sensor #1 is higher than sensor #2, move the motor one way. if sensor #2 is higher than sensor #1, move the other way.

if sensor #3 has a reading, move at least 90 degrees. then look at steps 1 and 2.

sensor #3 being the rear facing sensor, and I would flip a coin to pick which way to move to get the mirror turned to pick up the light. it really does not matter as the two front facing will be the key, that is if they move with the mirror.

if you are going to have multiple LDR sensors that are fixed, and try to move the mirror only, you will need to use a different approach to positioning.

I would use a stepper for this and Robin2 had a great intro into steppers. I hope he can post the link.

for the stepper code, I would have three levels or windows. if LDR1 is move than 20% higher/lower than LDR2, then move at 100 pulses per second. if the difference is 5% to 20% move as 20 pulses per second if the difference is less than 5%, move at 2 pulses per second.

this will get you really close really fast, then slow as it gets closer, then tweaks itself into that final balance.

you can adjust the pulse rate for your application.

I roughly know the concept but I need encoder and such to know where my motor has turned and how much it turned. Maybe I should just turn the mirror itself instead of the whole platform.

I am thinking of stepper too.. but either stepper or servo I will need a limit switch to know where my mirror is facing right?

and yes the mirror position is always fix and same to the receiver as well. Only the platform will be moving accordingly to find the light source and so to reflect back certain signal

MLP? More detail please. The first page of Google results for MLP is all [u]My Little Pony.[/u]

What is the positioning accuracy required? Is the light source 0.5 degrees across (hint: both the sun and the moon are this size as seen from the Earth.) Is the detector 0.5 degrees or bigger? Is it wide or tall - is the accuracy different in different planes?

You have told us nothing about the receiver or what it is supposed to do with this light. That should be your main detector right there. If the target receiver gets a signal then we know the mirror is positioned correctly.

MorganS:
MLP? More detail please. The first page of Google results for MLP is all My Little Pony.

What is the positioning accuracy required? Is the light source 0.5 degrees across (hint: both the sun and the moon are this size as seen from the Earth.) Is the detector 0.5 degrees or bigger? Is it wide or tall - is the accuracy different in different planes?

You have told us nothing about the receiver or what it is supposed to do with this light. That should be your main detector right there. If the target receiver gets a signal then we know the mirror is positioned correctly.

DLP* so sorry LOL, which is digital light processing
it need certain position accuracy, I am planning of just using limit switches. Light source will be just torch light in a dark environment (testing out concept here if it works, will be uisng IR in future) detector I using is just those cheap photoresistors.

The light source and receivers will be stationery, receivers (will be just a camera recording down) is just supposed to receive the light reflected by the mirror. I think main thing I want to archive here is that I need the sensors to sense the light source and response to it by turning the motor to respective place where the sensor sensed something.

sensors are numbered as 1 at 12 olock then increment to the right
I attached a code I wrote, help me take a look thanks.

#include <Servo.h>

Servo panservo;         // servo for panning motion (horizontal)

int pan_pin = 9;        // pin for panning servo

int sens1 = A0;         // declare sensor to respective analog pin
int sens2 = A1;
int sens3 = A2;
int sens4 = A3;
int sens5 = A4;
int sens6 = A5;
int sens7 = A6;
int sens8 = A7;
/*int sens9 = A8;
int sens10 = A9;
int sens11 = A10;
int sens12 = A11;*/

int val1 = 0;           // declare respective sensor value to be 0 (for the start)
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;
int val6 = 0;
int val7 = 0;
int val8 = 0;
/*int val9 = 0;
int val10 = 0;
int val11 = 0;
int val12 = 0;*/

int pos = 90;           // initial value for servo motor (90=stop)
//int tol = ?;          // tolerance limit for LDR

int pin1 = 4;           // declare limit switches to respective digital pin
int pin2 = 5;
int pin3 = 6;
int pin4 = 7;
int pin5 = 8;
int pin6 = 9;
int pin7 = 10;
int pin8 = 11;

int lsw1 = 0;           // declare respective limit switch value to be 0
int lsw2 = 0;
int lsw3 = 0;
int lsw4 = 0;
int lsw5 = 0;
int lsw6 = 0;
int lsw7 = 0;
int lsw8 = 0;

void setup(){
  pinMode(pin1,INPUT);             // set the pin mode to be input
  pinMode(pin2,INPUT);
  pinMode(pin3,INPUT);
  pinMode(pin4,INPUT);
  pinMode(pin5,INPUT);
  pinMode(pin6,INPUT);
  pinMode(pin7,INPUT);
  pinMode(pin8,INPUT);
  
  panservo.attach(pan_pin);   
  panservo.write(pos);
}

void loop (){
  val1 = analogRead(sens1);       // read and store values of LDR
  val2 = analogRead(sens2);
  val3 = analogRead(sens3);
  val4 = analogRead(sens4);
  val5 = analogRead(sens5);
  val6 = analogRead(sens6);
  val7 = analogRead(sens7);
  val8 = analogRead(sens8);
  /*val9 = analogRead(sens9);
  val10 = analogRead(sens10);
  val11 = analogRead(sens11);
  val12 = analogRead(sens12);*/
  
  lsw1 = digitalRead(pin1);       // to determine whether limit switch is pressed or not
  lsw2 = digitalRead(pin2);
  lsw3 = digitalRead(pin3);
  lsw4 = digitalRead(pin4);
  lsw5 = digitalRead(pin5);
  lsw6 = digitalRead(pin6);
  lsw7 = digitalRead(pin7);
  lsw8 = digitalRead(pin8);
  
  
  //int avgL = (val7+val8+val9+val10+val11)/5;   // calculate average reading of left(horizontal)
  //int avgR = (val1+val2+val3+val4+val5)/5;     // calculate average reading of right(horizontal)
  int avgR = (val2+val3+val4)/3;
  int avgL = (val6+val7+val8)/3;
  int LRdiff = abs(avgL-avgR);                   // calculate difference of left and right
  
  if((val1 > avgL)&&(val1 > avgR)&&(val1 > val5)){             // if sensor 1 sensed stronger light
    panservo.write(15);                                        // turn the motor
    if(lsw1 == 1)                                              // stop the motor when limit switch is pressed
      panservo.write(pos);                                     
  }
  
  if((val5 > avgL)&&(val5 > avgR)&&(val5 > val1)){             // if sensor 5 sensed stronger light 
    panservo.write(15);                                        // turn the motor 
    if(lsw5 == 1)                                              // stop the motor when limit switch is pressed
      panservo.write(pos);
  }
  
  if((LRdiff <= -1*tol)||(LRdiff >= tol)){          // check if the difference are within the tolerance
    if(avgL > avgR){                                // check if left side sensed stronger light than right side
      if((val6 > val7)&&(val6 > val8)){             // if sensor 6 sensed stronger light 
        panservo.write(15);                         // turn the motor left
        if (lsw6 == 1)
          panservo.write(pos);                      // stop the motor when limit switch is pressed            
      }
      if((val7 > val6)&&(val7 > val8)){             // same function just diff sensor
        panservo.write(15);
        if (lsw7 == 1)
          panservo.write(pos);
      }
      if((val8 > val6)&&(val8 > val7)){             // same function just diff sensor
        panservo.write(15);
        if (lsw8 == 1)
          panservo.write(pos);
      }
    }
    if(avgR > avgL){                                // check if right side sensed stronger light than left side
      if((val2 > val3)&&(val2 > val4)){             // same function just diff sensor
        panservo.write(165);
        if (lsw2 == 1)
          panservo.write(pos);
      }
      if((val3 > val2)&&(val3 > val4)){             // same function just diff sensor
        panservo.write(165);
        if (lsw3 == 1)
          panservo.write(pos);
      }
      if((val4 > val2)&&(val4 > val3)){             // same function just diff sensor
        panservo.write(165);
        if (lsw4 == 1)
          panservo.write(pos);
      }
    }
  }  
}