Reading External LED Value for KVM Switch

Hi folks,

I’m currently looking at using an Arduino Nano for a computer desk I’m building - using it as a sort of KVM switch between the desk PC and a laptop by connecting it to a couple of DisplayPort switches and a USB switch, and I’m struggling to read which “side” is currently in use (eg. PC or laptop). I’m pretty new to the electronics side of things, so apologies if I’ve left any key information out.

The components I’m using are as follows (from Amazon):

  • CABLEDECONN DisplayPort 8K DP Switch x2 (I’ve read 3.3V from the switch)
  • Arduino Nano ATmega328P and CH340

The schematic below shows how I’m trying to test the voltage. The part in the green box is the DisplayPort switch, and is on it’s own PCB with external USB power, so they’re connected to other parts I don’t have the datasheet to. I’m just tapping into it by soldering some wires onto the board. When pressed and released, the switch turns one of the LED’s off and the other one on to show which side is active.

When I try to connect the DP/USB LED’s to A0/GND, I’m not getting much sense from the values. One side reads ~660, then when I switch it the value fluctuates up and down from 0 to ~660. Any ideas where I go from here?

As an aside, when I attach a multimeter to the switch, it reads 0 when the button is closed and 3.3V when open, whereas the LED’s read 1.4V when on and 0 when off.

1 Like

In which case the schematic is useless, isn’t it?

Your “R” and “G” LEDs are connected in reverse.

@Paul_B thanks for the reply - the schematic was definitely useless looking over it. I’ve edited my post completely and simplified everything to more focus on the issue I’m trying to solve, hopefully it’s more clear.

Well, I think I have more of an idea now. :+1:

If you are connecting directly across the LED in the switch box, then 660 on an analogRead sounds about right for the voltage across the LED when lit. When not lit, there is effectively no connection at all so your input pin is reading a random voltage below the threshold of the LED.

You really want to find the connections not just across the LED, but across the LED and its current limiting resistor in which case you should get a full 5 V logic level. And if you put say, a 22k resistor across that, it will pull down to ground when the LED is not lit.

Presumably you have checked with your multimeter that the point on the board that you have connected to your Arduino ground is actually ground on the KVM switch.

Thanks for the response @Paul_B that's making a bit more sense in my head now.

If you are connecting directly across the LED in the switch box, then 660 on an analogRead sounds about right for the voltage across the LED when lit. When not lit, there is effectively no connection at all so your input pin is reading a random voltage below the threshold of the LED.

This makes a lot of sense, I was wondering why the voltage fluctuated, but you've cleared that up nicely.

Presumably you have checked with your multimeter that the point on the board that you have connected to your Arduino ground is actually ground on the KVM switch.

So I was just connecting the anode of the switch's LED to A0, and the cathode to GND, which I presume is attached to ground on the switch. I tested they were the right way around with the multimeter, and got a positive voltage of 1.4V when on, is that what you mean here or am I off base?

You really want to find the connections not just across the LED, but across the LED and its current limiting resistor in which case you should get a full 5 V logic level. And if you put say, a 22k resistor across that, it will pull down to ground when the LED is not lit.

This makes sense to me in theory - so there's a resistor within the switch which is reducing the current so the LED is at the correct level. I think I've found it for each LED but it's tiny, so I might have some trouble soldering a wire to it. Just to show you what I'm working with, here's a picture of the switch:

I was going to try add a 22k resistor as suggested and test that path, but for some reason whenever I now connect the cathode to the Arduino, the LED lights up regardless of which side is supposed to be on, meaning both lights can be on at the same time when they shouldn't be, which has me completely confused. I'm wondering if I should just keep the circuits separate and use an optocoupler, or am I overcomplicating things here?

Just for clarity, the code I'm using for the test is:

#define dpOneLED A0    // Pin for DisplayPort switch 1 LED (PC Side)

void setup() {
  Serial.begin(9600);
}

void loop() {
  int dpOneLEDValue = analogRead(dpOneLED);
  Serial.print("DP1: ");
  Serial.println(dpOneLEDValue);
  delay(500); 
}

Side observation.

In the many years I have used KVM equipment I have never seen the need for this approach.
I will either learn something new or it may be over engineering something.

@Ballscrewbob just to give a bit of context - the main goal of the project is to create a Frankenstein KVM switch within a PC desk I've built, using 2 DisplayPort switches (one of which is above), and one USB switch. These will switch between the desk PC and a laptop, depending on what I want to use.

They're separate as I want to be able to control them separately (eg. having a monitor for the PC, and another for the laptop), and have 4 capacitive buttons within the top of the desk which do the following:

  1. Switch DP1
  2. Switch DP2
  3. Switch USB
  4. Switch all to either PC or laptop depending on some logic I haven't quite decided on yet eg. if the keyboard is on PC then move both monitors to PC if they're not already etc.

I've got all the switching stuff working and can individually swap the monitors/usb ports by clicking on their relevant buttons, but the "All" button relies on knowing which side of each is currently in use, which is why I'm trying to read the value of the LED and am struggling.

But you're probably right - I'm likely overengineering something :slight_smile:

presume

There's the problem. :roll_eyes:

What you really need to determine is how the LEDs are wired in the KVM switch. We know it operates at 5 V, but either it switches the negative end of the LED/ resistor pair to ground, or the positive end to 5 V.

If you connect your Nano ground to the negative end which happens to be the one being switched, then when you connect your various devices together via the USB connections, you will be grounding the switched connection and of course that will light the LED.

That is why you need to test what is connected to what with the multimeter.

Ahh I get you! So essentially when I'm connecting the LED to the arduino, I have something like the following circuit, which is obviously causing the LED to stay lit as the circuit is complete:

I used the multimeter continuity function to test the ground of the pushbutton switch to the ground of the USB power and that's connected, whereas the LED negatives are not, so that seems to line up with what you're saying.

So what I need to do is something like this, by connecting the arduino ground to the actual DP switch ground (eg. through the pushbutton switch), and putting a 22k resistor between the LED positive end and A0:

I'll need to wait until tomorrow to test it out, but hopefully I'm on the right track. Thanks for clearing that up for me, really appreciate it!

No, what you have illustrated will just tell you that there is power on the KVM switch.

You need to connect ground to ground as shown (and this is always the principle). Then you need to connect the Nano input (preferably through a 10k protective resistor) to the LED cathode, and provide a pull-up resistor from the LED cathode to 5 V. Using INPUT_PULLUP may suffice, if not then the 22k.

Note, the 22k pull-up connected to the LED cathode, not the Nano input pin.

This will read HIGH when the LED is not illuminated and LOW when either it is illuminated or the KVM power is off. :grin:

So I've done a bit of reading on both ground and pull-up/down resistors and I'm trying to imagine the flow of current through the circuit in both switched cases here. I have the following schematics with the green wires representing what I believe the flow should be in each case. Am I in the right ballpark, or should I be hitting the textbooks again?

No joy, I'm definitely messing up my circuit somewhere. Either way I've had plenty of gaps in my knowledge filled so at least I have a path forward, whereas before I just didn't know where to go. Thanks a mil for your help and your patience with everything!