Issues with Serial Communication (Disconnects halfway through)

I’m having an issue with my Arduino Nano and stepper motor setup for a 2D plotter/crane. Here’s a quick overview of the setup:

  • Arduino Nano
  • 3x A4988 stepper motor drivers for controlling the stepper motors
  • Arduino-compatible relay (5V)
  • 2 limit switches

The issue I’m facing is that the serial communication completely stops after the code reaches the halfway point of the crane’s movement. Specifically, Serial.println() stops printing anything, even though the crane continues to move and still accepts commands (I send coordinates through serial to control the crane).

  • When I disconnect the relay from the 5V power rails and reset the Arduino, everything starts working perfectly. The serial prints every line as expected.
  • I thought the problem could be due to power, so I'm using an external 5V power supply for the relay and connected the GND of the Arduino to the external GND for a common reference. I still encountered the same issue where the serial communication doesn’t print anything.
  • I think I've confirmed that the Arduino is resetting halfway through and is starting over. that's why it's still works, because it can still execute till halfway point. and everything after that point is not getting executed.
    As soon as I disconnect the relay pin. everything works fine and no issues. I suspect that running the 3 motors + relay + serial may be too much for the Arduino but I'm not sure.

Please Help

The problem is likely in

  • the code you didn't post, or
  • the schematic you didn't provide, or
  • something else.
1 Like

A nano, or Uno, is not a power supply. That 5V output is capable of at most, under the most benign circumstances, providing 150 ma of current. Three motors? No. One Motor - until it dies, yep.
Your relay, powered by the digital output, is similar. Additionally, it's likely to give a back-emf lightning stroke when shut off, which will eventually fry the digital output, and likely the Arduino.
In summary, you need a transistor/mosfet driver for the relay, and a separate power supply for the relay and motors.
edit - oops, missed the +12 supply notation. Motors are okay.

Relay still a problem.

It's a little more likely that your USB will power the relay successfully, but a bare relay is still a hazard.
However, is that relay a bare relay, or actually a relay module with printed circuit board and digital IC on it? A photo, or link to something purchased, would be helpful.

Just an update on the schematic. i'm running everything through an external 5V power supply (Cause i thought the arduino was undersupplying it, turns out that's not the case cause i'm still getting the same issue).
It's a relay module that has surface mount mosfet and diode. so it should be good

1 Like

Haven't dug into your code (yet), but I note things like short ints - are you fighting an int overflow issue?

I don't think so. i have nothing that keeps count especially large numbers.
Also What's interesting is that in my code i have two functions that turn relay on and off. if i comment out the turnOff function. everything works and the serial works for a long time.
Adding the digitalWrite(My_Relay, LOW) is causing issues for some reason (Maybe too much for the arduino?)

That points to a transient issue - the relay shutoff causes a large voltage transient.

I think you are correct. I swapped the relay with an LED and works beautifully. What's the solution tho? Capacitor across the pin? new relay?

I'd have to see the exact wiring - if there's already a coil suppression diode on board, putting another right across the pins of the relay coil would be something I'd try, but might not really expect an improvement. But I've got to go away right now, 8 hours before I'm back, so maybe someone else can follow up.

All good. I got it working. Because my load was inductive, the voltage spike was crazy (I checked it with the oscilloscope). I put a flyback diode across the load, and it lowered the spike. Now my program works nicely. Thanks for your help, my friend. I appreciate it.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.