Go Down

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

johnerrington

#30
Aug 18, 2020, 08:53 am Last Edit: Aug 18, 2020, 09:18 am by johnerrington
OK Gustav, you will know that low energy (infra-red 800 - 1000nm) will penetrate MUCH better than high energy (blu-violet 380 - 480nm)

unfortunately silicon (& germanium) photodevices are MUCH more sensitive to infra-red (peak typically 900nm) and have little sensitivity to blue light.

So ideally you'ld like a detector that is uv/blue sensitive.  You could use a VEML6070 and pair it with a UV LED.

As a compromise I'd recommend you use a high intensity blue LED (around 460nm) - or even white - and a silicon phototransistor that DOES NOT HAVE  a black coating.

Ebay - loads for little money (a few pence).  EG
https://www.ebay.co.uk/itm/IR-Infrared-Visible-Phototransistor-450mn-1070nm-50-3mm-2-Pin-Osram-SFH-310/302831495809?hash=item468229ea81:g:yvAAAOSwqvNaT~g0

An interesting alternative would be to use an LED as a detector (yes you can)
https://wiki.analog.com/university/courses/electronics/electronics-lab-led-sensor?rev=1551786227
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)

Paul__B

How do I filter the light/signal that the phototransistor is reading?
It's not so much filtering the light, but restricting the light coming in to that from the LED as far as possible.  As to the signal, you may need an amplifier (op-amp) between the photodiode and the analog input.

And how do I modulate the frequency of the LED?
The LED is switched on and off by the same Arduino that you use to read the photodiode.  So you take successive readings when the LED is turned on and when it is turned off, in order to compare them.


Gustavohbo

#32
Aug 19, 2020, 07:35 pm Last Edit: Aug 19, 2020, 08:41 pm by Gustavohbo
It's not so much filtering the light, but restricting the light coming in to that from the LED as far as possible.  As to the signal, you may need an amplifier (op-amp) between the photodiode and the analog input.
So what you meaning is that the phototransistor must be in dark and somewhere that heat and other kind of interference doesnt reach it?

The LED is switched on and off by the same Arduino that you use to read the photodiode.  So you take successive readings when the LED is turned on and when it is turned off, in order to compare them.
But how do i do this switch?
I saw one video using delay() but if my code bigger the delay will not work as expected.

Code: [Select]
void setup() {
  Serial.begin(9600);
  pinMode(4, OUTPUT);
  pinMode(A3, INPUT);
}

void loop() {

    digitalWrite(4,HIGH);
    delay(13);
    Serial.println(analogRead(A3));
    digitalWrite(4,LOW);
    delay(13);
    Serial.println(analogRead(A3));
}

I tried this code just to see what would happen.
LED emissor -> pin 4
Phototransistor -> pin A3
When the LED is on it gives near 600 and when it is off it gives 1023

Gustavohbo

So ideally you'ld like a detector that is uv/blue sensitive.  You could use a VEML6070 and pair it with a UV LED.

As a compromise I'd recommend you use a high intensity blue LED (around 460nm) - or even white - and a silicon phototransistor that DOES NOT HAVE  a black coating.

Thanks for you help!
Now i just have some infrared kit and white LED's.
I will try to build the sensor white infrared and measure it behavior, if it works as expected maybe I will try to improve it with the LED and UV sensor.

Gustavohbo

Mike
I found this code that you posted in an old topic about modoluting a LED and I wanted to know if I copy and paste it will work in a arduino nano.
And how does it work?

Code: [Select]
/* Code to pulse pin 3 with a modulated signal
* Can be used to drive an IR LED to keep a TSOP IR reciever happy
* This allows you to use a modulated reciever and a continious beam detector
* By Mike Cook Nov 2011 - Released under the Open Source licence
*/
volatile byte pulse = 0;

ISR(TIMER2_COMPB_vect){  // Interrupt service routine to pulse the modulated pin 3
    pulse++;
  if(pulse >= 8) { // change number for number of modulation cycles in a pulse
    pulse =0;
    TCCR2A ^= _BV(COM2B1); // toggle pin 3 enable, turning the pin on and off
  }
}

void setIrModOutput(){  // sets pin 3 going at the IR modulation rate
  pinMode(3, OUTPUT);
  TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); // Just enable output on Pin 3 and disable it on Pin 11
  TCCR2B = _BV(WGM22) | _BV(CS22);
  OCR2A = 51; // defines the frequency 51 = 38.4 KHz, 54 = 36.2 KHz, 58 = 34 KHz, 62 = 32 KHz
  OCR2B = 26;  // deines the duty cycle - Half the OCR2A value for 50%
  TCCR2B = TCCR2B & 0b00111000 | 0x2; // select a prescale value of 8:1 of the system clock
}

