I have the following relay board (pictured below), and to activate any of the relays, you simply connect one of the IN1-IN8 pins to ground. Easy. The current going between gnd and INx is negligible, because of the transistors already on the board, so the current going through the serial port of the PC is not an issue.

How can I electronically use the serial port to to activate a relay on this board? I'm not concerned about the software aspect of it. The standard serial port has DTR and RTS (pin 4 and 7) that can be set high or low through software. I believe that "high" on a serial port is -3 to -25 volts and "low" on a serial port is +3 to +25 volts.

Is there some easy way to use that to set IN1 to GND? Look at the schematic below, and see if there is an easy way to accomplish this:

By the way, VCC and JD-VCC are connected together with the jumper, I'm not doing high voltage or concerned about isolation.


  • \$\begingroup\$ This isn't really a good solution. You are looking for a current sink for the opto LED. The serial port may not be able to do this. "_ The current going between gnd and INx is negligible ..._". It must be 5 mA or so to drive the LED. That's not negligible for a serial port. "By the way, VCC and JD-VCC are connected together with the jumper ...". You might need to model how this would affect the serial port. Is there no USB breakout board you could use instead? \$\endgroup\$ – Transistor May 20 '16 at 22:27
  • \$\begingroup\$ "Is there no USB breakout board you could use instead?" Sure, I could use something like a serial or usb relay board and be done with it, and I may have to do that, but I am trying to keep the hardware to a minimum and this board already has plenty of relays that I'm using with other devices that do a dry closure. The PC won't do a dry closure without additional hardware, unless as I was hoping, that the serial port could somehow pull the input low. \$\endgroup\$ – JMain May 21 '16 at 0:36


simulate this circuit – Schematic created using CircuitLab

Figure 1. Serial to relay-board interface.

This circuit should work.

  • When serial-out line goes positive Q1 is turned on via R1. This will turn on the opto-LED on the relay board.
  • When serial-out line goes negative Q1 will be turned off and D1 will prevent the base of Q1 being pulled more than 0.7 V negative.

Relay board GND needs to be connected to serial port GND - pin 5 on the 9-pin PC port or pin 7 on the 25-pin port.

Q1 can be any small signal NPN transistor with a Vce greater than your relay board supply voltage subject to base current below.

+/-25 V seems extreme for RS232-type serial port. I always thought it was +/-12 V. Most devices use something like the MAX232 chips to double the 5 V supply to give 8 or 9 V out for reliability. Working on +12V on Ser-Out you would get 12 mA into the base of Q1 which should be fine for something like the 2N2222. D1 will easily handle the reverse current. If you really expect Ser-Out > 12 V increase the value of R1 accordingly.

  • \$\begingroup\$ This looks like it is going to be the answer. What is the value of Q1? Also, confirm that your circuit can handle voltages from -25 to +25 volts. \$\endgroup\$ – JMain May 21 '16 at 16:09
  • \$\begingroup\$ Update: added two more paragraphs. \$\endgroup\$ – Transistor May 21 '16 at 16:27
  • \$\begingroup\$ I think you are correct that most serial ports probably only do around 12 volts, but the official RS232 specs states "up to 25" volts, either + or -. \$\endgroup\$ – JMain May 21 '16 at 16:37

If by Electronically you mean by Software, yes you can Programmatically Toggle a Specific Serial Line. In LabVIEW this would look as follows:

Toggle a Specific Serial Line in LabVIEW

In Python you can use the pySerial Library, where the code would look like this:

__init__(port=None, baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=None, xonxoff=False, rtscts=False, write_timeout=None, dsrdtr=False, inter_byte_timeout=None),

where rtscts=False sets RTS to Low and drsdtr=False sets DTR to low.

And you are right, the Serial Port Voltages can reach from -25 to +25 Volts, but in most cases it will be around -10 to 10 Volts.

  • 1
    \$\begingroup\$ "I'm not concerned about the software aspect of it." \$\endgroup\$ – JMain May 21 '16 at 0:33

This is an 8 realy board. A standard (9 pin) serial port doesn't have 8 outputs. Are you going to use (at least) 2 serial ports?

The quickest solution would be to put an Arduino (Uno or Nano) between your PC and the relay board. Or, for the more adventurous: an FT245RL usb-to-parallel chip.

If you realy want to use serial ports: use the pins that are outputs. My gut feeling is that they can drive your optocouplers directly (disconnect VCC-JDvcc, connect VCC to the serial ground).

If this doesn't activate the relays, use a transistor per input as 'transistor' suggests (how could he suggest anything else!), or an ULN2803 for 8 lines.

  • \$\begingroup\$ Not 8, only 1: "Is there some easy way to use that to set IN1 to GND?" \$\endgroup\$ – JMain May 21 '16 at 16:05
  • \$\begingroup\$ OK, that would invalidate my first sentence. The rest is still valid. \$\endgroup\$ – Wouter van Ooijen May 21 '16 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.