Hi Everyone!

Need help in my new Project with Visual Basic 6..
I need to send a 5 volts signal from my pc using a VB6 program
to the serial port where I could place a relay...

Thanks :)

Dexter A.

Dani AI

Generated

Quick clarification and a safer, reusable approach (for future readers): was right to flag that the PC serial interface does not behave like a 0–5V GPIO pin. Serial control/data lines use bipolar signaling and are not directly compatible with TTL/relay coils — you need level conversion and a proper driver. RS-232 overview. (en.wikipedia.org)

A robust, low-effort pattern that works in most hobby/legacy-PC projects:

  • Convert the DB‑9 RS‑232 signals to logic levels with an RS‑232 transceiver (MAX232 family or equivalent).
  • Feed the resulting TTL logic into a relay driver (a ULN2003/ULN2803 or a single transistor/MOSFET plus a flyback diode) and power the relay coil from a separate 5V supply.
    This separates the port from the coil current and uses the driver’s built‑in protection where available. See the MAX232 conversion concept and the ULN2003 relay-driver family for details. MAX232 info. (en.wikipedia.org)

If you prefer software simplicity over wiring, a USB‑to‑TTL module (FTDI/CP210x) that exposes TTL control lines or supports bit‑bang/CBUS GPIO is often the fastest route: it gives true 5V logic outputs you can toggle from a VB6 app without DB‑9 level tricks. Check FTDI application notes for bit‑bang/CBUS options. FTDI docs. (ftdichip.com)

Practical checks before wiring: measure the line with a multimeter to confirm whether you have RS‑232 or TTL; do not power a relay coil from the COM port; always use an external supply and a flyback diode or driver IC; and consider an opto‑isolated relay board if switching mains. For relay‑drive basics and protection, see the SparkFun/Adafruit tutorials. Relay drive fundamentals. (learn.sparkfun.com)

Summary: convert levels, use a dedicated driver (or a commercial serial‑relay board), and keep the coil power off the port. This preserves the serial port and gives reliable 5V switching for your relay.

Recommended Answers

All 5 Replies

You can try to do it with MSComm.RTSEnable = true.

If you dont know pinnings in serial port.

1 = DCD
2 = RXD#
3 = TXD#
4 = DTR
5 = GND
6 = DST
7 = RST
8 = CTS
9 = RI

I hope that will work. Just don't connect something that will burn your com port.

Oh i all most forgot comm port is +10 V when he gives signal and -10V when hes not active.

Correction of command for activation MSComm.portopen = true and voltage between pins 5-7 will be +10V when its disabled voltage will be -10V you will need some electronics to make it 0-10, diode and drive relay with transistor and external power supplay just to make sure u dont burn serial port.

thanks I'll try this.:)

i've connected the rs232 with an rs485 but the output voltage signal is still 2v.

Ahh I got it, tnx Teropod. your codes works. :twisted:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.