Relays Cycling Without Serial Connection

Hello,
I have an Arduino Mega 2560, a PoE Ethernet 2 Shield and 3 x 8 channel relay boards.

I have spent a bit of time trying to debug my problem but I am at a loss and hence this post.

I am making extensive use of MQTT and fundamentally, this device subscribes to and takes actions on MQTT messages. The action in most cases is toggling relays.

The issue I am having is whilst I use external power supplies for all relays. When I loose USB (serial) in the case of the host system being offline or it is rebooting, some of the relays (not all) cycle, you can hear them latching.

The Arduino does not loose power, their is PoE from the Ethernet2 shield and I have used a barrel jack also.

I am at a loss.

My main loop just calls functions. I have placed these functions in an if statement and have sleep functions if the connection to the MQTT broker is offline.
if(Serial.available())

Any thoughts, happy to share my sketch.

You need to find out where the Arduino Mega takes its power from. From what you see it seems that it's USB and so loosing USB means a reset.

When you reset all pins are inputs by default and thus likely to float. If these are wired to outputs to control your relays, this can drive your relay nuts until the setup() is executed again.

An external pull down or up resistor on the pin helps prevents the floating status during the reboot.

1 Like

Opening the serial monitor on the PC resets the Arduino and you get a similar effect if you have a PC program of your own talking to it.

It may be that a reboot of the host machine has the same result as the UART gets powered up.

If you have POE, do you need USB for anything other than debugging?

This is exactly the question I am asking myself. With a Ethernet 2 shield that has PoE which still remains lit without the USB connection, how can I deem where the Arduino is getting power from.

What you described below is exactly what is happening

When you reset all pins are inputs by default and thus likely to float. If these are wired to outputs to control your relays, this can drive your relay nuts until the setup() is executed again.

Is there any way to solve this without using a pullup resistor? Could I solve this in code and more so, why if I use a barrel plug (12v, 5amp) or PoE does this cycling occur when I loose the USB interface?

Hey WildBill,
These relays will always cycle without USB. My thought are like yours, I shoulnt need USB except for code changes or debugging.

Any thoughts?

I'm not sure what you mean by this.

One other thing; you have 24 relays. What do you have powering their coils?

I mean to convey, without the USB (serial) connection the relays latch and unlatch continuously.
I am powering the relays with a dedicated PSU, the Arduino is not powering them.

It appear that the Arduino is loosing power without the USB connection. The Ethernet shield (with the PoE) module remains lit at all times (lots of lights).

Is there any way @wildbill to validate the shield is indeed powering the Arduino Mega?

If I look through my code and the comments made by yourself and @J-M-L I think the setup mode is constantly firing. Below is from my void setup(); and my guess is on serial loss this is running. My guess is, the board is loosing power. Even with a barrel jack plugged in, I am experiencing the same behaviour.

Any thoughts and thank-you?

Shane

//Roller Shutter - Initialise High and Low Every Pair To Have One NO/NC
    pinMode(RELAY_CH9, OUTPUT);
    pinMode(RELAY_CH10, OUTPUT);
    pinMode(RELAY_CH11, OUTPUT);
    pinMode(RELAY_CH12, OUTPUT);
    pinMode(RELAY_CH13, OUTPUT);
    pinMode(RELAY_CH14, OUTPUT);
    pinMode(RELAY_CH15, OUTPUT);
    pinMode(RELAY_CH16, OUTPUT);
    pinMode(RELAY_CH17, OUTPUT);
    pinMode(RELAY_CH18, OUTPUT);
    pinMode(RELAY_CH19, OUTPUT);
    pinMode(RELAY_CH20, OUTPUT);
    pinMode(RELAY_CH21, OUTPUT);
    pinMode(RELAY_CH22, OUTPUT);
    //This is the state the roller shutter relays need to be to OFF
    digitalWrite(RELAY_CH9, HIGH);
    digitalWrite(RELAY_CH10, LOW);
    digitalWrite(RELAY_CH11, HIGH);
    digitalWrite(RELAY_CH12, LOW);
    digitalWrite(RELAY_CH13, LOW);
    digitalWrite(RELAY_CH14, HIGH);
    digitalWrite(RELAY_CH15, HIGH);
    digitalWrite(RELAY_CH16, LOW);
    digitalWrite(RELAY_CH17, HIGH);
    digitalWrite(RELAY_CH18, LOW);
    digitalWrite(RELAY_CH19, HIGH);
    digitalWrite(RELAY_CH20, LOW);
    digitalWrite(RELAY_CH21, HIGH);
    digitalWrite(RELAY_CH22, LOW);

@wildbill idea was good. You might get power from POE or the jack but if you open the Serial monitor it will reset your MEGA.

There is no other way than a pull-up/down resistor unfortunately (that I know of) if you want to be protected from floating pins.

Oh are you saying because I leave the serial monitor open it will reset the MEGA, just the fact of having it open. I run it open at all times.

I am going to test this.

Also are you able to provide me a link @J-M-L on how to wire in a pull-down resistor?

Thanks heaps.

I can confirm closing the Arduino IDE & Serial monitor made zero difference. When I unplugged the USB the relays started to cycle and worth mentioning the ethernet link was broken and started to re-establish again.

