Arduino USB Locking Up - Page 1
Forum section: electronics / beginners

author: JSanders
author_rank: Contributor
timestamp: July 25, 2023, 10:18:52 pm
content: Have an Ardunio UNO & relay board controlling A/C loads which occasionally locks up the USB Serial Port when switching things off / de-energizing the relays.The relay board is isolated through opto-couplers along with separate 5V power for the triggering circuit & relay coils. The triggering circuits, opto-couplers, are powered through the Arduino and the relay coils from a separate 5V A/C power adapter (wall wart).The Arduino continues to run when things freeze but the PC can no longer communicate with it over the USB connection. I’ve tried pressing the reset button on the Arduino, which restarts the program / sketch but still unable to communicate. The only solution is to unplug and reconnect the USB cable, then everything comes back to life.While I can see snubber diodes on the relay board, it’s still ‘electrically‘ noisy as I can hear static coming across the PC speakers every time the relay’s open / de-energize. This static varies from rather subtle & almost undetectable to others that are quite loud. I’ve tracked the USB connection locking up to when the static coming from the speakers is the loudest.I don’t understand how noise from the relays is making its way back to the PC through the USB connection, or why it’s causing things to lock up. I’ve been thinking about swapping out the mechanical relay board for a solid state version but not sure if that would solve the problem or not.Any suggestion or help would be appreciated – thanks.

