I am reading 5 different photoresistors through the analog inputs on an Arduino Uno, which are set up in a plus sign. I am trying to find which photoresistor picks up the most light. How do I code this task?
Welcome to the forum
How is the data from the sensors held ?
How often do you want to know which is the greatest reading ?
Do you want to know what the reading is or just which sensor is most illuminated ?
Please post your current sketch, using code tags when you do
Not sure what that means?
But to get the max, see this:
https://www.tutorialspoint.com/get-max-and-min-values-of-an-array-in-arduino#:~:text=One%20uses%20the%20max(),of%20a%20and%20b%20respectively.
here's a slightly different approach
const byte PinAnlg [] = { A0, A1, A2, A3, A4 };
const int Nanlg = sizeof(PinAnlg);
int anlgVal [Nanlg];
int idxMax;
char s [90];
void loop()
{
idxMax = 0;
for (int n = 0; n < Nanlg; n++) {
anlgVal [n] = analogRead (PinAnlg [n]);
if (anlgVal [idxMax] < anlgVal [n])
idxMax = n;
}
sprintf (s, " max idx %d, val %6d", idxMax, anlgVal [idxMax]);
Serial.println (s);
delay (1000);
}
void setup() {
Serial.begin (9600);
}
but why in the shape of a + sign? are you using the device to track a light source? if so, do you want to determine the difference in light intensity between opposite sides of the + sign?
if there a purpose for the center detector? can you just average the 4 other detectors
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.