void setup(){
  setIrModOutput();
  TIMSK2 = _BV(OCIE2B); // Output Compare Match B Interrupt Enable
}

void loop(){
// do something here
}

Grumpy_Mike

Quote
if I copy and paste it will work in a arduino nano.
Yes.

Quote
And how does it work?
It changes the registers that control Timer 2 in the chip. This timer controls two of the PWM generators and by altering the prescaller of the timer's input it changes the frequency. The names in all capitals are the internal register addresses. You can look them up in the data sheet of the 328 processor which is used both in the nano and the Uno.
Timer operations can be hard to understand because what is important is what individual bits are changed in these registers. The collection of bits make up the number you put into them, but the numbers themselves don't have any meaning other than defining the bit pattern.

The TSOP series of detectors have built in tuned amplifiers to help with the rejection of ambient light. They are mainly used for TV remote controls.

Quote
But how do i do this switch?
By using the analogue multiplexers you mentioned previously.

Gustavohbo

The TSOP series of detectors have built in tuned amplifiers to help with the rejection of ambient light. They are mainly used for TV remote controls.
If i use this code with the phototransistor that i have it will work as expected but it could suffer of ambient light inteferrence?

By using the analogue multiplexers you mentioned previously.
Like the 555?
Just to be sure, if I use one of this i will not need your code?
Thanks for explainig the code!

johnerrington

You can use this code
https://www.arduino.cc/en/tutorial/BlinkWithoutDelay
and just change the interval from 1000 to say 43.
That will give you a 43ms on & off.
then in this bit of the code
Code: [Select]
// if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }


add in lines to measure the transistor level when LED ON & OFF and subtract to get the difference.
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)

Grumpy_Mike

Quote
Like the 555?
No the 74HC4066.

Quote
If i use this code with the phototransistor that i have it will work as expected but it could suffer of ambient light inteferrence?
There is no point in modulating the LED, if you do not use a tuned amplifier on the receiver, and the tuned amplifier is what gives the light sensor some degree of ambient noise immunity. Ever with a modulated light source and tuned amplifier too much ambient light can saturate the light sensor and so you will not be able to do your measurements.

Gustavohbo

Ever with a modulated light source and tuned amplifier too much ambient light can saturate the light sensor and so you will not be able to do your measurements.
I understand but in my project the phototransistor will be covered or inserted in a structure like a 3D printer adapter so I guess the ambient light will not interefere that much.

My partener and I were doing some tests and we noticed that the reading wasnt stabilizing so we thought that the temperature was interfering the results.
Does the temperature can interfere the reading of signal?
If so is this interfance substancial?

Grumpy_Mike

Quote
Does the temperature can interfere the reading of signal?
Not in the way you are experiencing. Temperature changes would affect the signal level but only on the time scale of the temperature changes.

There are many reasons why the signal was not stabilising, one might be if the sample fluid was in motion. 

Paul__B

There are many reasons why the signal was not stabilising, one might be if the sample fluid was in motion.  
That would be the very first thing to consider!  :smiley-roll:

johnerrington

Fascinating project. Can you give us some more detail about your experimental set-up? (eg a diagram or sketch?)
and also on the characteristics of the liquid you are using, as if its homogeneous this may not work?

Quote
In turbulent flow the speed of the fluid at a point is continuously undergoing changes in both magnitude and direction.
So you should not expect a smooth signal. Perhaps you could do a statistical analysis of the variations you are seeing; in any case, the fact you ARE seeing variation is a good sign your messurement system is working.

Are you measuring transmitted or 90 degree scattered light? or both? and how are you collimating the light from the LED?
https://publiclab.org/questions/warren/12-18-2017/can-a-diy-spectrometer-be-used-to-measure-water-turbidity
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)

Nazaar--

I've used scientific turbidity meters in the field, and even the ones with 2ml cuvettes don't fully stabilise within a minute or so. The meters just look at the readings and lock them when they're relatively stable.

Gustavohbo

There are many reasons why the signal was not stabilising, one might be if the sample fluid was in motion. 
I am aware of this, for now I am testing it in small scale prototype that I put and take out the water.
If the prototype works fine I will install it on my home plumbing and with it a flow sensor so I the turbidity sensor will only measure the turbidity when there is no flow.

Go Up