Infrared reflection level measurement

CLUELESS1

Senior Member
I want to have two IR LED's, one emitting IR, the other receiving any reflective IR and measure level.

If I use Irout, modulated to minimise ambient light on the TX device , and use Irin on the RX device to catch back any reflection, then how can I sense level changes of IR coming back. In other words can someone explain or point me in the direction of how I deviate from basically what looks like an IR remote control.

Thanks
 

geoff07

Senior Member
It depends on how you want to actually detect the level. If the level is changing (not much point otherwise) then the detector needs to be remote from the surface. With IR I doubt that you will be measuring propagation delay directly (as you might with ultrasound). So you must find something to measure. If it is a go/nogo test, then looking at a float as it passes the detector might do it. If you want actual level measurements, then you need some sort of analogue for the level that you can measure (e.g. resistance as per car fuel tank gauges), or, sticking with IR, you could use a combined device such as the GP2D120 or similar. But then the work is done in the device, and you won't be using leds.
 

CLUELESS1

Senior Member
Thanks Geoff, its to control the amount of IR a CCTV illuminator radiates. If something (person or light object) moves nearer to the IR light source then I want to reduce the level of IR being emitted from the main IR light source to prevent the subject being over lit. Hope that makes sense.
 

hippy

Technical Support
Staff member
As the IR is presumably being PWM'd you can probably use an IR photodiode or phototransistor, op-amp and RC circuit to detect the amount of IR reflection, then just read that using a READADC.

I recall there may be a TSOP receiver which outputs a level dependant on IR brightness but the standard IR receivers used with IRIN don't do that, do their best to ignore variations in brightness.
 

CLUELESS1

Senior Member
Thanks Hippy, you have hit my problem/querie on the head.

Yes I will use PWM on the IR emitter, but how would the photodiode or phototransistor know what was being returned that wasn't ambient. In other words how could I tune the receive part to receive only the PWM light source.
 

hippy

Technical Support
Staff member
To ignore ambient I would guess you would rely on photodiode characteristics and putting a physical IR-passing filter in front of it. You could also have a separate setup which wasn't filtered and adjust using that. You might be able to measure when IR is on and when off. There might also be some useful information from searching on SpO2 or Pulse Oximeter circuits.

If your CCTV camera has a composite video or RGB output you might be able to average that signal out to determine if it was saturated. If you can grab the output frames on a PC you could software process those to determine the same.
 
Last edited:

BeanieBots

Moderator
You need to syncronise the adc reading with the PWM.
In breif, when the transmitter is on, take a reading, then take another reading during the off period.
The difference is the amount received due to the transmission.

Taking hippy's suggsetion a little further, you MIGHT have some joy with a simple averaged signal level from the composite feed out of the camera.
Composite is typically ~1v so just feeding into an RC via a schottky diode should give a value that could be fed direct into a PICAXE ADC.
Certainly worth a try for the ten minutes it would take to experiment to see if it's feasable.
 

AllyCat

Senior Member
Hi,

I would have expected PWM illumination from a LED (unless heavily filtered with an inductor/diode) to "strobe" with the scanning frequency of the CCTV imager (producing "horizontal bars"). But certainly, use a Photo-transistor (not a diode) with a suitable load resistor (perhaps an internal "Weak Pullup") on an ADC input pin, to detect the reflected light.

You need to syncronise the adc reading with the PWM.
That would need quite a low PWM frequency, and if the PWM is a "background" (hardware) task, then I'm not sure how the PICaxe (software) would detect the "on" period (that's an issue I had been considering for one of my own projects, just a few days ago).

Cheers, Alan.
 

CLUELESS1

Senior Member
Many thanks both. I will order a phototransistor as suggested and start seeing what I get. At the moment I don't seem to have much in the way of strobing, however that could still become a problem as I have seen when I dim the IR LED's they do start to flicker. If that happens then I will have to drive the LED's a different way. I am far from being in my comfort zone with this project but it's good to try.
 

Dippy

Moderator
This is interesting so (assuming I have vaguely understood) I'm just thinking out aloud here...

Using the composite to feedback a bightness value will probably require buffering.
If you distort the composite signal you will upset your video signal and muck up your image.

Also, without introducing some delay/hysterisis your auto illuminator level might fight with the CCTV camera AGC circuit.
You could use the same buffer circuit to do this or do it in code.

If you just use one of the many senors on the market that would get around that and not put a load on your video signal.

On the PWM lED illumination: I would be tempted to consider a switcher style circuit or RC so that you 'feed' your IRLEDs with a DC-ish voltage which would get rid of flicker.. unless you can PWM at some monstrously high frequency.
 

CLUELESS1

