I have a custom proof-of-concept project to detect fluid color within a PVC tube coming out of a patient's brain and turbidity (a reduction in light passing through) using an Arduino micro, a TCS3200 sensor, and an LED. The tube sits in a custom housing, and the LED shines from the other side and passes through it.
This is the TCS3200 set inside a PLA dark chamber:
Tube passes through this chamber:
Very very crude diagram of the setup:
I've found out that, interestingly, the sensor output increases nearly fifty-fold when I measure with an LED with low resistance (220 Ω resistor, 5 V) compared to (68 kΩ, 5 V, to obtain 100~ measurements of clear when I'm measuring distilled water).
Here are the recordings over 5 minutes, averaging 7 standardized fluids and the empty tube. Both for 66 kΩ and 200 Ω. I feel like the numbers I'm getting from here are basically noise at 220 Ω.
I also measured absorbance using a standard spectrophotometer and "reversed" it in the color scale to its appropriate color (since absorbance gives the wavelength of blue when the fluid is red, for instance).
Test 0: Empty tube.
Test 1: Distilled water.
Test 2: 1:10 dilution of a yellow drug.
Test 3: 1:100 dilution of a yellow drug.
Test 4: 1:100 dilution of a red drug. (due to the max absorbance of being limited by the spectrophotometer, this is not a good test)
Test 5: 1:1000 dilution of a red drug. (The color of the drug got close to yellow at this dilution, effectively leaving me with only two standard fluids)
Test 6: 1:1000 dilution of a blue drug.
Test 7: 1:10k dilution of a blue drug.
I'm using this LED to shine light on the TCS3200 sensor:
And here is the linearity data for the TCS3200 sensor: ±0.1% for output frequencies between 0 to 5 kHz ±0.2% for output frequencies between 0 to 50 kHz ±0.5% for output frequencies between 0 to 500 kHz
I can see that the values of the low-intensity (68 kΩ) LED light are more in line with the real color and have more sensitivity compared to the 4000~ sensor readings I'm getting.
I don't think the code is exactly relevant, but for completeness sake, here is the color sensor bit:
void readColor(int &colorCount, int S2State, int S3State) {
// Setting frequency scaling to 20%
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
digitalWrite(S2, S2State);
digitalWrite(S3, S3State);
unsigned long startTime = millis();
colorCount = 0;
int dynamicMeasurementTime = 50;
unsigned long currentTime = millis();
while (currentTime - startTime < dynamicMeasurementTime) {
int pulseWidth = pulseIn(sensorOut, LOW, pulseTimeout);
if (pulseWidth > 0) {
colorCount++;
}
currentTime = millis();
}
My question is, why is it recording this very high, probably filled with noise values when the LED is bright?
Also, what would be a good way to correlate the wavelength readings to the RGB sensor outputs?