Question

I want to control LED with C# using only USB port. I don't want to attach any other device with USB. I just want to attach LED directly to USB port pins and program it (blink etc). How can i do that? I am new to hardware programming and it will be my first program.

EDIT: I can do it already (blink LED) using printer port by attaching one led pin to data pin and other to ground. How can i do the same with USB port? My motherboard does not have a printer port. USB is the only option.

Was it helpful?

Solution

This is not possible.

4 usb pins

| | | |  
| | | |  
1 2 3 4

1: +5V
2: D-
3: D+
4: Ground

To trun on LED connect with 1 and 4

Current on Data pins is too low therefore LED will never turn on if connected with 5V and any Data pin. Hence LED can not be controlled directly using data pins on USB port

OTHER TIPS

Many mainboards will permanently supply USB ports with current.

You could theoretically put the USB controller into some suspend mode and back again but this is bad.

You'd need some sort of controller to accept commands over USB then some discrete elements to open/close current from the permanent USB supply and let it reach your LED.

You really can't do this. You can do it with a parallel port because you have individual control over the data pins. With USB, you only have control over the data the rides on top of the USB protocol. It's likely that protocol is being run in firmware by a chip on the motherboard anyway, so there's most likely no way to do what you want to do, short connecting the LED across the power pins and toggling the USB bus power, which you should NOT do for a whole variety of reasons.

Just get an Arduino or something. In the long run it will be a lot easier and be more flexible.

I can do it already (blink LED) using printer port...

OK, so why not buy a cheap USB based printer port and use that? Since you already have the LPT port code working, this gives you a transparent solution.

You could use a PIC microcontroller . The 18f series can directly interface led's over the usb . It is also possible to code using c# and use only the USB port to control the led . I'm guessing you actually want to control the led and not just get it to glow .

If you can clear the motive of controlling LED using USB then it will be very helpful to answer the Q:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top