Saving Highest output from multiple sensors

Hi, everyone, it's my first time using this so please excuse me for doing any mistakes.

I am currently working on an autonomous firefighting robot and currently in the stage of moving the robot by means of flame sensors.

(https://grobotronics.com/images/detailed/104/Free-Shipping-font-b-5-b-font-Way-font-b-Flame-b-font-font-b-Sensor.jpg)

I am using 2 of these sensors, therefore, will have 10 analogue pins since each module is 5ch. (attached is a picture describing my concept)

my objective is to have the highest values of both from the group on the left compared with that of the highest in the group on the right. This would result in the robot to turn until both of them are within an acceptable set threshold.

I'd like some help or guidance on how can I achieve the selection of the highest amongst the 5 on the left and the highest amongst the 5 on the right.

Thank you

I'd like some help or guidance on how can I achieve the selection of the highest amongst the 5 on the left and the highest amongst the 5 on the right.

Set a variable, let's name it highestLeft, to zero. Read each left value in turn and if the value is higher than highestLeft copy it to highestLeft and save the sensor number. When all 5 sensors have been read you have the highest value found and the sensor number that it was found on.

I cannot make sense of that sensor module. Is it an "Arduino" or does it communicate with and, if so, how ?

UKHeliBob:
I cannot make sense of that sensor module. Is it an "Arduino" or does it communicate with and, if so, how ?

Hi sir,

Thanks for your help yes these sensors are currently connected to an arduino mega. As for your guidance, yes that is the idea but I'm still trying figure out how to implement the "compare and save part".

For example:
highestleft = 0

left90 = 300
left120 = 350
left150 = 275
left 180 = 170
left 210 = 85

I know that the loop would start to compare each one with the "highestleft". Which in this example will be left120 (350) since no other sensor would read higher at that moment.

My problem is that I don't know how do write it into code =/.

Would you reccomend any notes or books which could help me for this please?

I'm still trying figure out how to implement the "compare and save part".

Put the pin numbers in an array and iterate through them with a for loop

Something like (NOT TESTED)

const byte leftPins[] = {10, 11, 12, 13, 14, 15};  //replace with the real pin numbers
int highestLeft = 0;
byte highestLeftInput;
for (int pin = 0; pin < 5; pin++)
{
  int tempValue = analogRead(leftPins[pin]);
  if tempValue > highestLeft)
    {
      higestLeft = tempValue;
      highestLeftInput = pin;
    }
}

Will be having a go at it.

Thank you so much for your help.

I made the following code, it is doing the job but I'm having an issue. I want it to reset the highestright and highestrightinput every 2.5 seconds for example, yet when implement this I get readings from all 5 sensors. when the code below is removed I have the correct reading of the highest value and the pin but they never reset.

" delay (2500);
highestright = 0;
highestrightinput = 0; "

int rht[] = {0, 1, 2, 3, 4}; // right fire, declare the analog pins for the fire sensors H1-H5
//int pinCount = 5;

int rhtA = 5;

int highestright = 450;

byte highestrightinput;

const int rhtled = 13; // This is digital pin
//const int lftled = 12; // This is digital pin

int threshold_pot = 10; // Use this potentiometer to calibrate the threshold of
// the sensors to the light source.

int closeness = 50; // This value defines when the left and right light
// sensors detect light at a similar enough intensity
// to indicate that the light source is straight ahead.

//int SensorDifference; // Stores absolute difference between left and right

void setup()

{

for (int rhtpin = 0; rhtpin < rhtA; rhtpin++)
pinMode(rht[rhtpin], INPUT);
pinMode(threshold_pot, INPUT);
Serial.begin(9600);

}

void loop()

{
for (int rhtpin = 0; rhtpin < 5; rhtpin++)
{
int tempValue = analogRead(rht[rhtpin]);
if (tempValue > highestright)
{
highestright = tempValue;
highestrightinput = rhtpin;

Serial.println(tempValue);
Serial.println(rhtpin);
}

}
//Serial.println();
delay (2500);
highestright = 0;
highestrightinput = 0;
}

Please do us all a favour. Delete the multiple blank lines from your sketch, Auto Format it in the IDE and use code tags when you post the tidier version here.

delay(2500);

will do nothing for 2.5 seconds. Is that what you want when you say

I want it to reset the highestright and highestrightinput every 2.5 seconds

or should the program continue to read values during the 2.5 seconds. If so, then you will need to use millis() to implement non blocking timing.

See Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

Sorry mate will do next time. I intend to have the loop read the values from the 5 sensors and determine which is the highest. Since this will be implemented on an autonomous firefighting robot I need it to reset all the temporarily stored values, after an "X" amount of time (as in duration).

OK, so delay() will not do what you want so you need to use millis() for timing to allow loop() to run freely and read your sensors

On outline of what I think you need to do

period = 2500 //milliseconds
start time = millis()
set highest value to zero

start of loop()
  read 5 sensors and save highest value so far and its sensor number
  time now = millis()
  if time now - start time >= period  //non blocking time check
    //2.5 seconds has elapsed
    //do whatever you need with highest value and sensor number
    set highest value to zero
    start time = time now
  end if
end of loop()