Switch load using COM port

I was asked to switch load using computer’s COM port (RS232). At first, I was thinking, that I need to switch some lamp or heater, so I offered to use solid state relay and forget all the electronics. But later, I was explained, that I need to manage wireless access point connected to router. As the access point tends to hang-up the administrator need to reboot it. Automatically from linux router script.

I offered simple variant- use the mosfet. Here is the first version of the device in mine breadboard… somewhere in this image. 🙂

RS232 DTR as power on switch

The only device in this circuit is mosfet. I used IXFH50N20. Why? Because I have lots of them. This transistor is quite powerful- up to 50A load, 200V and only 45mΩ source-drain resistance when on. Other interesting parameter- the gate can withstand +-20V (30V in pulse). So I can connect the gate to RS232 levels without any problem. I used target 5 port UTP switch as the load.

circuit of RS232 power switch

There is small problem with this circuit. The load must be separated from the ground as the mosfet cuts the ground line. Practically it is quite difficult to attach device to computer without connecting ground plane. This circuit is good for switching some lamp, relay or heater.

Now other version:

circuit of RS232 power switch

Now n-channel mosfet is connected in strange way. It is hang-up in the air. There is problem with this circuit. We need to supply at least 4V to gate to open the device. But as device is “in the air” the gate potential is calculated in respect that the PSU of the load. The load must be less than RS232 level minus gate open voltage. As my computer give -11 and +11.75 on the DTR line. So if the load PSU is about 7V everything is OK. When I tested with 12V PSU the mosfet was not open quite well and it was getting warm.

Check your PSU and RS232 voltage levels before using this circuit!

If we want to use proper circuit, we must use “High-Side, N-Channel MOSFET Switch Driver” chip.
Or we can use P-channel mosfet. For testing, I found SFP9520. It is a bit weaker device, but is quite useful for access point manage.

circuit of RS232 power switch

Only we need to invert the DTR signal. Also, when computer is off the load is connected.

About Administrator

I am owner of this site.
This entry was posted in Anything. Bookmark the permalink.

One Response to Switch load using COM port

  1. Control program by Eimis.

    execute “gcc file.c -o executable” to compile.

    #include <sys/types.h>
    #include <sys/ioctl.h>
    #include <fcntl.h>
    #include <errno.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <stdio.h>
    #include <signal.h>
    #include <termios.h>
    /* Main program. */
    int main(int argc, char **argv)
    {
    int fd;
    int status;
    int set_bits;
    /* Open monitor device. */
    if ((fd = open(argv[1], O_RDWR | O_NDELAY)) < 0) {
    fprintf(stderr, "ar-2: %s: %s\n",
    argv[1], sys_errlist[errno]);
    exit(1);
    }
    ioctl(fd, TIOCMGET, &status);
    set_bits=2;
    ioctl(fd, TIOCMSET, &set_bits);
    // Nutraukus maitinimą laukti 10 sekundžių
    sleep(10);
    ioctl(fd, TIOCMGET, &status);
    if (status & TIOCM_DTR) {
    set_bits=0;
    ioctl(fd, TIOCMSET, &set_bits);
    }
    close(fd);
    }

Leave a Reply

Your email address will not be published. Required fields are marked *