I have an Arduino (Pro Mini) connected to an HMI display over serial. 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).

The following code works perfectly if I disconnect either of the signal lines (tx or rx) or ground from the HMI. If I disconnect the +5 volts, however, the Arduino freezes completely, and therefore never shuts down the relay.

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

The code is as follows, however, it works as expected if the data lines or ground are severed.

int getNumber(const char *reqString)

  long startTime = currentMillis;
  long waitTimer = currentMillis - startTime;

  bool responded = false;
  int endcount = 0;
  byte inbyte;
  byte bytebuffer[80];
  int bytecount = 0;

  while (waitTimer < 100 && !responded)

      if (HMI.available())
        inbyte = HMI.read();

        if (inbyte == 0xFF)
          if (endcount == 3)
            responded = true;
            endcount = 0;
          endcount = 0;

        bytebuffer[bytecount] = inbyte;

      // Update the wait Timer.
      waitTimer = millis() - startTime;

  // If we received a response, return the first data byte. If not, return 0
  if (responded)
     Serial.println("Received response");
     return bytebuffer[1];
 Serial.println("No response");
     return 0;
  • The more time I spend troubleshooting this, the more I think it's an electrical issue. When I disconnect the power from the display, either' s attempting to draw power or discharge a load through the data lines. As I said in the post, the code works when I disconnect either data line or the ground. – Prdufresne Dec 6 '17 at 1:43
  • 1
    Can you post also the schematic? – frarugi87 Dec 6 '17 at 15:24
  • I will have the generate a schematic first. Simply, though, the Arduino and the HIM are both connected to a common 5VDC bench supply. The HMI TX line is connected to pin 2 and the HMI RX line to pin 3. – Prdufresne Dec 6 '17 at 15:30
  • I did some probing. It appears that the software serial enables the internal pullup resistor, because I always read 5V when nothing is connected to the pin. The HMI, on the other hand, appears to clamp the TX line to ground when it has no power. Armed with this, I shorted the RX pin (pin 2) on the Arduino to ground and got the same result. The unit freezes. – Prdufresne Dec 6 '17 at 21:38
  • Yes, I thought it could be this, but there isn't any place in the code which actually blocks this, unless a lot of pin changes happen. The problem is that the "idle" state of the serial wire is +5V (that's why the TX wire goes to +5V). You will have to double check first of all what happens when you apply 5V on a pin of the unpowered HMI (if it is not protected you can also break it). Then you will need a way to cope with the fact that you receive an invalid idle state. The solutions I can see are 1) don't use SoftwareSerial 2) pull a wire with the HMI 5V to the arduino, and use it to [...] – frarugi87 Dec 7 '17 at 9:25

It seems that Software Serial is waiting for "high" on RX

Only a hardware solution comes to my mind


simulate this circuit – Schematic created using CircuitLab

This way Arduino RX will be released on HMI power loss

Later edit

You can also use the watchdog timer to unfreeze your code when unresponsive. It will reset the Arduino if wdt_reset() is not called in a given amount of time and you can make the cleaning you need before using Software Serial again. Here is a useful tutorial.

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.