Senior Member
Thanks Dippy. Yes, I don't really want to intercept the video output of the camera in case it deteriorates the output. I have ordered a couple of phototransistors which I will try putting in front of the camera to see what IR comes back (reflected) when someone moves up to the camera. Fortunately the main IR lighting is seperate and away from the camera so it won't pick up stray outgoing IR illumination. Being external hopefully makes it easier to play with.
 

Dippy

Moderator
Yes, worth a try.
But I think a device like a TSL262 (just an example) would give a more useful signal with a far wider dynamic range that a photodiode based circuit offers.
It may need a filter in tricky situations.
Photo-transistors tend to be a bit on-offy. Not impossible but not so easy.

Again though, the light detected will have to be DC-ish or you may have problems. Did you read my previous thoughts?
 

CLUELESS1

Senior Member
Tried using a phototransistor but there was very little reflected IR picked up, certainly nothing a few feet away (8 feet)
Looked at the TSL26R-LF but that was 940nM and the IR I am working with is 850nM.

I have asked a camera company if they know how SMART IR cameras get there feedback from, they reduce the level of IR illumination as a persons face gets nearer a camera in night view, this is to avoid whiteout

Maybe it's ultrasonics, so now I will see if I can find a working example of 9/10 feet unltrasonics, as the device Rev-Ed sells is only for 3 metres. If anyone has a link to help me, would be very greatful.
 

Dippy

Moderator
This is why I suggested something with a wider dynamic range.
All the sensors I have seen which work over a large illumination range have been photo-diode based.

I don't know your application but you need to find a sensor appropriate to the task.
Don't give up after one attempt. All these things are useful to put in the 'experience bank'.

At a guess I'd say simply detecting distance is not so good.
Some items are much more light reflective.
Therefore, reflected light (visible or IR) is what you need to detect and measure.

I think you need to descibe the application (outdooors? nighttime only? or twilight day/night?).
Then people might be able to help you with a fancy design.

What is your experience/skill level so that people can adjust their replies?
I'm sure you're not entirely 'clueless'? ;)
 

CLUELESS1

Senior Member
Hello Dippy, the task is to variably control the output level of infrared illuminators with a CCTV (board camera) in night time only

When a person gets illuminated with IR, they can easily be over exposed and faces appear as white blobs with no facial detail. I apply PWM to the led illuminators to adjust brightness, but different objects light up (illuminate) differently, and the IR lighting can light up an area perfectly (ie driveway and cars) but as soon as a human face is lit up the face is over exposed and gets worse the nearer the person moves towards the IR light source.

I have tried to set the IR level as a compromise between background and faces but it's not good enough.

There are now a range of CCTV cameras with what they call SMART IR. The camera senses the moving object (person) and adjusts the level of Infrared lighing as the person moves nearer or away from the cameras IR lighting.

I have tried to find how they do this, ie IR reflectiveness or ultrasonics or maybe something I cannot get into ie video signal.

If I could find an ultrasonic device that worked over 8-10 feet then I feel I could make something to control me PWM. Hope that explains what I a trying to achieve.
 

AllyCat

Senior Member
Hi,

Don't overlook that IR is effectively light of a different "colour" so objects may not look the same as in white light. Just like the old "low pressure sodium" (very yellow) streetlights, that made many colours just look "black". Some materials are transparent to IR, even though opaque in visible light.

Your next enemy is the "inverse square law" which means that objects half the distance away will look four times brighter. I think even simple snapshot cameras with built-in flash now terminate the flash when the sensor has received sufficient light (a kind of single-cycle PWM).

I suspect that the Smart IR cameras will simply monitor the video signal. It's not difficult to do, but it is necessary to detect the amplitude correctly. In principle it needs a "peak to peak" detector, because the low level is usually either black or "sync" level (sometimes called "blacker than black"). But you may need to pay careful attention to the "integration", or filtering, time constant (low-pass R-C values) to get good results.

Finally, 3 metres range is 10 feet (within a couple of inches) and the Rev-Ed ultrasonic sensor claims to detect a broom handle at more than 3 metres. I believe the main limitation is that the electronic circuit sets a timing window, after which it "ignores" signals that have taken longer to return (i.e. from án object further away). You might find that an ultrasonic sensor module with separate transmit and receive pins can manage further, or perhaps use two of the "cheapies" from China (one to transmit, the other to receive).

Cheers, Alan.
 

CLUELESS1

Senior Member
Thanks Alan. big appology to you and technical, I meant 8-10 metres!

Thanks also Alan for the addirional information. Unfortunately because of my lack of video circuit knowledge as well as where to interupt the video, I have to go down the road of controlling the IR light. If I can find a device to allow detection then I should be able to step my IR output up and down. There must be some devices out there to use as in tape measure replacements
 

Dippy

Moderator
In that case, like I said before, look into light sensors (which also respond to IR) that allow a large dynamic range.
Put phot-tr to one side, they're not suitable for this application (if I understand the application sufficiently).
 

