infrared Liquid level detector

Thread Starter

fantabulous68

Joined Nov 3, 2007
51
i want to determine the distance from the time interval between pulses.
Just imagine you dropping a stone into a deep hole and waiting for the sound of the stone hitting the floor.
The shorter the time between the point of release of the stone and the sound of it hitting the floor, the shorter
the distance the stone travelled.

The is how i want to program the circuit to operate.



Basically the sequence for programming should be as follows:

Set timer to ZERO!
Send signal to transmitting IR diode
Start timer
If your receiving IR diode(active low) - indicating it received the signal the STOP timer.

Work out the distance from halving the time and using that speed formula : distance = speed * time.


if i cant get the timer to work properly maybe i try this approach... its a little crude
but should give me some results in any case...

using an arbitrary variable say T (being an integer)

Set T = ZERO.
Send signal to transmitting diode.

If your receiving IR Diode is still low (meaning no signal received as yet)
increase T by 1

The above loop will continue to run until the receiving IR Diode goes HIGH.

Now you will have an unknown positive value in T which is not associated in any equation.
But if you plot out the value of T versus the distance you set the diodes at, then you can work out the equation
for distance - straight line equation

y = mx + c

m = (y2-y1)/(x2-x1)
(x1,y1) and (x2,y2) being co-ordinates with x representing distance and y representing the various values of T.

^
| /
T| /
| /
| /
| / this is a straight line
| /
|/
|----------------------------- >
0

your two co-ordinates (x1,y1) and (x2,y2) are for the shortest and furthest distance of measurement.
So when setting the shortest distance - use a ruler and obstruct the IR diodes approximately 5cm away.
Your distance is known cos you measured it right But you will get a T value for this distance.

Now set the furthest distance (50cm) - use the ruler, obstruct again at 50cm away and get that T value.
Plot a graph and work out the equation of T versus distance.

But this is if i cannot get the timer function to work but the procedure is the same in any case.

yes i will consult with my lecturer and respond to you all.
 

jpanhalt

Joined Jan 18, 2008
11,087
I think all of us understand the principle of TOF ("time of flight") measurements. The link you provide will not measure distance. As others have pointed out, your timing is simply too crude to measure TOF of a light beam for measuring the level of liquid.

Moreover, even if your timing were precise enough, you have not considered the question I raised early on about the reflectivity of water or common (colorless) liquids to the IR wavelength you are using.

I think it is time that you consider exactly what you want or need to do. And, you need to have an open mind as to various approaches. What you have described so far WILL NOT WORK.

John
 

rjenkins

Joined Nov 6, 2005
1,013
Same problem as noted before. What if there are ripples on the liquid?

Again I ask, what liquid are you trying to measure?

John
That's why I stated the sensor should be dead vertical, it will of course measure the height of any ripples but not fundamentally affect the geometry of the TX to RX path; you measure the beam angle needed to put a spot below the sensor.

As others have stated, 'echo timing' will not work for your requirements.
Even if 5cm steps were OK (so 10cm round trip), with light travelling at 300 Metres per microsecond you would need a counter operating at 30GHz - around a thousand times faster than the fastest PIC timer..
 
Last edited:

jpanhalt

Joined Jan 18, 2008
11,087
@Bill:

