Serial communication over long distance

I'm using two USB To RJ45 and about 130 ft of cat6 cable (the adapter supports up to 150 ft) to connect an Arduino Mega with a PC and established serial communication. I've been having a weird problem, when I use a laptop or the pc with just the battery of the UPS everything works fine, but as soon as I plug the PC to the power outlet the communication is lost. What should I check?

Don't do that! The ground is a significantly different voltage at each end, that's to be expected.

Normally you'd use a 20mA current loop, or isolate at one end (for voltage serial), or switch to differential signalling with RS485 transceivers (which typically tolerate +/-7V or more common mode voltage offset).

An opto isolator at the receiving end is probably the simplest first thing to try.

Thanks for response,

I could only find how to implement optoisolators for specific I/O of the Arduino, how can I do this for the usb serial communication?

edruiz: I'm using two USB To RJ45 and about 130 ft of cat6 cable (the adapter supports up to 150 ft)

Link?

[quote author=Coding Badly link=msg=2719723 date=1461100954] Link?

[/quote]

here's the adpater

I would expect that kind of adaptor to have the appropriate optoisolators and EMI precautions. It may be a ripoff one without that protection, but it's probably ok.

How are you powering the Mega? On the USB power down this cable? That may not work very well.

MorganS: I would expect that kind of adaptor to have the appropriate optoisolators and EMI precautions. It may be a ripoff one without that protection, but it's probably ok.

How are you powering the Mega? On the USB power down this cable? That may not work very well.

I also tried powering it with an external DC adapter, got the same result.

Here's a picture of the adapter, It doesn't seem too complicated

That adapter probably does not have optoisolators, and in any case it is for USB signals, not "serial" as in TTL RS232 serial. You have a ground loop problem, and need optoisolated RS485 or similar adapters. Otherwise, you could easily fry the communications port of the PC.

jremington: That adapter probably does not have optoisolators, and in any case it is for USB signals, not "serial" as in TTL RS232 serial. You have a ground loop problem, and need optoisolated RS485 or similar adapters. Otherwise, you could easily fry the communications port of the PC.

Thanks!

Is there something else I should try while I get another adapter? I searched for the circuit of the optoisolator for usb but couldn't find it.

Will the HifimeDIY USB Isolator work for this?

That is more likely to work. At least the seller is clear that you will get a refund if it doesn't solve your problem.

Why aren't you using RS-485 ?

raschemmel: Why aren't you using RS-485 ?

I didn't have any RS-485 adapter and the RJ45 was working fine in shorter distances.

I tried with another RJ45 adapter, it supports longer distances and it has a 5V external power supply, so far everything is working fine, tested for about 10 hours without any disconnections. I order the HifimeDIY USB Isolator but it has not arrived, will try to tested as well.

That's a clever product.