CLUELESS1

Senior Member
After hours of googling, I got a lead on one companies development on SMART IR

What is Smart IR?

Our eyes are designed to detect visible light waves across the electromagnetic spectrum, although we can only detect a small portion. Infrared waves fall in between what is visible to us and microwaves which are completely invisible. Infrared waves can be measured as the heat an object emits, and every object emits some level of energy, even if it is small.

An imager inside a camera allows you to capture the heat image projected by an object, and this feature is called SMART IR, or Smart infrared. Coreveillance’s cameras are able to convert the infrared energy into electrical signals, which is then converted to an image.

So now I need to go down the road of capturing heat images. Any clues/advice.
 

JimPerry

Senior Member
Virtually all CCD camera units can detect IR - look at an IR remote with your phone camera - you can see the remote signal when pressing buttons :cool:
 

Buzby

Senior Member
Having a camera which is 'tuned' to receiving IR only won't get rid of your over-exposure problem, you will still need to detect it and correct it somehow.

One simple experiment is to use ultrasonics to measure the range, and adjust the illumination accordingly.

Another idea, but it depends on your specific application, use a break-beam detector set a few feet in front of the camera to drop to a lower illumination level.

EDIT : The vivotek web page ( http://www.vivotek.com/smart-ir/ ) says this
"Smart IR eliminates overexposure problems by dynamically adjusting the intensity of infrared light emitted by the camera’s LED source as an object of interest moves closer or farther away in the field of view."
In the demo video shown it could quite easily be done using ultrasonics.

ANOTHER EDIT : The .pdf about Vivotek cameras ( http://www.use-ip.co.uk/datasheets/vivotekproductbrochurejanuary2014.pdf ) says
"*WDR Pro: It works by capturing alternate frames using different exposure times. A single high-contrast frame that retains details in both the dark and bright areas of the field of view will then be created by combining the two frames using an advanced image signal processor."
so it does look like they are using digital signal processing. Not a task that a PICAXE could do in realtime.
 
Last edited:

Dippy

Moderator
Clueless, you've had several suggestions; any thoughts on how to proceed?

It looks like the most likely candidates for a solution have been covered.
Which is the one you prefer?
 

CLUELESS1

Senior Member
Thanks Buzby, I was considering ultrasonics earlier, however I am wanting 8/10 mtres and the devices seem only good for 3 metres.

Unfortunately the location does not lend itself to mounting part way devices. I am now trying to find how I can utilize the device/sensor in a PIR device, as this works on heat. I know there not easy to use in burglar alarms (false alarms) but that would not be a problem in occasional IR light level changes.

EDIT Might knock PIR on head, as they do not sense straight line movements to and from!
 

Dippy

Moderator
Yep, forget PIR (as in the standard sensors).

What's wrong with sensing IR reflection with a suitable sensor?
You've got to consider something that you are comfortable with.
I doubt you want something with a pile of complicated electronics.

Are you after a ready-made solution?
 

CLUELESS1

Senior Member
Thanks Dippy. Unless I can find an ultrasonic device to cover 8/10 mtres (Alibaba has, need to order 1000pieces) so thats out. PIR no good from what I can see as relies on moving in an out from sides, not forwards or backwards, so thats out. So until then it's trying to get reflective IR back, more emission and more sensors. So thats the road I'm going down just now. Thanks all.
 

Buzby

Senior Member
Remember the inverse square law ?. Due to this the biggest effects will be at close range, so that is where you need to change illumination most.

I still think that an SRF05 will give you all you need.
 

CLUELESS1

Senior Member
Thanks Buzby, giving ultrasonics another shot.

Using an 08M2, together with a HC-SR04 device

Code
Code:
symbol trig = 2          
symbol echo  = 1         
symbol range = w1       
 
main:
    pulsout trig,2         
    pulsin echo,1,range    
    pause 10               
 
' now convert range to cm (divide by 6.2) or inches (divide by 14.9)
' as picaxe cannot use fractions, multiply by 10 then divide by full number
' e.g. range x 10 then / 62 is the same as range / 6.2
 
    'let range = range * 10 / 62 ' multiply by 10 then divide by 62 
    
    let range = range * 10 / 62
    debug range   
 
    goto main
I would like to have the range in feet but cannot work out the range devide by 10 divide by 14.9 bit avoiding fractions.
Also, unless I hold a piece of paper or solid object in front of the device, w1 jumps all over the place with values, just like I have seen in adc. I have got decoupling capacitor on picaxe power pins, and a 470uf capacitor on the 5v rail. Is it normal to see it eratically producing values of range when I am sitting stationary in front of the device.

I want to stabilize it a bit more, get units of range that I can put into a pwm syntax so I can see a varying level of light being emitted from a normal led as I move forwards and backwards from the device.
 

AllyCat

Senior Member
Hi,

To convert to feet, just use the inches figure and divide by 12. That can be done all in one calculation by dividing by 14.9 * 12 = 178.8 , or just dividing by 179 will be good enough. But using units of feet is probably not a good idea if you only have integer maths. For example, taking into account the inverse square law, an object 2 feet away will be more than twice as bright as one at 3 feet (i.e. 9 / 4 times brighter).

But the actual distance units aren't relevant anyway, what you want to achieve is a value of (about) 1023 (for the PWM command) at the distance that the LED illimumination is correct. Taking into account the inverse square law, you need that distance to be 32 "units" (because 32 * 32 = 1024), so if the distance were 20 feet, then the unit would be 240 inches / 32 = 7.5 inches or 19 cms. So the overall divison factor would be 6.2 * 19 = 117.8, or 118 would be "good enough".

But incidentally, a useful trick if you want the program to divide more accurately by 117.8 is to divide 65,536 by 117.8 = 556(.333), so the calculation can be to multiply by 556 and divide by 65,536. That's exactly what the ** operator can do, so instead of dividing by 117.8 (or * 10 / 1178), simply ** 556 .

As for measuring a distance of 20+ feet, plenty of "ultrasonic tape measures" work to that distance, so you might be able to "hack" one. Alternatively, I don't know how quickly it's posisble to "turn around" the HC-SR04 (i.e. transmit a second pulse) but the following might work (or maybe use two transmitting sequentially):

Transmit a pulse and if no "echo" is detected then immediately send another pulse. Of course that should also get no signal, but if one is received then it must be the one transmitted previously. So if you know the delay to the second transmission, you can calculate the additional distance. Maybe even repeat again to give up to 30 feet range.

There may be some difficulty if the echo returns just when the second transmission starts, but it might be possible to work around that with two ultrasonic units and/or two different delays.

However, IMHO as you have a CCTV camera signal (a USB webcam or networked camera would be a different story) it should be quite easy for the PICaxe to detect if the output ("1 volt CVBS") signal overloads, and reduce the PWM accordingly.

Cheers, Alan.
 

CLUELESS1

Senior Member
Thanks Alan for your help.

"distance units aren't relevant anyway"

If I can produce a useable range of distance units, I will get somebody stand in front of the camera and I will adjust and take note of the IR PWM figure so that I can produce spot settings on an if/else routine, starting from the longest distance hoping the range data will kick in when getting nearer. Doing it this way will hopefully give a result, maybe I'm wrong.

My current PWM settings are done from a potentiometer

Code:
main:
readadc 1,b1
pwmout pwmdiv64, C.2, 63, b1
pause 20
goto main
So I need to log values of b1 against range values observing a persons face!
 

CLUELESS1

Senior Member
Still looking at HC-SC04 use, however finding so many Arduino articles but no Picaxe ones. Trying to produce beeps in a speaker as the range changes with the ultrasonic device. Finding it so hard trying to work at both ends of the project in reading debug ranges and being at the other end moving. If I had some beeping activity such as a car parking sensor would help. If I knew how to convert the HC-SR04 output into voltage would help. Any links, clues?
 

hippy

Technical Support
Staff member
You can simply use the pulse width which increases with distance to change the pause time after reading the pulse which can vary the rate of beeping.

Code:
Do
  read ultrasonic pulse into w0
  Pause w0
  Sound pin,(tone,duration )
Loop
You might need to adjust w0 to get a useful result. Start by checking the ultrasonic triggering is working and w0 holds expected results with SERTXD first.
 

CLUELESS1

Senior Member
Thanks Hippy.

My current code

Code:
main:
    pulsout trig,1   
    pulsin echo,1,range
    pause 10              
    let range = range / 149
    debug  
    goto main
read ultrasonic pulse into w0 - ?????

EDIT: Just seen my speaker is 8ohms, do I need series resistor or drive with a transistor?

Thanks
 

AllyCat

Senior Member
Hi,

Yes, connect the loudspeaker to a PICaxe pin through about 220 ohms. If it isn't loud enough then you'll need to use a transistor amplifier.

As your code is dividing by 149 (but not first multiplying by 10) I'd expect your "range units" to be about 10 inches. Therefore, expect a result of about 12 or 13 for a range of 10 feet.

Cheers, Alan.
 

CLUELESS1

Senior Member
Thanks Alan,

I read that I could use a 33k resistor, but using a 38k, seems okay.

I am playing round with getting beeps, because now I can move towards the sensor to see when it kicks in.

Code:
symbol trig = 2        
symbol echo  = 1         
symbol range = w1       
symbol range2 = w2  
 
main:

    pulsout trig,1   
    pulsin echo,1,range
    pause 10              
 
    let range = range / 149
   
 range2=range*10
    
    sound 4, (range2 ,10)
      
    goto main
Need to play a bit more.
 
Top