Go Down

Topic: Building a Tubidity meter (Read 2502 times) previous topic - next topic

Gustavohbo

#60
Nov 16, 2020, 07:35 pm Last Edit: Nov 16, 2020, 07:37 pm by Gustavohbo
Quote
Gustav, you need to get the sensor part working first.  You also need to understand the behaviour of the devices you are using.
I know, that is what I am trying to do but now I am having some problems with how the phototransitor work and which resistor I must use.
Quote
measure the current through the phototransistor, so connect it to +5 and your resistor to ground.
1: DETAIL what are the device part numbers?
I did not understand this part is that what you mean?

And I dont know what is part number, is that the datasheet, if so here it is.


Gustavohbo

Hi,
Can you please post a  picture of your phototransistor please?
You are  sure you are connected to the correct legs?
What is the part number off the phototransistor?

Thanks... Tom... :)
In the begging I was making some mistakes with the phototransistor legs but now I already fixed it. The longer is at GND and the shorter is at 5V. And about the part number I already anserwered in the previous post. Thank for your help 

Gustavohbo

Is the sensor in the dark or is it exposed somehow to daylight?
It was exposed but i did this test at night so there was no ilumination besides the light bulb. 
Today I did some tests during the morning and the 22k resistor reduced the reading to about 570

dlloyd

