Author Topic: Feeding LED state into Arduino  (Read 1770 times)

0 Members and 1 Guest are viewing this topic.

Offline tjkolevTopic starter

  • Contributor
  • Posts: 10
  • Country: us
Feeding LED state into Arduino
« on: April 20, 2022, 12:52:50 am »
Feeding LED state into Arduino

Greetings,

I have a device, which provides status and error information via three LEDs. I would like to feed the state of the LEDs to an Arduino (3.3V Sparkfun Arduino Pro Mini) - logical 1 when an LED is on, logical 0 when LED is off.

I was able to "break out" connections parallel to each LED's pin. So I figured I'd use an optocoupler. Hopefully one that can be activated without diminishing the LED brightness too much. However, my electronics proficiency is right about at the level of battery-switch-resistor circuit. And I am off looking for help.

I searched, but could not find a reference for my setup. Hits were for the reverse - Arduino on the photodiode side of the optocoupler. Which optocoupler is appropriate, and how do I wire each side?

I also took a shot of the signal on one of the LEDs - attached. Very much surprised. But explainable, because the device uses AC. Looks like the LEDs are controlled with a square wave of sorts. How do I get a steady 0/1 level for the Arduino? Preferably with something on the optocoupler's Arduino side.

Or should I instead use a photodiode placed over the LED? Will that be simpler?

Cheers!
tjk :)

=========
LED on:
1466821-0

LED off:
1466827-1
 

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3439
  • Country: us
Re: Feeding LED state into Arduino
« Reply #1 on: April 20, 2022, 01:09:52 am »
Using PWM to control LED brightness is common.  PWM (Pulse Width Modulation) is the method of turning the LED on for limited time each cycle then off.  Longer the ON, brighter it gets.  That is why you are seeing a square wave of sort.

PWM at 50% would be half ON time, half off.  PWM at 25% would be 1/4 of the time on, 3/4 time off.  Most-bright would be PWM at 100% meaning continuous ON.  PWM cycle usually would be thousands of times a second.

Direct connection (from LED V+) to the Arduino input would not work well since even when the LED is lid up rather bright, part of the time it would be OFF.  You need some isolation (such as using a diode instead of direct connect to the LED's +), and perhaps a capacitor to hold the voltage (on the other side of the diode where Arduino input is reading). 
« Last Edit: April 20, 2022, 01:16:38 am by Rick Law »
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1314
  • Country: us
Re: Feeding LED state into Arduino
« Reply #2 on: April 20, 2022, 02:07:43 am »
Does the Arduino have ADC inputs?  If so, can you just read the ADC a couple times in a row?
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
Re: Feeding LED state into Arduino
« Reply #3 on: April 20, 2022, 02:42:02 am »

I searched, but could not find a reference for my setup. Hits were for the reverse - Arduino on the photodiode side of the optocoupler. Which optocoupler is appropriate, and how do I wire each side?

The basic idea is described here:

https://electronics.stackexchange.com/a/480490/95488

You can experiment with the pull-up resistor -- something in the range of 2K to 20K should work.

You may not need to add R1 as the existing circuit should already implement some form of current limiting for the LED. However, having a small resistor like 200 ohms wouldn't be a bad idea and shouldn't affect the operation of the optocoupler.

The GPIO pin will be pulled low when the LED is being illuminated and will be hi otherwise.

As for the software side, how fast can you sample the inputs -- like every 100 microseconds? If that's not fast enough to catch the LEDs turning on you can add some additional circuitry to help catch the transistions.
« Last Edit: April 20, 2022, 02:47:34 am by ledtester »
 

Offline mikeho

  • Newbie
  • Posts: 2
  • Country: au
Re: Feeding LED state into Arduino
« Reply #4 on: April 20, 2022, 11:22:20 am »
Why do you need isolation?
Could you run the Arduino from the device's power? It needs little.
You could use an ESP32 or similar and make the readings available over wifi or bluetooth.

If one end of the LED is tied or pulled to ground, you may be able to read the voltage directly.
Read multiple times over the 16ms cycle.


 

Offline tjkolevTopic starter

  • Contributor
  • Posts: 10
  • Country: us
Re: Feeding LED state into Arduino
« Reply #5 on: April 20, 2022, 11:47:38 pm »
Great information!

@mikeho,
I am trying to build an "observer" circuit. Ideally an observer must not affect in any way the observed. So I was considering using a photodiode observing the LED light - completely isolated. But that requires me building some frame to fix the photodiodes over the LEDs. An optocoupler is the next best observer I can think of. But the photodiode side would still be tapped into the device, and thus could (would) affect in some (hopefully non-degrading) way the device. Electrically isolating circuits for various reason is very common.

@all,
Thank you for the advice. I am going to try some setups and report back findings. The Arduino does have analog inputs (ADC). Sampling on that, and doing some averaging is something I will try. Sounds simple enough to detect LED on/off state without additional circuitry to get a proper logical level. The LED signaling is very low "frequency". Too of the LEDs are on/off for a long period of time (minutes). The third one "blinks" error codes - 2 to 5 blinks with 2 second pause in between. No worries with the sampling on the ADC pin.

I still need to get an optocoupler. Will this one work well enough:
https://www.mouser.com/datasheet/2/365/SHRP_S_A0005004462_1-2563657.pdf

Thank you, all!
tjk :)
 