author: tooki
author_rank: Super Contributor
timestamp: July 25, 2023, 10:52:40 pm
content: Yeah, the amount of noise depends on the load, and on where in the AC waveform the relay opens. A heavy load, switched right at the peak of the AC waveform, will produce the most noise.I see at least two failure modes:1. The genuine Arduino Uno doesn't use a regular off-the-shelf USB-to-serial converter chip (like the CP2102N used by the ESP32 boards, the FTDI FT232 used in lots of serial dongles, or the CP340G used in many cheap Arduino Uno clones), but instead uses a whole separate Atmega16U2 microcontroller running its own firmware. If the switching noise from your load is causing this MCU to crash (or even just its USB interface to get confused), pressing the reset button won't restart the Atmega16U2, because it has a separate reset line that isn't connected to the reset button. (It is, however, run to the Atmega16U2's programming header, ICSP1.)2. The switching noise from your load is causing enough interference on the USB data lines to cause the PC's USB interface to get confused.Understanding these failure modes might help you diagnose where the problem lies.Anyhow, some fixes to try:- Have the loads, PC, and Arduino circuits all powered from the same outlet, so they're on the same circuit, as close together as possible, electrically speaking.- Get a better USB cable. Most standard USB cables have basically the minimum shielding. Better cables may do better. If you have some with ferrites on them (those bulbous cylinders sometimes found a few inches away from either end of the cable), try that.- Connect each low-voltage wire going to/from the relay board using twisted-pair wire, where each pair has a ground. (That is, each signal wire and each 5V wire should be twisted with its own ground wire.) This makes the pair much more resistant to induced noise.- Add filtering (like common-mode chokes and capacitors) to the AC wiring.- Add filtering (like common-mode chokes and capacitors, or simple RC low-pass filters) to the DC wiring.- Swap out the mechanical relays for solid-state relays (SSRs) that use zero-crossing switching. (That is, those always wait until the next zero-crossing of the AC waveform to switch on or off, so you're basically never switching under load, no matter how big the actual load is. Most, but not all, AC SSRs are the zero-crossing type.)-- If the load is safety-critical (e.g. a device that could burn your house down if it got left on too long), use a belt and suspenders approach, just in case an SSR fails closed: Use both mechanical relaysandSSRs for each load. When turning on, close the mechanical relay first, then close the SSR. When turning off, open the SSR first, then the mechanical relay. That way, the mechanical relay is never switched under load.

author: aduinstat
author_rank: Contributor
timestamp: July 25, 2023, 11:38:41 pm
content: You are breaking the isolation between the coils and Arduino when you connect the ground to the Arduino. Disconnect that and see if it works.The opto-isolators have LEDs that are driven directly from your IO pins, so you don't need a common ground (your IO are low side switches).

author: tooki
author_rank: Super Contributor
timestamp: July 26, 2023, 12:09:03 am
content: Quote from: aduinstat on July 25, 2023, 11:38:41 pmExcept that, despite having optoisolators, those relay modules don't have the relay coils galvanically isolated. There's no separate ground for them -- all you can do is remove a jumper to provide them with their own 5V supply. Refer to the attached photo.

author: amyk
author_rank: Super Contributor
timestamp: July 26, 2023, 12:13:48 am
content: "A/C loads"? Air conditioners? Those areveryhigh in startup current and also high in running current, and I suspect you're getting lots of arcing across the contacts when disconnecting them, which emits EMI and causes the crash. Check that your relays are actually rated to break the load current. Other solutions to reduce arcing:https://electronics.stackexchange.com/questions/474780/reduce-remove-sparks-in-ac-and-dc-contacts-of-relays

author: tooki
author_rank: Super Contributor
timestamp: July 26, 2023, 12:17:22 am
content: Quote from: amyk on July 26, 2023, 12:13:48 amGiven that they later mention a "5V A/C power adapter", I think they simply mean alternating current, not air conditioning. (It used to be much more common to write A/C and D/C for alternating and direct current, respectively.)

author: aduinstat
author_rank: Contributor
timestamp: July 26, 2023, 12:18:56 am
content: Quote from: tooki on July 26, 2023, 12:09:03 amLooks isolated to me.

author: tooki
author_rank: Super Contributor
timestamp: July 26, 2023, 12:37:59 am
content: Quote from: aduinstat on July 26, 2023, 12:18:56 amOh, you're right. That's different from the one I have here at home. My mistake! I think it's time for bed...

author: jmelson
author_rank: Super Contributor
timestamp: July 26, 2023, 01:04:33 am
content: J? pin 1 is connected to the LED anodes. J? pin 2 is connected to the relay drivers. What is connected to J? and can it maintain EMI isolation between pins 1 and 2?Jon

author: JSanders
author_rank: Contributor
timestamp: July 26, 2023, 02:01:20 pm
content: Thanks everyone for all the replies.aduinstatPulled the ground wire from the Arduino, running things right now to see if it works. Originally used the common ground as plan to add 5V sensors once things become stable.The relay board in use has low-level triggers, (seems most mechanical relay boards with separate VCC only have low-level triggers), however did just find a high-level version I’d like to use, would it require the use of the common ground wire?TookiThanks for all the info, started out looking to use solid-state relays but didn’t want to deal with the unknown failure state. Thought the same about ‘daisy-chaining’ mechanical relays till I read the specs and saw the limited current rating of the solid-state relay at 2 amps.Ended up using an Arduino knock off board I had laying around, not sure what chip is being used but really appreciate the details about the reset line ICSP1. Has me wondering if there would ever be a reason in trying to programmatically reset the USB serial chip.If pulling the ground wire doesn’t work plan on following some of your suggestions. Pretty sure the USB cable I’m using isn’t of very high quality and easily replaceable. Bit more work to add some filtering, have to see how things go.

author: tooki
author_rank: Super Contributor
timestamp: July 26, 2023, 11:43:17 pm
content: Quote from: JSanders on July 26, 2023, 02:01:20 pmYou can get SSRs with far higher current handling than that. If you don’t need galvanic isolation, the driver can be as simple as a series resistor to an MCU pin.

author: JSanders
author_rank: Contributor
timestamp: July 27, 2023, 01:48:05 am
content: Thanks, have to check out other solid-state relays & there ratings.Also trying to find more information on the NOYITO relay board, especially details about the TRV jumpers. Was wondering if anybody has or run across a circuit diagram / schematic?All I have is the pdf manual.

author: JustMeHere
author_rank: Frequent Contributor
timestamp: July 27, 2023, 05:00:40 am
content: It's been awhile since I've messed with an Arduino, but I do remember that if you did not read the serial out data things would go stupid. Basically if you're writing serial from the main chip, you must consume it. I guess a buffer got filled up.It's been well over a decade, but I do remember something like this.

author: JSanders
author_rank: Contributor
timestamp: July 27, 2023, 09:19:24 pm
content: Pulling the ground from the Arduino didn’t fix the problem, serial connection still locked up. Grabbed a new USB cable advertised as ‘multi-shielded’ and the PC speakers went silent, no more static.Been running things since this morning without issue and while the cable might have ‘solved’ the problem, more of a Band-Aid fix then anything. Going to add some filtering as there has to be an awful lot of noise for this to have happened in the first place. Thanks for all the help.

author: tooki
author_rank: Super Contributor
timestamp: July 27, 2023, 11:21:37 pm
content: Eh, not necessarily a band-aid. A lot of USB cables are stupidly cheap, and don’t really meet the standards, the transceivers are just good enough to tolerate shitty cables. It’s more of a miracle that it usually works at all given the abysmal quality of so many cables.