Some things to think about or experiment with: (sorry, I didn't read through all the previous replies)

What range of operation do you need?
When looking at the ADC, you have 0-1023 which would represent 0-5V on the analog input.
When looking at the phototransistor, check the "Collector Current vs. Irradiance curve" ... it only shows 1 one order of magnitude in range, however if you extend the line to the left down to 0.01mA (dark current) there's really 3 orders of magnitude. Therefore, the maximum range of the phototransistor is from dark current (0.01mA) to 10mA (on the graph) ... absolute max is 20mA.
Ideally you would use the full range of the ADC for the desired operating range of the turbidity meter.

Max Reading Calibration:
For example, say you'd like to use a range of 0.1mA to 10mA representing analog reads of 10 to 1000. If you wire up the phototransistor so that its collector is at 5V and the resistor is from emitter to GND, then the signal will go lower as the light levels get darker and increase for increasing light levels. The minimum reading will be difficult to calibrate, but it could be measured and utilized in your code. To calibrate for maximum reading, first, get a good level of infrared light ... for example, 100 to 220 ohm in series with the IRLED. Then, use a resistor in series with the emitter that gives close to 1000 ADC count with clear liquid.

Grumpy_Mike

#64
Nov 16, 2020, 10:01 pm Last Edit: Nov 16, 2020, 10:04 pm by Grumpy_Mike
The resistor in that photograph seems to show an IR LED, with a 10K resistor. That is way too high to give you a decent amount of light. You need something like a 47R for that.

Quote
is that the datasheet
Well the LED data sheet shows a clear housing, so if that part is the IR emitter it is not the data sheet for the one you have.

Gustavohbo

#65
Nov 16, 2020, 11:09 pm Last Edit: Nov 16, 2020, 11:16 pm by Gustavohbo
The resistor in that photograph seems to show an IR LED, with a 10K resistor. That is way too high to give you a decent amount of light. You need something like a 47R for that.
Well the LED data sheet shows a clear housing, so if that part is the IR emitter it is not the data sheet for the one you have.
No I think the way that it is wired to the bread board confused you.
The picture represents the way that johnerrington requested me, so I could measure the current through the phototransistor
The black one is the phototransistor and the clear one is the Infrared LED.

Gustavohbo

Some things to think about or experiment with: (sorry, I didn't read through all the previous replies)

What range of operation do you need?
When looking at the ADC, you have 0-1023 which would represent 0-5V on the analog input.
When looking at the phototransistor, check the "Collector Current vs. Irradiance curve" ... it only shows 1 one order of magnitude in range, however if you extend the line to the left down to 0.01mA (dark current) there's really 3 orders of magnitude. Therefore, the maximum range of the phototransistor is from dark current (0.01mA) to 10mA (on the graph) ... absolute max is 20mA.
Ideally you would use the full range of the ADC for the desired operating range of the turbidity meter.

Max Reading Calibration:
For example, say you'd like to use a range of 0.1mA to 10mA representing analog reads of 10 to 1000. If you wire up the phototransistor so that its collector is at 5V and the resistor is from emitter to GND, then the signal will go lower as the light levels get darker and increase for increasing light levels. The minimum reading will be difficult to calibrate, but it could be measured and utilized in your code. To calibrate for maximum reading, first, get a good level of infrared light ... for example, 100 to 220 ohm in series with the IRLED. Then, use a resistor in series with the emitter that gives close to 1000 ADC count with clear liquid.
Thanks for your help, I think that what you said will be very helpful
But I dont get it, what is the real difference between using the ADC 'scale' and the phototransistor 'scale'? They have about the same range
So the difference between a pull-up resistor and a pull-down resistor is the interaction with reading? 
Pull-down is no light is 0 and direct light 1023 and Pull-up is no light 1023 and direct light 0

dlloyd

Quote
But I dont get it, what is the real difference between using the ADC 'scale' and the phototransistor 'scale'? They have about the same range
Its good if you can achieve 0 to full scale swing on the ADC (0-1023). However, what if the reading stays at 0 until 30% light and rises to 1023 when the light level increases to 50%? In this case, you'll read 1023 for direct light (100%) and 0 for no light (0%) but your meter will have "tunnel vision". Here, 80% of what needs to be within measurement range is excluded. Other possibilities are some of the upper range or lower range excluded, therefore choosing the resistor(s) value is important. Ideally, the range in light levels to be measured will use up most of the ADC range available.

Quote
So the difference between a pull-up resistor and a pull-down resistor is the interaction with reading?
Pull-down is no light is 0 and direct light 1023 and Pull-up is no light 1023 and direct light 0?
With resistor on the collector end of the phototransistor (pullup) the signal level decreases for increasing light levels.
With resistor on the emitter end of the phototransistor (pulldown) the signal level increases for increasing light levels.
Each connection method operates inversely to the other. Also, the recorded signal's response can be "flipped" in your code if needed. For example: Reading = 1023 - analogRead(photoTransistor);

johnerrington

#68
Nov 17, 2020, 07:32 am Last Edit: Nov 17, 2020, 07:42 am by johnerrington
@Gustav great progress. Thanks for data sheets too - sorry I didnt spot them in your second post.

Part numbers

Phototransistor is PT333-3B,

important characteristics are
dark current 100nA &
On State Collector Current 3mA

Emitter is 5mm Infrared LED,T-1 3/4IR333C/H0/L10

important characteristics are
Forward voltage Vf = 1.4V at If = 20mA

Lets get the idea working first and deal with any problems as we meet them.

You need to drive your LED with a square wave from the NANO. An output pin can provide up to 40mA max but lets just go for 20mA. Vol is about 0.7V at 20mA and Vf for the diode about 1.4
so we have 5V -(0.7 +1.4) = 2.9V left and 2.9V 20mA = 150 ohms

If the phototrans is passing 3mA when the LED is ON then you need 3mA 5V = 1k6, 2k2 or so

schematic looks like this



run the program and tell us the high and low value readings

Code: [Select]
/* copied from arduino examples
  Blink - Turns on an LED on for one second, then off for one second, repeatedly.
  AnalogRead example
  This example code is in the public domain.
 */
 
int led = 4;
int det = A0;
int val = 0; //value from adc

void setup() {                
  pinMode(led, OUTPUT);  // initialize the digital pin as an output.
 Serial.begin(9600);           //  setup serial  
}

void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  val = analogRead(det);  // read the input pin
  Serial.println(val);          // debug value
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  val = analogRead(det);  // read the input pin
  Serial.println(val);
  delay(1000);               // wait for a second
}




I'm trying to help. If I find your question interesting I'll give you karma. If you find my input useful please give me karma (I need it)

Gustavohbo

#69
Nov 17, 2020, 09:50 pm Last Edit: Nov 17, 2020, 09:51 pm by Gustavohbo
run the program and tell us the high and low value readings
Thanks for your help, I did every this as you said and the results are:
The LED is immediately in front of the phototransistor about 5mm apart from each other
When the LED is ON the output is about 1000 and when it is OFF the output is about 30.
I noticed that if I cover the phototransitor with my hand while the LED is OFF the readings decrease more, to about 3 a few times even 0.
Where did you make this schematic?
And what does dark current mean?

raschemmel

Do you have a test chamber and some method to simulate the turbidity range ?

johnerrington

Hi Gustav..
Those are great results, couldnt be better.
Quote
I noticed that if I cover the phototransitor with my hand while the LED is OFF the readings decrease more, to about 3 a few times even 0.
Yes - the phototransistor is sensitive to light.

Quote
Where did you make this schematic?
How to make a schematic you can post.


Quote
what does dark current mean?
https://en.wikipedia.org/wiki/Dark_current_(physics)

Your next steps - modify the code to subtract the dark value (LED off) from the light value (LED on)
and reduce the delay to 10msec.
I'm trying to help. If I find your question interesting I'll give you karma. If you find my input useful please give me karma (I need it)

Gustavohbo

Do you have a test chamber and some method to simulate the turbidity range ?

Unfortunately due to Corona Virus pandemic I am not able to frequent the university, so I dont have a proper method to simulate the turbidity, but I have some 3D printed test chambers that I am using to test.
But for now I am trying to understand and make the phototransistor work as expected.



raschemmel

Well, actually I didn't mean anything that fancy. I just meant a 1/2" diameter glass beaker with various percentage'
mixtures of some powder that blocks light so you can vary the light intensity by varying the mixture percentage.
I'm not a chemist or artist so I wouldn't have a clue what powder particles would work best. It only needs to be 1"
high so size is not an issue. Most of the work would be experimenting to find a suitable powder.

Gustavohbo

Your next steps - modify the code to subtract the dark value (LED off) from the light value (LED on)
and reduce the delay to 10msec.
Ok, but why? what does the result of this subtraction mean?
When I copy and paste the code that you send to me te output is not as god as the one I said before, I have add another two delay, right after the digitalWrite that controls the LED.
If i run the code as you sent the results are:
ON: 993    OFF: 886    ->     ON: 994    OFF: 924    ->   ON: 995    OFF: 925
Code: [Select]

void loop() {
  digitalWrite(led, HIGH);  
  delay(100);               // NEW DELAY
  val = analogRead(det);  
  Serial.print("ON: ");
  Serial.println(val);          
  delay(1000);              
  digitalWrite(led, LOW);    
  delay(100);               // NEW DELAY
  Serial.print("OFF: ");
  val = analogRead(det);  
  Serial.println( val);
  delay(1000);              
}


I did as you said and this is the output:
ON: 972 OFF: 4 Subtraction: 968
ON: 972 OFF: 3 Subtraction: 969
ON: 972 OFF: 3 Subtraction: 969

Basically I added this 2 lines at end and reduced all for delays to 10miliseconds
Code: [Select]
Serial.print("\tSubtraction: ");
Serial.println(val1 - val2);  //Subtract the output when the LED is ON from OFF





Go Up