Offline tjkolevTopic starter

  • Contributor
  • Posts: 10
  • Country: us
Re: Feeding LED state into Arduino
« Reply #6 on: May 19, 2022, 04:36:53 am »
Greetings,

I am back, needing more help...
I used an PC817 optocoupler with the included circuit - modeled after @ledtester's suggestion. I did some tests with an input generated from an Arduino. Worked fine, as expected. Then I tried to do a real world test, and it did not work. In the circuit the orange part is the LED on the device, and I am attaching the IR LED (input) side to that. The phototransistor side (output) stays "closed".

Here's what I've tried. In all of the cases the phototransistor side does not change. Using the same 3.3V DC with a 10K resistor. For R1 I tried 1K, 100, and 0 (wire) ohm resistors.

Using a DC power supply to drive the input side.
A-B input voltage: 1.14V. At that value the D-E output voltage drops to about 130mV, which I figured would register as logic 0. The output opens fast between 1.00V and 1.14V. With lower than 1.00V the output is closed, and D-E is close to 3.3V as expected (pulled high).
With a 100 ohms for R1 the input draws 2.7mA. With 0 ohms - 130mA

The above indicates to me normal working, and that the optocoupler isn't shot.

Next I connect the input to the actual device - parallel to its LED I want to monitor. Not working - the output stays closed, and the signal was a flat line at some 3.3V. I expect to see a similar pulse signal on the output, but inverted.
Following are the captures from the oscilloscope. The first one is without my circuit being attached. All are 5ms and 1V per division.
With a 100 ohm R1 the current was 2.2mA. With 0 ohm - 2.3mA. The signals had no perceived difference.

So, why is my circuit not working? Not enough current? The DC test had very similar value. Signal too fast? Based on the datasheet switch time is microseconds - this is milliseconds. Input voltage just a tad low?
How do I fix this?

And also - how come even with D1 the AC signal still goes negative. I was expecting to see just to top part. My test isn't set up right? I guess the oscilloscope would still see the "reverse" signal.

Cheers!
tjk :)


 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
Re: Feeding LED state into Arduino
« Reply #7 on: May 19, 2022, 06:14:00 am »
Some questions...

- what exactly is your device and how is it powered?

- with the PC817 attached does the original LED light up?

I think we have to determine if the status LEDs are being driven from the high-side or low-side and that will tell us how to connect the PC817. Generally one end of the led-resistor combo is permanently tied to a rail -- either the positive rail or GND. If it's the positive rail then low-side switching is being used and if it is GND then it's high-side switching. You probably can determine this by seeing where the LEDs traces go off to.

1490476-0




 

Offline tjkolevTopic starter

  • Contributor
  • Posts: 10
  • Country: us
Re: Feeding LED state into Arduino
« Reply #8 on: May 20, 2022, 03:14:23 am »
Hello ledtester,

I think I understand low vs high side driven. However this is applicable for a DC circuit, no? The one I am dealing with is AC. I followed the traces and this is as much as I could figure out. I am fairly certain that AN1 resistor goes to 24VAC COM. It is labeled "Power". It's on when the device is powered, and off otherwise. I am not interested in monitoring it. I am only interested in AN2, and AN3. The test/circuit in the previous post was connecting to AN2 at the A-B points.

It looks like a low driven LED circuit.

The labels are as on the PCB. Can't see the whole number on D6.

Thank you!
tjk :)
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
Re: Feeding LED state into Arduino
« Reply #9 on: May 20, 2022, 05:56:58 am »
This helps out a lot!

