Note: [I am approximately two weeks into learning Arduino and hence have little experience with utilizing Phototransistors.]
My plan revolves around placing four identical Phototransisors which are spread approximately 10cm apart on a breadboard in a V configuration. Each Phototransistor is connected to one of the "analog In" pins respectively (I am using the Arduino Uno), with the long leg attached to 5V while the short leg is connected to ground via a 220-ohm resistor. In the center of this setup, I plan to place a servo that will face the direction of the light beam emitted from a flashlight.
(I want this project to be allocated in a dark room with any external lighting calibrated),The idea is to identify the phototransistor which has the highest analog value (closest to the light source). With this information, I want to be able to compute an approximate angle of the light source to then write it on my servo.
You can find the attached datasheets below (All the components are from the Arduino starter kit :) ).
[Datasheet for the Phototransistor]
[Datasheet for the Servo motor]
[Datasheet for the 220 ohm Resistor]
Here is what I have so far for the code:
#include <Servo.h>
Servo myServo;
const int transistorPin1 = A0;
const int transistorPin2 = A1;
const int transistorPin3 = A2;
const int transistorPin4 = A3;
void setup() {
myServo.attach (10);
Serial.begin (9600);
}
void loop() {
int reading1 = analogRead (transistorPin1);
int reading2 = analogRead (transistorPin2);
int reading3 = analogRead (transistorPin3);
int reading4 = analogRead (transistorPin4);
int reading [] = {reading1, reading2, reading3, reading4}; //This is an array for the values:
int maxReading = reading [0], maxSensor = 1; // I am setting the maximum reading and the Phototransistor that corresponds to it:
for (int i = 1; i <= 3; i++){ //Setting this for the other three phototransistors:
if (reading[i] > maxReading){
maxReading = reading[i];
maxSensor = i + 1;
}
}
}
So my question is: What is the most efficient way to compute the angle of the lighsource? And is my method even relevant for this application?
Thank you for taking you time to read this! Your support will be very much appreciated!
Edit 1:
Explanation of my hardware setup:
This project is allocated on two connected breadboards which means that there are no moving parts. The only moving component is the one single servo that is fixed in position.
The phototransistors, (as mentioned above), are placed in a V configuration which too are stationary. The servo is allocated behind the phototransistors and can only rotate 180 degrees. (You can see the attached illustrations below, I apologize in advance for any technical errors or my horrible drawings.)


As you can visualize on the first image, I do not plan on a complete 360 degree rotation which probably complicates the issue further. Any suggestions on how I can code this would be greatly appreciated! Once again thank you for your time.