Electronics > Microcontrollers

Feeding LED state into Arduino

(1/3) > >>

tjkolev:
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:
[attach=1]

LED off:
[attach=2]

Rick Law:
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). 

MikeK:
Does the Arduino have ADC inputs?  If so, can you just read the ADC a couple times in a row?

ledtester:

--- Quote from: tjkolev on April 20, 2022, 12:52:50 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?

--- End quote ---

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.

mikeho:
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.


Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version