LDR for interrupting proximity sensor


Senior Member
I was fiddling around with an LDR this weekend, trying to cobble together a sensor to count revolutions (relatively slow ones -1-70 RPM, but perhaps measuring in as small as quarter rev, so up to 280 300 pulses per minute). I had left my sensors designed to do this at home, but had some LDRs, so....

Anyway, plugged it together as mentioned in the manual with a 100K resistor, but the voltage ranges were not in the range to trigger a count (always on). So I took a pot, and hooked it up as a variable resistor until I got the ratio where it looked right. Got counts - Hooray! Oops, got sometimes 8 or even 30 counts per occlusion (looked kind of like switch bounce or something).

Hookup -


Back home now, and have the optical sensors handy (and plan to work out how to hook them up later, as they will probably work easier mechanically as well), but any thoughts on what was going on with the LDR and who to resolve it? For instance swap the position of the LDR and the VR? Add a cap in there? Get a phototransistor out of the box (not sure I had one handy, but didn't look thoroughly after I spotted the LDRs)?




Were you reading this analogue voltage on a digital input?
If it's a TTL input, then any voltage hovering around the threshold would cause multiple triggers.
Feed via a ST type input. Either use a PICAXE ST input or use a ST buffer (74C14).


Senior Member
Bear in mind that with an ST input, you will need to get a full swing from near 0 to near supply - fluctuations in the middle area won't give clean counts
eg @ +5V supply,
high = 0.8 VSupply = 4V
low = 0.2 VSupply = 1V

So the opto and pullups etc must give voltage swing <1v to > 4V for reliability.


Senior Member

Just for background, what was your program?

As I recall, it was basically something like:

count 1, 5000, w1 ; count the pulses for 5 seconds
pause 1000 ; wait a tad
debug ; see what the count is in W1
goto main

Tried to keep it pretty simple.




Can you scope it?

I'm sure once you see the actual signal then , in conjunction with the above info about Input thresholds, the reason will pop out.

You don't mention the triggering method; reflecting off something on the shaft or break-beam or what? Illumination level; nice bright light pr ambient?

LDR response isn't particularly fast and it is even slower at lower light levels, but I'm sure once you have seen the shape and amplitude on a scope then you'll get it sussed.

Or just stick in your proper sensors at home and be done with it :)


I know that the 100k Ohm resistor is what is shown in the PICAXE Manual 3 from the pin/LDR to 0V. However, some tests I did around a year ago found better values exist.

I have one LDR operating with 24k Ohm for maximum voltage variation.

Another LDR I bought recently (at Jaycar her in Aust) has a 2.2k Ohm resistor which gives me a range of 1 to 254 with READADC so verly close to 0V to 5V.

So try something lkike a 10k Ohm resistor which will may give a greater voltage variation.


Senior Member

I was aiming for a break beam, occluding the light. Yes, first tests were just passing my hand close over it in ambient (under some decent overhead lights. I then used a flashlight aimed directly into the LDR with a dark credit card as the occluder. I didn't notice a particularly better result one way or the other.

Westaust, I was checking the range with a VOM to get what looked like an appropriate input trigger range while adjusting the Variable Resistor. When I got what looked appropriate, it did work, but as noted, with multiple triggers. Tried tweaking it with the VR, no joy.

Didn't have a scope handy, but it will be interesting to look when I get a moment to dig it out and set it up.




See post #3
With no hysterisis you will potentially always get multiple triggers measuring an analogue signal with a TTL input.

You must either add hysterisis to your signal or use a ST type input.

Depending on speed, it might be possible to add the hysterisis in software using ReadADC instead.