If you were closer, I would shine it at you. FatMax is or has apparently become a generic Stanley brand name; although, that is what my laser device is labeled. It is a class IIIa laser. The product is labeled "Swiss Technology" by Leica Corporation, is made in Austria, and is labeled Type TLM 100. The TLM 100 was the low-end device (+/- 1/4 inch --about 6 mm-- at 100 ft. The high-end TLM300 device is rated at +/- 1/16 inch at 600 ft.

The old catalog # was 77-910. I bought the low-end device because of price, and because I intended to tear it apart to see how it worked. I was able to satisfy my curiosity without doing that. It is TOF, which is almost unbelievable. Those Swiss are clever indeed.

As for subs, the tape measure would probably be more cost effective, if you consider the probability of an attack from Canada.

John
 

Thread Starter

fantabulous68

Joined Nov 3, 2007
51
any1 knows of an infrared receiver IC with an analogue output,
its output voltage should vary with the intensity of the reflected light?

plan to do some ADC with a lookup table
 

jpanhalt

Joined Jan 18, 2008
11,087
Gaspode42, that wasnt very nice. I need all the help i can get thats why i post my topic on different forums.
Let me say that many individuals post simultaneously on multiple forums. That in itself doesn't bother me at all. In fact, the OP of a recent thread here mentioned getting input from another forum that we could then build upon constructively.

I think it is far better to be open and to have a good dialog than it is to pretend AAC is your one and only. In other words, share the information both ways. For myself, I would have liked to see the exact wording for the problem as you posted elsewhere. This is obviously an academic exercise, and it is not at all certain TOF is the answer the teacher is after. In fact, the teacher may not have even done the project successfully himself.

John
 

jpanhalt

Joined Jan 18, 2008
11,087
any1 knows of an infrared receiver IC with an analogue output,
its output voltage should vary with the intensity of the reflected light?

plan to do some ADC with a lookup table
RadioShack used to sell one, and I got several from one of the surplus dealers years ago (Electronics Goldmine). It is not an IC; it is just a detector and looks much like an LED but is dark.

John
 

Thread Starter

fantabulous68

Joined Nov 3, 2007
51
rjenkins rjenkins is offline
Senior Member

Join Date: Nov 2005
Location: UK
Posts: 146
Default
For 50cm you would probably be best off using the strength of the reflected IR signal.

Switch the emitter on&off at a steady rate (tens of hz?) and measure the IR sensor output with one of the ADCs in the PIC for both emitter on & emitter off.

The difference gives you the signal due to the emitter, cancelling any ambient illumination.

You can then calibrate that (using a look-up table?) to actual distance.
I want to go with this method.
 
Last edited:

Thread Starter

fantabulous68

Joined Nov 3, 2007
51
im going to ask my lecturer today if he would pls allow me to use the sharpgp2d12. And decrease the range of the sensor from 50cm to about 35cm

Any 1 has a clue if its suitable for liquids???
The Sharp GP2D12 is an analog distance sensor that uses infrared to detect an object between 10 cm
and 80 cm away. The GP2D12 provides a non-linear voltage output in relation to the distance an object
is from the sensor and interfaces easily using any analog to digital converter.
 

DickCappels

Joined Aug 21, 2008
10,187
So...you are looking at this as a signal processing problem, but maybe a better solution can be obtained by viewing it as an optical problem.




In the picture above depicts a mouse with an optical detector that can tell when the mouse is off the table or mouse pad. If more than one detector is used, the distance from the mouse to the table can be determined.

The surface 580 is the water in the tank. Detector 530 will detect the light from the LED when the two angles (alpha1 and apha2 in the picture) are equal.

The details, including a circuit, are in U.S. patent 7196690, which can be viewed or dowloaded from Google Patents.http://www.google.com/patents?q=7196690&btnG=Search+Patents
 

Thread Starter

fantabulous68

Joined Nov 3, 2007
51
Thanks Dick Cappels for your input. I decided to use the Sharp GP2.

This is for the PIC 18F1320 BUT i want to modify this code to suit the PIC16f690. I am trying but not sure about a few things. I attached a word document with the relevent datasheets from the 18F and 16F. This code is for the Sharp GP2 sensor. Im a beginner with programming the pic. Please do assist me...

Rich (BB code):
void main()
{
	// setup the PIC 18F1320
	OSCCON = 0x72;      	// internal osc, 8MHz

	PORTA = 0;
	TRISA = 0b10000010; 	// RA7 high imp, RA3 is serial out,
							// RA1 is ADC input measuring VR1
	PORTB = 0;
	INTCON2 = 0;            // PORTB pullups ON
	TRISB = 0b00000000; 	// PORTB not used

	ADCON0 = 0b00000101;	// ADC ON, RA1 is ADC input
	ADCON1 = 0b01111101;	// AN1 is ADC input
	ADCON2 = 0b10100010;	// right justify, 8Tad, 32Tosc

	T1CON = 0b00010001;     // TMR1 is ON, 1:2 prescale, =1MHz

	T3CON = 0b00010001;     // TMR3 is ON, 1:2 prescale, =1MHz

	// main loop here;
	while(1)
	{
		// wait for 2 seconds, uses TMR1 free running at 1Mhz
		while(!PIR1.TMR1IF);    // wait for TMR1 overflow
        PIR1.TMR1IF = 0;		// clear overflow flag
		LATA = 0;				// all LEDs off
		
		bres += 65536;			// add 65536uS to bres value
		if(bres >= 2000000)		// if reached 2 seconds!
		{
			bres -= 2000000;	// subtract 2 seconds, keep error
		
			// flash Junebug LED1,  RA0=1 RA6=0 RA7=hiimpedance
			LATA.F0 = 1;			// LED on

		    // read the ADC voltage RA1 (Sharp GP2 sensor)
		    ADCON0.F1 = 1;		// set GO bit, start doing ADC
		    while(ADCON0.F1);	// wait until ADC done
			calc_distance();		// convert ADC value to distance
			send_serial_message();	// send message back to PC!
		}

	}
}
My code to suit pic 16f690:

Rich (BB code):
	TRISA = 0b10000010; 	// RA7 high imp, RA3 is serial out,
				// RA1 is ADC input measuring VR1
Question1:The 16f690 doesnt have a RA7. What does makin the pin a high impedance mean? Im assuming imp is impedance. I know TRIS sets pins as inputs and outputs.

*********************************************************
Im sure this part is right:)Easy part
//18F
Rich (BB code):
PORTB = 0;
INTCON2 = 0;            // PORTB pullups ON
TRISB = 0b00000000; 	// PORTB not used
//16F
Rich (BB code):
PORTB = 0;          
WPUB = 1;
RABPU = 0;

*********************************************************

//18F
Rich (BB code):
ADCON0 = 0b00000101;	// ADC ON, RA1 is ADC input
ADCON1 = 0b01111101;	// AN1 is ADC input
ADCON2 = 0b10100010;	// right justify, 8Tad, 32Tosc

//16F

Rich (BB code):
ADCON0 = 0b10000101;	// bit 7 right justify,analogue channel select bits bits5-2  0001=AN1,ADC ON, RA1 is ADC input
ADCON1 = 0b00100000;	//bits6-4  fosc/32
Question2:
I dont know how to set 8Tad on the 16f690. Could someone please tell me how to do that?

Question3:
Does analogue channel select bits bits5-2 0001=AN1 mean that AN1 is ADC input?


Im going to collect the sharp GP2 today
 

Attachments

GetDeviceInfo

Joined Jun 7, 2009
2,196
Your not at programming yet, as the hardware isn't proven.

Here's a contemplation;

If you issue the IR radiation, and at the same time start an RC charge ramp. The detector then would cease and hold the charge, for the micro to AD convert, or drain the charge at a different rate that is complatable with the micro.

You will need a high power emitter and a sensitive reciever.

Another approach could be to charge a capacitive gate for the TOF duration, then inspect the gate effect.

Your problem is not in the pics timers, as you would only use them to time the sampling rate, but in the gating of your signals used to capture the TOF.
 

jpanhalt

Joined Jan 18, 2008
11,087
I agree in part. The OP, I believe, has given up on using TOF because of the inherent technical hurdles. He is now looking at using the intensity of reflected light.

He does not seem to have done any preliminary experiments to determine the feasibility of that approach. We are all familiar with reflections from walls and other surfaces, but I believe he should briefly look at the problems of using reflection from an unknown liquid that may very well have ripples and standing waves on its surface.

Those experiments can be done quickly using analog signals and detection just to confirm proof of concept. What good will a nice program in C be, if there is no predictable correlation between the intensity of the reflected light and the volume of liquid in the container? Some liquids are so transparent at 940 nm (presumably the wavelength that he will be using -- it would be nice to know for sure) that the most intense reflection he detects may be off the vessel's walls. That will not change much, or its intensity may even increase as the level of liquid decreases.

John
 
Top