Calibrating an array of sensors

Ok, so the short of it I made an array of IR transistor sensors but readings across them isn't equal, each sensor reading corresponds to a color of an LED in a strip. Making each LED different color in the default state, making each LED slightly or completely different color, when they supposed to be the same :confused: Is there a way to calibrate the array in the program,

 #include <FastLED.h>

 
 #define COLOR_ORDER      GRB
 #define LED_TYPE         WS2811        
 #define LED_PIN          5
 #define NUM_LEDS         9           
 #define MAX_BRIGHTNESS   50    
 #define MIN_BRIGHTNESS   50     
 #define BRIGHTNESS       50
 #define SPEED            1000
 
 struct CRGB leds[NUM_LEDS];
 

 const int numOfInputs = 3;
 const int inputPins[numOfInputs] = {0,1,2};


 unsigned int analogVal[numOfInputs];
 int analogPin[] = {0,1,2};
 int digitalPin []={2,3,4};

 int counter;
 
unsigned int analogSensorRead[2];

 int i;
 int j;
 
 int hue;
 int mappedHue;
 int LEDno;
 
void setup() {
  Serial.begin(9600);   
  
  LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
  

    for (int counter=0; counter <= 2; counter++){       
      pinMode(digitalPin [counter], OUTPUT);

    }
}
void loop() {
  
  for(int i=0; i<=2; i++){
    
    digitalWrite(digitalPin[i], HIGH);

        
      for(int j=0; j<=2; j++){

         LEDno = ((numOfInputs-1)*i+i+j);
        delay(5);
        analogSensorRead[j] = analogRead(analogPin[j]);
       //Serial.println((String) +"Sensor  "+ LEDno + " Value: " + analogSensorRead[j]);
       //Serial.println((String) +"Row "+ i + " Column " + j + " Value: " + analogSensorRead[j]);
       //Serial.println(analogSensorRead[i][j]);
       
         
             hue = (analogSensorRead[j]);
             mappedHue = map(hue, 0, 1023, 0, 255);
             leds[LEDno] = CHSV(mappedHue, 255, 255);   
           //Serial.println((String) +"LED  "+ LEDno + " Value : " + hue);
           //delay(300);
             FastLED.show();
        
      }
    digitalWrite(digitalPin[i], LOW);  
    
    
  }
}

The code works well and each LED changes color with an appropriate LED
but the min and max values for each sensor are different messing up the aesthetic of it.

Edit:
accidentally clicked post instead of preview heres what it looks like and yes 3 sensors dont work properly but it was just a test anyway, Led Matrix Test GIF | Gfycat

Why do want to measure the IR output of various visible light LEDS? Are your IR sensors all from the same manufacturer and lot number? IF not there is no way they could give the same value for the same light.

Paul

I'm measuring the voltage between the resistor that is connected to the IR transistor, depending on the intensity of light it gets from an IR LED it has a different potential difference. Hence voltage changes with the distance of the object above the sensor, the idea is the same as with a LDR voltage divider. I just need a way of calibrating it so when nothing is near I get an even color.

Light intensity and color (wavelength) both affect the output of the IR photodiode or transistor. There is no way to separate the two effects.

The typical wavelength response curve of an IR photodiode looks like this:

The accuracy isn't my goal, it's just for the coffee table or something similar. I just have no idea how to calibrate the array, there should be little light from the led strip anyway most should come from a separate IR LED.

I still cannot grasp the purpose of your project :frowning:

How is a coffee table related to IR sensor readings?

when so,something is placed above the sensor it will change the color of the led below.

"most should come from a separate IR LED." There's not much light that comes from an IR Led!

But maybe this project could be made more practical by making it indicate when your coffee is getting cold.

I'm sure I saw a YouTube video recently doing exactly what your proposing.

Regards

Bill

Hi

If i understand corectly, your problem is that your sensors dont output the same values according to light intensity from distance, eg sensor 1 gives say 1023 and sensor 2 gives 578 and sensor 3 gives 897 ... under the same conditions.

And you ould like them to give the same values under the same conditions.

If that is the case , just off-hand i can see 2 solutions:

One would be to determine the max and min value of each sensor and map the value according to those. Basically this gives you relative values rather then absolute.

The other solution is , i presume you use a voltage divider to read the phototransistors. You could adjust the resistor values so they output the same value . You could use pots instead of resistors, at least temporary until you find the sweet spot value

Yes, that's exactly it. I'd rather do it in the software since the amount of sensors can get overwhelming, I want something like 15x15 at least, working with 3x3 for testing tho. Calibrating individual sensors isnt much of an issue but I just cant figure out how to do it in the array

void calibrate(){
    for(int i=0; i<=2; i++){
    
    digitalWrite(digitalPin[i], HIGH);

        for(int j=0; j<=2; j++){

// save values for each sensors default and max state, the bit I cant figure out

digitalWrite(digitalPin[i], LOW);
   }
 }

it's just a test rig but works for trouble shooting

Edit:
here's what i get back from the serial monitor
LED 0 Value : 52
LED 1 Value : 96
LED 2 Value : 5
LED 3 Value : 51
LED 4 Value : 165
LED 5 Value : 7
LED 6 Value : 7
LED 7 Value : 180
LED 8 Value : 219

alexs_tech:
The other solution is , i presume you use a voltage divider to read the phototransistors. You could adjust the resistor values so they output the same value . You could use pots instead of resistors, at least temporary until you find the sweet spot value

It should be sufficient to adjust the load resistor for setting the amplification.

Do you already have a plan how to scan 15x15=225 or more analog signals in acceptable time?

Your test results suggest that the transistors are not aligned to the light source as required or catch random ambient light. Use a pulsed light source and determine the ripple on the signal to learn more about your real problems.

If need be I can use multiple arduinos, each resistor and IR transisntor aren't perrfect so values differ slightly, and setting 200 odd pots each time it needs calibrating isn't practical :confused: it's still a problem when they aren't that close to one another, for the actual build i will test each LED and IR tranisitor to get most similar ones but it still wont be perfect, and i want to calibrate it to the ambient light regardless.

I just wrote this but it doesn't let me use the values in the rest of the code and I can't figure out hot to assign a each LedMin value to a corresponding LED hue value

void calibrate () {
    for(int i=0; i<=2; i++){
    
    digitalWrite(digitalPin[i], HIGH);

        for(int j=0; j<=2; j++){

         LEDno = ((numOfInputs-1)*i+i+j);
        delay(5);
        analogSensorRead[j] = analogRead(analogPin[j]-minVal[LEDno]);

                   hue = (analogSensorRead[j]);
                   
  minVal[LEDno] = map( hue, 0, 1023, 5 , 250);
                  
                    
  LedMin0 = minVal[0];
  LedMin1 = minVal[1];
  LedMin2 = minVal[2];
  LedMin3 = minVal[3];
  LedMin4 = minVal[4];
  LedMin5 = minVal[5];
  LedMin6 = minVal[6];
  LedMin7 = minVal[7];
  LedMin8 = minVal[8];

        Serial.println((String) + "0 : " + LedMin0 + " 1 : " + LedMin1 + "... so on");
    }
    digitalWrite(digitalPin[i], LOW); 
  }
}

serial.print ln = (0 : 70 1 : 60... so on)

since there is some confusion I thought I'd update my test rig

Edit:
yes I know some don't work i dropped it one too many times

Here's the link to a YouTube video that shows how someone else achieves this.

Regards

Bill

thanks, but ive seen it ages ago but this one uses the premade sensors and they work as buttons essentially,what im doing is analog, with the way its made id the video you cant get a gradual change of color :confused: also id have to spend a small fortune on the sensors given the size i want