Here is the set up:
Right now I have an IR emitter and an IR receiver in slots on polar opposite walls of a tube. I need them to be able to detect a stoppage of flow within the tube. The tube is vertical and the flow will be a metal powder. I am using a 10 value averaging array and subtracting ambient IR from emitted IR (see code). IR emitter is turned on and off by a digitalWrite from an Arduino mega. IR emitter is connected to the 5V rail through a 100k ohm resistor and the analog read wire is connected to the node between the IR sensor and the resistor.
Here is my plan:
I plan to start the metal powder flow (due to gravity, from a hopper full of powder) and take an initial reading of the IR. Then when the metal powder hopper empties, the IR will be blocked less and the sensor should increase its output. this will allow me to detect when the hopper is empty and done flowing.
Here is my function: (it works well and is very consistent)
int readIR(int times) {
for (int x = 0; x < times; x++) {
digitalWrite(IRemitter, LOW); //turning the IR LEDs off to read the IR coming from the ambient
delay(10); // minimum delay necessary to read values
ambientIR = analogRead(IRpin); // storing IR coming from the ambient
digitalWrite(IRemitter, HIGH); //turning the IR LEDs on to read the IR coming from the obstacle
delay(10); // minimum delay necessary to read values
obstacleIR = analogRead(IRpin); // storing IR coming from the obstacle
value[x] = ambientIR - obstacleIR; // calculating changes in IR values and storing it for future average
}
for (int x = 0; x < times; x++) { // calculating the average based on the "accuracy"
powder += value[x];
}
return (powder / times); // return the final value
}
The Problem:
I don't think the metal powder will be able to block enough light. My code displays an average value of 1127 when the tube is empty and down to 1098 when I stick a drill bit between the sensor and emitter. This drill bit is blocking more of the light than the metal powder will. I need to somehow adjust my set up to have the obstacle bring down the reading much more. I am loosing a lot of fidelity with the reading currently.
Any suggestions?