Reading data from sensor

Hello ,

I have a question related to the data that I get from the photoresistor sensor.

I would like to make the program in such a way that it reads the values from the sensor for a certain period and after that I want to know at which moment the data from the sensor is at the highest point. I tried to use the variable “timer” but it counts how many times the sensor value was increased.

Can you give any suggestions how to read at which moment the received analog value is highest?

const int sensorPin = A3;

int var = 0;
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value
int sensorValue = 0;
int timer = 0;

void setup() {

Serial.begin(9600);
}

void loop() {

while (var < 10)
{
Scanning();
delay(1000);
var++;
}
Serial.print("sensor max = “);
Serial.print(sensorMax);
Serial.print(”\t sensor min = “);
Serial.println(sensorMin);
Serial.print(”\t round = ");
Serial.println(timer);

delay(5000);
sensorMin = 1023;
sensorMax = 0;
var = 0;
timer = 0;
}

int Scanning() {

// the sensor value
sensorValue = analogRead(sensorPin);

// record the maximum sensor value
if (sensorValue > sensorMax) {
sensorMax = sensorValue;
timer++;
}

// record the minimum sensor value
if (sensorValue < sensorMin) {
sensorMin = sensorValue;
}
}

Reading_photoresistor.ino (870 Bytes)

unsigned long timer;
...
...
...
...
  if (sensorValue > sensorMax) {
    sensorMax = sensorValue;
    timer = millis ();
  }