Building a Tubidity meter

HI, I think you are going to keep having problems if you are trying to read very small DC values.

My approach would be to modulate the light source and use a optical semiconductor detector. The receiver detects the modulated light, you filter and measure its amplitude.

That way you filter out ambient light and electrical noise that can enter the system.

Most systems use scatter methods; https://www.fondriest.com/environmental-measurements/measurements/measuring-water-quality/turbidity-sensors-meters-and-methods/

Surely you have resources there at the University that has a chemistry or analysis department that has one of these devices or can supply info about them.

Tom... :)

Gustavohbo: It is not in the wrong direction. The yellow portion is Light, so when it hits the hole only the portion that is parallel to the hole passes

|500x244

So the yellow portion has an arrow on the end, this is pointing to the left. This says to anyone that the light is traveling from right to left.

But on the right you label a box saying LDR or receiver, and on the left the box is labeled LED or IR emitter.

You might not have seen the triangular yellow portion as an arrow, but I assure you the rest of the world does.

What is the name of this amplifier that you mentioned? Is it expansive?

I thing you mean expensive. It is called a "tuned amplifier" an amplifier with a specific frequency response that peaks at the modulation frequency. This is not the sort of amplifier you buy but one that you make.

Grumpy_Mike:
It is called a “tuned amplifier” an amplifier with a specific frequency response that peaks at the modulation frequency. This is not the sort of amplifier you buy but one that you make.

Actually, the “tuning” is now digital. You use the same signal that switches the LED on and off, to control a switch (74HC4066) which swaps the amplifier (op-amp) between inverting and non-inverting, and integrate (low pass filter) the result.

If the ADC is sufficiently fast (or you use a much lower frequency that the 38 kHz I mentioned, such as 700 Hz), you can perform this in the Arduino.

TomGeorge: HI, I think you are going to keep having problems if you are trying to read very small DC values.

My approach would be to modulate the light source and use a optical semiconductor detector. The receiver detects the modulated light, you filter and measure its amplitude.

What do you mean as a optical semiconductor detector? A LDR or an phototransistor as a infrared receiver?

TomGeorge: Surely you have resources there at the University that has a chemistry or analysis department that has one of these devices or can supply info about them.

We have a Turbidity meter at the University but unfortunately due to covid it harder to go there to test or study. So currently Im trying to do most of my reaserch at home

Grumpy_Mike:

So the yellow portion has an arrow on the end, this is pointing to the left. This says to anyone that the light is traveling from right to left.

But on the right you label a box saying LDR or receiver, and on the left the box is labeled LED or IR emitter.

You might not have seen the triangular yellow portion as an arrow, but I assure you the rest of the world does.

I see what you mean, that was my fault. I did it just as a sketch to post the question

Grumpy_Mike:
I thing you mean expensive. It is called a “tuned amplifier” an amplifier with a specific frequency response that peaks at the modulation frequency. This is not the sort of amplifier you buy but one that you make.

Ops, another silly mistake but english is not my native language so please take it easy. Anyway thanks for the warning.
Is it possible do this amplifier by software or do i need to buy some kind of hardware?

Paul__B: which swaps the amplifier (op-amp) between inverting and non-inverting, and integrate (low pass filter) the result.

I didnt understand what you said here. Can you explain this in a less technical way? What is op-amp?

Paul__B: If the ADC is sufficiently fast (or you use a much lower frequency that the 38 kHz I mentioned, such as 700 Hz), you can perform this in the Arduino.

This one that you mentioned (74HC4066) would be able to amplify the signal to 38 kHz or even 700 Hz? How do i know that the frequency that i chose will not suffer amy kind of interference? I want to emmit and read the signal continuously, will the tuning interfere on it?

My thoughts were that the kind of light would not interfere on it. Because in other words what I'm trying to measure is the amount of particles in water that are blocking the light.

Yes it would. The longer wavelength IR light “gets round” small partials that white light would be blocked by.

Have a look at photographs of the night sky taken in visible light and IR light. The visible light is blocked by dust in the milky way where as the IR light is not blocked by dust it goes round it. Go and ask at your Physics department.

This one that you mentioned (74HC4066) would be able to amplify the signal to 38 kHz or even 700 Hz?

I think this project is too much for you. The phrase “amplify the signal to a frequency” is meaningless. That chip is not an amplifier it is an analogue switch. You use it to swap signals over.

The best way to eliminate external effects is to use a square wave rather than a continuous signal. Choose a frequency that is not a harmonic of mains frequency.

Drive your LED (white will be fine) from a digital output via a resistor, and use a photodiode or phototransistor to measure the height when its ON.

Then take another measurement when its OFF and subtract the two.

I'd still recommend you exclude ambient light.

My page here shows how to drive an LED.

johnerrington: Drive your LED (white will be fine) from a digital output via a resistor, and use a photodiode or phototransistor to measure the height when its ON.

Then take another measurement when its OFF and subtract the two.

As I was suggesting in #22. :grinning: It seems you have explained it better.

johnerrington: The best way to eliminate external effects is to use a square wave rather than a continuous signal. Choose a frequency that is not a harmonic of mains frequency.

Which is why I suggested 700 Hz.

johnerrington: The best way to eliminate external effects is to use a square wave rather than a continuous signal. Choose a frequency that is not a harmonic of mains frequency.

Drive your LED (white will be fine) from a digital output via a resistor, and use a photodiode or phototransistor to measure the height when its ON.

Then take another measurement when its OFF and subtract the two.

I'd still recommend you exclude ambient light.

My page here shows how to drive an LED.

How do i filter the light/signal that the phototransistor is reading? And how do I modulate the frequency of the LED? Can you indicate me a photodiode that you would use. I have the cheap ones and I dont know if they are very good and the only ones I have are covered with some black filter that filter most of the visible light.

Thanks for your help!

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

Gustavohbo: 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.

Gustavohbo: 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.

Paul__B: 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?

Paul__B: 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.

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

johnerrington: 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.

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 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
}

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

Yes.

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.

But how do i do this switch?

By using the analogue multiplexers you mentioned previously.

Grumpy_Mike: 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?

Grumpy_Mike: 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!

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

// 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.

Like the 555?

No the 74HC4066.

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.

Grumpy_Mike: 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?