Red LED detector (hopefully more interesting than it sounds) - Page 1
Forum section: electronics / projects

author: Bakafish
author_rank: Contributor
timestamp: September 03, 2021, 04:20:14 am
content: I have a precision tool post height gauge made by BIG Daishawa.https://www.big-daishowa.co.jp/product_page/data_15_base-master.phpIt works based on a simple completion of a circuit, and it lights a small red LED on the body. It has no outputs and is a sealed enclosure that I do not want to open as it is calibrated and accurate to a micron, it is highly probable that attempting disassembly will render it inaccurate. What I want to do is to make an external fitting with a sensor on it that will detect when the light is on (with as little latency as possible) so that I can integrate it electrically into a CNC.Basically the way these work is you put it on the bed of your machine and lower the tool until it completes the circuit, at that very first touch you know the tool is within a micron of exactly 50mm from the bed. Doing this manually isn't hard, but automating the procedure is very helpful, especially when using quick change tool holders or checking for tool breakage during long job runs.Not wanting to reinvent the wheel I bought a 3 pack of Chinese made Uxcell 'adjustable' LM393 based light sensors that claim to use "Photo diodes" (but they look just like normal LEDs) and tried to use them.https://www.amazon.co.jp/gp/product/B07X6CFKMT/ref=ppx_yo_dt_b_asin_title_o09_s00?ie=UTF8&psc=1I'm sure it will come as no surprise that they worked like crap, with a ton of unit to unit variation, none of which worked very effectively. Very hard to set a threshold that wouldn't false trigger and that would reliably indicate when the LED was on. I honestly didn't think detecting an LED would be much of a challenge, but when you have an expensive CNC with an expensive Carbide end mill moving on its own to depress the sensor of an expensive height gauge, you start reconsidering the quality of your hacks. I will protect the unit with a secondary switch, but I'd really like a reliable solution.So what I'm wondering is, the LM393 (if it is really what it is, who knows with CN stuff) seems like a reasonable device. The photo diode they are using is completely suspect though. Since the LED outputs such a narrow spectrum of light, is there some issue using a photodiode? Should I buy a more reputable photo diode or a different type of sensor and replace it? Is there an alternative part or solution I should be trying instead?

author: bob91343
author_rank: Super Contributor
timestamp: September 03, 2021, 04:28:50 am
content: One important consideration is stray light. If possible, an opaque tube should be used to prevent activation from reflections or ambient light. Further, a filter may help to narrow the sensitivity spectrum to the peak of the LED.

author: Bakafish
author_rank: Contributor
timestamp: September 03, 2021, 04:31:36 am
content: Quote from: bob91343 on September 03, 2021, 04:28:50 amYes, of course. Assume the LED and Detector are completely isolated from any external lighting. The CN units were isolated in the tests. I noticed they could easily be triggered by stray capacitance from being touched. Not great...

author: james_s
author_rank: Super Contributor
timestamp: September 03, 2021, 04:40:53 am
content: This should be trivial. A photodiode will work, and yes many of them do look just like LEDs but for a simple binary detection like this I'd go with a phototransistor. With nothing more than a resistor to bias it from a 5V or so power source you should get a nice strong signal from the light of an LED. If ambient light is an issue then a red filter ought to help to some extent.

author: Ian.M
author_rank: Super Contributor
timestamp: September 03, 2021, 06:48:45 am
content: Another possibility would be to access the LED and switch circuit via the height gauge's battery compartment. The two battery contacts would allow you to access the series combo of the LED and switch, and you could apply external power through the base of a transistor or if the housing is part of the circuit, isolated external power through the LED of an optocoupler to detect the current through the LED when the switch is closed. It would then be easy to get a logic level signal from the transistor, or opto's phototransistor, collector.Before implementing this, you'd need to hook up the batteries externally and measure the current so you can calculate a dropper resistor to keep the current the same.The only possible problem is if the battery compartment cover is in the unit's bottom, as that would make it impossible to bring a cable out, unless you were willing to accept a precision 10mm block under it (for a total height of 60mm) with a slot for the cable. I am assuming that duplicating the battery compartment cover, with a hole for the cable and making a dummy battery assembly to connect to the battery contacts is well within your capabilities.

