I have an Arduino (Pro Mini) connected to an HMI display with a serial interface. When the user pushes a button on the HMI screen, it activates a relay attached to one of the digital pins on the Arduino.

For safety reasons, if the Arduino loses communications with the HMI, I want it to turn off the relay. So, when the button has been pushed, it triggers a polling sequence to verify that the button is still being pushed (I'm not relying on the button release event, again for safety). Essentially, the Arduino queries the HIM for a value. If none isn't returned within 100ms, the code times out and kills the relay. As I said, the code works if I pull the RX, TX or Ground connections from the HIM, the code kills the relay and everything keeps working fine. Pull the Bcc from the screen, though and stretching freezer with the relay engaged.

A few notes:

  • The Arduino and HMI share a common 5V supply, but the HMI doesn't draw power from the Arduino
  • It's a TTL level serial connection, not RS-232
  • I don't think it matters, but the Arduino is using software serial on GPIO pins, not the built-in UART.
  • The serial connection is running at 19.2K

My best guess, and it is a guess, is that the HMI screen momentarily attempts to draw current or dump a load via the I/O lines when it loses it's power source. This appears to be enough to cause the MCU to freeze not sure why.

Any suggestions? Should I have something in parallel with the data lines to protect the MCU?

What could be causing this, and what can I do to overcome the problem?

  • 1
    \$\begingroup\$ Are you sure that the MCU is freezing, as in the program counter is not moving, or is stuck in some kind of ISR? Have you debugged the Arduino side? Can you blink an LED to verify that the LED stops blinking (or stays on)? \$\endgroup\$
    – Ron Beyer
    Dec 6 '17 at 4:42
  • \$\begingroup\$ Yes, quite sure. The screen isn't my only interface. I have other inputs that trigger LEDs and the Serial interface to the PC stops receiving debug data. Even after I reattach the screen, I have to reset the Arduino to get it to respond to anything. \$\endgroup\$
    – Prdufresne
    Dec 6 '17 at 5:40
  • \$\begingroup\$ @RonBeyer After some further testing this morning, I discovered a couple of things. The RX pin I was using for my software serial did not have a hardware interrupt, so moved the serial to different pins. The system is still locking up when I cut power to the display, but I regain control when power is restored to the HMI. I'm not really sure what to make of this change in behavior, but it still hasn't solved my core issue. \$\endgroup\$
    – Prdufresne
    Dec 6 '17 at 20:38
  • \$\begingroup\$ Program the MCU with a blinky LED program. Absolutely minimal program which: (1) shows lifesigns when it runs, so you know when it freezes (2) doesn't talk or listen to anything, so it can't get stuck for software-defined reasons. Repeat your test scenario. If the minimal program doesn't freeze, then your original freezing was software-defined (or at least software-enabled). \$\endgroup\$ Dec 6 '17 at 20:50
  • \$\begingroup\$ @NickAlexeev I already did that. I reduced my sketch to do nothing but define the software serial but not attempt to transfer any data with it. When I pull the power to the HMI, the LED stops blinking. If it was on, it stays on and vice versa. I also did some probing, and found that when the screen has no power, the TX line reads 0V, as if it's clamped to ground whereas the RX pin (pin 2) on the Arduino reads 5V, I assume because of the internal pullup resistor. \$\endgroup\$
    – Prdufresne
    Dec 6 '17 at 21:35

You need to carefully evaluate how the relay is hooked up. There are two big issues with the relay that can definitely cause an MCU's software to go out to the weeds. This comes from internal disturbance of the MCU execution due to out of spec supply lines or out of spec voltages present on GPIO pins.

The Relay Coil

Relay coils are inductive loads and can cause spikes to occur, particularly when the relay coil becomes un-energized. But supply and GND surges and spikes can also occur when the relay becomes energized, because in some cases the change of current flow that occurs at time of switch on can be significant with a low resistance relay coil.

Some things to deal with and consider:

  1. Make sure there is a flyback clamping diode across the relay coil.
  2. Consider to operate the relay off a separate power rail than the MCU and then buffer the drive to the relay coil through a buffer transistor that isolates relay coil current away from the MCU.
  3. If a completely separate voltage rail is available with isolated GND consider running the relay coil off that and isolate between the MCU and the relay with an opto-coupler.
  4. Verify that you have sufficient filtering capacitors on the MCU supply rail.
  5. Ensure that there is proper high frequency bypass capacitance right across the MCU PWR/GND pins.
  6. Make sure that there is not an bad circuit design on the GPIO driving the relay that taxes the pin drive capabilities beyond the spec ratings.
  7. Look carefully at how the actual connections to the relay coil are made. Make sure that there are not careless long wires that themselves can create noise coupling to the rest of the circuit.

The Relay Contacts

Relay contacts can be a nightmare in the amount of noise generated. This is especially true when high voltage or high currents are switched. Here are some of the things to consider taking a look at:

  1. Make sure that whatever wiring is associated with the relay contacts is routed away from the rest of the MCU circuitry.
  2. Sometimes it is necessary to add snubber circuit components across the relay switch contacts to reduce the amount of noise generated when contacts open and close.
  3. Relay contacts are known to bounce and cause multiple opening and closing of the load switching. In some cases it may be possible to select a different type of relay to reduce this effect and thus reduce generated noise.
  • \$\begingroup\$ I appreciate the feedback, however the relays aren't the issue. There are optocouplers between the Arduino and the relays. When the screen is connected, I can switch them on and off all day. The issue is only relayed to the HMI display when I cut power to it. \$\endgroup\$
    – Prdufresne
    Dec 6 '17 at 5:44
  • \$\begingroup\$ To be clear, when I cut power to the HMI, I'm trying to simulate a failure. Under normal conditions, the power should never be removed. I'm trying to code in fault handlers. \$\endgroup\$
    – Prdufresne
    Dec 6 '17 at 5:55

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.