I would expect the signals on pins 1 through 7 of the ULN2003 to be digital signals with respect to pin 8. That is, if you put your scope ground clip on pin 8 and probed, say, pin 5 you should see more or less a square wave corresponding to when the LED attached to pin 12 is turned on (the signal will be inverted).

Is your device is powered by a 24VAC transformer? If it is powered from an isolated supply it should be safe to probe the inputs of the ULN2003A as I described above -- i.e. with the ground clip connected to pin 8.

Some more things to check...

- is pin 8 of the 2003 connected to "24VAC COM"?
- is there a capacitor connected between the cathode of D6 and "24VAC COM"? (see the "half wave capacitor input load" diagram)



 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
Re: Feeding LED state into Arduino
« Reply #10 on: May 20, 2022, 07:43:20 pm »
Here's another thing to try...

place another LED and resistor pair in parallel with, say, AN3. That is, between point B and pin 12.

Code: [Select]

    B ----->|------/\/\/---- PIN 12


This new LED should light up whenever AN3 lights up. The ULN2003A should have enough oomph to drive both LEDs.
 
 

Offline tjkolevTopic starter

  • Contributor
  • Posts: 10
  • Country: us
Re: Feeding LED state into Arduino
« Reply #11 on: May 21, 2022, 02:42:28 am »
@ledtester,

First - I much appreciate your time staying with me and helping me troubleshoot my circuit. It's been fun an learning experience.

(1) I wired an LED with 1K resistor parallel to AN2. Both light up.
(2) I didn't feel comfortable probing the ULN2003 with the scope while the device was on. No good access, and it would be easy for me to shortcircuit some pins with unfortunate outcome.
(3) The whole device is powered from a regular 110VAC outlet. I was fairly certain the board/module in question was powered by a 24VAC transformer. I thought it would isolated. But may be not so much. The COM terminal has electrical continuity with any part of the device's frame or enclosure.
(4) There's no continuity between pin 8 of the 2003 and the 24VAC COM terminal. However - there's continuity between pin 8 and the full rectifier bridge. So some components are DC driven. I checked that while the device was powered off.
(5) There's no capacitor, or anything else between D6 and B. D6's cathode goes directly to the common anode for AN1 - AN3. However, there's a capacitor between D6 anode and COM. Well, the capacitor is across, and next to the 24VAC SEC/COM terminals.
(6) The original LED, AN2 does light up when I have my optocoupler circuit connected. I missed that question previously.

I am attaching an updated schematic.

Now,
Quote
- what exactly is your device and how is it powered?
I purposefully avoided mentioning that because I didn't want the conversation to derail. The LEDs I am trying to monitor are on the control board of my furnace.  ???

Thank you!
tjk :)

 

Offline ozcar

  • Frequent Contributor
  • **
  • Posts: 322
  • Country: au
Re: Feeding LED state into Arduino
« Reply #12 on: May 21, 2022, 07:39:57 pm »
So, while there is no direct connection between ULN pin 8 and COM, one of the diodes in the bridge is connected between those two points. This gives a path for current to flow from the "top" end of the transformer, through D6, and say AN3, R52, the ULN IC (when "on"), the diode in the bridge, and back to the other end of the transformer winding (COM). If there really is no capacitor from B to COM, then the current through the LEDs will be half-wave rectified pulses, something you would have to deal with if you choose to wire the input of your optocouplers in parallel with the LEDs.

The other option would be to investigate what voltage is used to drive the inputs of the ULN IC (between those inputs and pin 8 ), as that will presumably be DC, somehow derived from the + output of the bridge. That is assuming no need to monitor AN1, which will be on as long as the power is on.
« Last Edit: May 21, 2022, 07:42:25 pm by ozcar »
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
Re: Feeding LED state into Arduino
« Reply #13 on: May 21, 2022, 10:03:21 pm »
The LED you added to the ULN2003 is basically the same way you'd hook up an optocoupler.

However, given the device you are working with I would instead affix phototransistors over the LEDs to monitor their status. Might have to fiddle around with making the phototransistor sensitive enough but it would be a lot safer.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Feeding LED state into Arduino
« Reply #14 on: May 22, 2022, 06:48:45 pm »
diode from the LED output to a small capacitor, this will take the pulses and create a steady voltage. Then connect this voltage to a resistor feeding the base of a BJT, use the BJT collector connected to the MCU pin with the pin set to have a pullup resistor or ad an external one. When the LED is turned on the pin will be pulled low.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf