Connect LED via USB [closed]

20

How can I send a 5V pulse via a USB?

Imagine a USB cable that has 4 wires (one generates 5V and the other negative pole). The two central strands remain. My question is how can I read via Delphi that these cables are getting 5V?

Objective : Capture signal for counting units via Serial.

Idea : Using a USB cable open an electric lock.

The program I'm developing would send a 5V pulse. The idea is to connect this wrist to one of the USB cables.

Doubt :

  • How can I send a 5v pulse via USB cable?
  • Regarding sending: In C # how to connect and disconnect an LED via USB. Because direct calling is easy using normal USB power.
  • asked by anonymous 29.01.2015 / 16:18

    3 answers

    8

    Let's go by parts ...

    The Universal Serial Bus (USB) is a serial communication protocol used to perform communication between peripherals, considering that a peripheral is composed of a "processing center" is erroneous to realize the activation of a LED only sending a signal via D + and D-. Roughly the LED does not know to read commands that arrive via serial connection.

    You can use electronic prototyping platforms, among them Arduino.

    Basically what you would do would be to develop and compile a code for Arduino where in that code you would receive command from your program (C #, Delphi, C ++) via USB and activate the actuators like LEDs, Relays and etc ...

    You can learn more about:

    link and link

    I also have my course completion topic which shows a business development model with Arduino.

    link

    An example:

    Let's say you want to turn on an LED X period of time using an Arduino, you can use this code:

    / * 
       Acende um LED por um segundo, então fora por um segundo, repetidamente. 
       Este exemplo de código é de domínio público. 
    * /
    
    void setup () 
    {
       // Inicializa o pino digital como uma saída.
       // Pin 13 tem um LED conectado na maioria das placas Arduino:
       pinMode (13, OUTPUT);
    }
    
    void loop () 
    {
       digitalWrite (13, HIGH); / / set o LED
       delay (1000); / esperar / por um segundo
       digitalWrite (13, LOW); / / definir o off LED
       delay (1000); / esperar / por um segundo
    }
    
        
    30.01.2015 / 12:58
    6

    Not because ...

    You can not do this in a "Beautiful" way, a solution would be to turn off and on the USB output, but I'm pretty sure that OS will not let you do it that easy.

    USB is fully dedicated to passing information, but on the cable you find + 5V and GND outputs for powering the plugged devices.

    Controlling an electronic device by programming

    First you need to understand electronics, at least the minimum (current, resistance..etc) you can use a microcontroller or a circuit capable of communicating with a computer, nowadays Arduino has become the easiest platform and simple implementation of projects for lay developers, arduino can be programmed in java, c, python being the form adopted by the community.

    Printing Data in the Serial Output

    int pushButton = 2;
    void setup() {
    
      Serial.begin(9600);
      // informa que pino "2" é uma entrada de dados
      pinMode(pushButton, INPUT);
    }
    
    void loop() {
      // faz a leitura da saida "2" do dispositivo 
      int buttonState = digitalRead(pushButton);
      // Mostra isso na saida Serial
      Serial.println(buttonState);
      delay(1);
    }
    

    You can make your program communicate with another through the serial port.

    Arduino communication with serial port in python

    Python is a language with many facilitations, there is module for almost anything, including arduino, web, interfaces ...

    #!/usr/bin/env python
    """
     Blinks an LED on digital pin 13
     in 1 second intervals
    """
    
    from Arduino import Arduino
    import time
    
    board = Arduino('9600') #plugged in via USB, serial com at rate 9600
    board.pinMode(13, "OUTPUT")
    
    while True:
        board.digitalWrite(13, "LOW")
        time.sleep(1)
        board.digitalWrite(13, "HIGH")
        time.sleep(1)
    

    Check out the documentation Python-Arduino

        
    03.02.2015 / 22:41
    1

    A further option is to use the Comx serial port as follows using pin 4 (DTR) in old DOS would be mode Com1 dtr = off / on

    db9 connector Pin 4 = DTR Pin 5 GND Via software triggering pin 4 connect resistor in series with led type 4 --- xxxx ---- led ----- 5 in the old DOS (window) Mode Com2 dtr = ON > > > turn on the led               OFF > > > turn off the led

        
    14.04.2016 / 02:20