author: Bakafish
author_rank: Contributor
timestamp: September 03, 2021, 08:30:31 am
content: Quote from: Ian.M on September 03, 2021, 06:48:45 amYes, I thought of this tooBut as you noted, the battery compartment is located on the bottom and so a precision spacer would be needed. Since I plan to put a secondary physical switch (as a backup that triggers if the top plate is depressed too far) I kind of wanted to keep things as clean as possible, was picturing a simple clip on collar that had the sensor and switch. My feeling is if I can't get the light sensor to work I would risk disassembly. I have a half micron resolution digital dial indicator and a test stand, so I can always just re-calibrate the height measurement and use that offset if it ends up being different.I just ordered a couple Kodenshi ST23G phototransistors that unless the spec's are wrong, should pick up the LED properly. I got some high speed optoisolators as well, I'm probably overcomplicating things, but I want to make sure I don't burn up my controller.

author: james_s
author_rank: Super Contributor
timestamp: September 03, 2021, 05:15:06 pm
content: What do you need the opto isolators for? You already inherently have an opto-isolator since you are trying to detect an LED.

author: Bakafish
author_rank: Contributor
timestamp: September 04, 2021, 02:41:57 am
content: Quote from: james_s on September 03, 2021, 05:15:06 pmMy controller is based on an ESP32 module that uses 3.3v levels, and I wasn't sure that the phototransistor would be happy at that low of a voltage, so I was thinking I would run as high a voltage as the sensor could comfortably tolerate (to help with noise, CNC's are electromagnetically hostile) and then use the opto-isolator to deal with the level shifting. Maybe I'm over complicating this?

author: james_s
author_rank: Super Contributor
timestamp: September 04, 2021, 04:05:20 am
content: A phototransistor will have a forward drop of under a volt, it should work just fine on 3.3V. Just hook it up like this.https://www.electronics-notes.com/articles/electronic_components/transistor/phototransistor-circuits-applications.php

author: AndyC_772
author_rank: Super Contributor
timestamp: September 04, 2021, 07:49:09 am
content: This reminds me of one of my university projects, which was a line following robot. It used LEDs and light detectors to follow a white line, which marked a course through a number of obstacles that it needed to traverse.The lab had three identical courses laid out, and the choice of which one the team used, on any given session, was random.We kept finding that software which had been tuned to work perfectly one day would suddenly start misbehaving on another. Events would be triggered prematurely or not at all, or it would hunt from side to side as it followed curves.Eventually we figured out the issue. The ceiling of the lab was lower over one of the tracks compared to the other two. This meant the overhead fluorescent lights were closer, and so the amount of ambient light was greater. This altered the threshold at which the detectors would change state, and made the line appear wider or narrower.I forget how we fixed it, but any number of changes would have worked - physically shielding the sensor from ambient light or moving it lower to the ground would be obvious fixes.

author: Bakafish
author_rank: Contributor
timestamp: September 14, 2021, 05:44:28 am
content: Closing the Google circle for those who may later visit in search of a similar solution:I was able to breadboard and test this simple circuit, I have not yet used it in production but it seems fully workable and I will update this if I experience difficulties in the future.The Phototransistor used is theKodenshi ST23G, it is a side lens design tuned to the infrared spectrum, but wide band enough to work well with the red LED's used in my devices. A total resistance of 4.7Kresulted in a good switch like response. The induced latency (rise time) according to the documentation should be under 15µs, which should be fine for a relatively slow probe cycle speed. In theory, at a feed rate of 3000 mm/min it would contribute less than a micron of error.

author: elnino1947
author_rank: Newbie
timestamp: September 14, 2021, 11:14:53 am
content: to add to this make sure the Opaque material is dead dark black!. Infra red Light can pass through some opaque materials which can easily trigger the led.Also you don't even need an Opamp for this application - the device is marketed as a photo diode but actually is a photo transistor. you can easily hook up one of the lead to ground and then pull it up using a 10K resistor. use the Arduino(ESP) inbuilt ADC to measure the voltage at the other terminal. this will get you a better control over it through the code!

author: harerod
author_rank: Frequent Contributor
timestamp: September 14, 2021, 07:22:37 pm
content: Quote from: AndyC_772 on September 04, 2021, 07:49:09 amAll light barrier projects start simple, until exterior noise sources come in. The only reliable way of handling those, is to make your emitter do something the environment never does. That might be using a modulated signal (see IR-remotes) or a synchronization between detector and emitter (sharp pulses in light curtains).Anything less than that requires a strong enough light source and optical shielding to work, and that under very limited conditions, only.