It is as if, the device is power cycling.

Ideally I want to get to a point where I can run purely off PoE.

Is my next step wiring in pullup resistors?

One last bit of information. When the relays click (like every 1000ms) the link light on my cisco switch goes off and on (well orange trying to re-establish). The device is loosing power I am almost sure of it.

My Cisco Catalyst 3750 shows the port drawing a PoE load but I am almost certain as soon as I unplug USB (or a DC Barrell jack) I loose power.

Any thoughts?

The barrel jack isn't a good way to power the Arduino. Better to provide stable 5V to the 5V pin.

I would want to test that the Mega is resetting. You might flash the Led in a distinct pattern at startup, or send an MQTT message or set up some logging over ethernet. The latter would be my preference because I expect you'll need it later on too.

1 Like

@wildbill - You solved my problem but I dont fully get why.
I tried yesterday using a barrel jack which didn't help, nor did putting the relay functions in an if statement based on MQTT status.

I have the genuine Arduino PoE Ethernet 2 shield, why doesnt it provide power when the USB interface is disconnected.

I feed 5v in from the same PSU powering the relays and it just worked, it works perfect. USB vanishes and the show goes on, it still responds to MQTT messages via Ethernet.

I am grateful you have helped me but can you explain why this has worked yet the PoE shield doesnt keep the unit alive.

I am curious more than anything else

Shane

If the relays are ON when the output pin is LOW, do this first thing in setup():
void setup()
{

  digitalWrite(RELAY_CH9, HIGH);  // set all relay pins to OFF state
  digitalWrite(RELAY_CH10, HIGH);
  digitalWrite(RELAY_CH11, HIGH);
  digitalWrite(RELAY_CH12, HIGH);
  digitalWrite(RELAY_CH13, HIGH);
  digitalWrite(RELAY_CH14, HIGH);
  digitalWrite(RELAY_CH15, HIGH);
  digitalWrite(RELAY_CH16, HIGH);
  digitalWrite(RELAY_CH17, HIGH);
  digitalWrite(RELAY_CH18, HIGH;
  digitalWrite(RELAY_CH19, HIGH);
  digitalWrite(RELAY_CH20, HIGH);
  digitalWrite(RELAY_CH21, HIGH);
  digitalWrite(RELAY_CH22, HIGH);

  pinMode(RELAY_CH9, OUTPUT);  // enable outputs
  pinMode(RELAY_CH10, OUTPUT);
  pinMode(RELAY_CH11, OUTPUT);
  pinMode(RELAY_CH12, OUTPUT);
  pinMode(RELAY_CH13, OUTPUT);
  pinMode(RELAY_CH14, OUTPUT);
  pinMode(RELAY_CH15, OUTPUT);
  pinMode(RELAY_CH16, OUTPUT);
  pinMode(RELAY_CH17, OUTPUT);
  pinMode(RELAY_CH18, OUTPUT);
  pinMode(RELAY_CH19, OUTPUT);
  pinMode(RELAY_CH20, OUTPUT);
  pinMode(RELAY_CH21, OUTPUT);
  pinMode(RELAY_CH22, OUTPUT);

Then change relay states last thing in setup():

    digitalWrite(RELAY_CH10, LOW);
    digitalWrite(RELAY_CH12, LOW);
    digitalWrite(RELAY_CH13, LOW);
    digitalWrite(RELAY_CH16, LOW);
    digitalWrite(RELAY_CH18, LOW);
    digitalWrite(RELAY_CH20, LOW);
    digitalWrite(RELAY_CH22, LOW);
}

How are the relay boards powered?

The relays are powered now from the same psu as the Arduino and it works fine.

Prior it was a usb and PoE from the Ethernet Sheild.

I assumed the PoE would keep the unit powered but upon loosing USB the mega would power cycle.

Any ideas why the 5V rail is the only thing to keep it alive?

Do i need to do anything to make the PoE shield work

What voltage were you using on the jack?

There is a circuit selecting the power source between USB and Jack.

Not sure how the POE shield provides power to your arduino

The barrel jack had a 12V DC voltage. Looking at Arduino Ethernet Shield 2 with PoE | Arduino Documentation | Arduino Documentation I have a hunch the PoE is passed through to the pins on the shield and not actually the Arduino as I thought it would be.

How do you interpret the datasheet there?

I’ve never used one

The arduino doc is not clear… easiest way to know is to only connect the Ethernet cable and upload a program doing something like a web server
If you can connect then it means the arduino is powered :slight_smile:

(It’s unclear also if you can use that as a source of current for other parts of your system.)

The documentation is ambiguous and vague - it looked initially like someone copied the Ethernet shield doc and added POE to the title without fixing the rest of the text because it says that you have to power the shield from the Arduino although now it actually appears to me that you do.

I suspect now that POE really only powers the shield (that certainly seems to be what you observe) and that the only point of it is to let the Mega keep as much power for other things as possible. Also, some POE standards can't provide much current, so perhaps there was concern about the Arduino and a shield and a bunch of peripherals browning the power out.

I've never used a POE shield, but I would certainly have expected if I did that POE would deal with everything. Now I know better I think.