2

The Arduino Mega 2560 Rev 3 has multiple relays connected to its digital output pins.

Whenever the Arduino is reset (using reset button, turning on Serial Monitor etc), the Arduino turns on all relays then turns them off. I cant find any function in my sketch that causes the outputs to go HIGH then LOW. Assuming this is a normal feature of the Arduino, how can we prevent this and ensure that the outputs do not flip to the HIGH state?

  • How are the relays connected to the pins? Is there a pull-up or pull-down resistor? – Craig Jun 6 '14 at 22:09
  • @Craig The relays are connected directly to Arduino's pins. There's no pull-up or pull-down resistors – Nyxynyx Jun 7 '14 at 20:36
  • But there are flyback diodes, right? – jippie Jun 8 '14 at 15:01
  • Maybe I have different hardware/bootloader, but I cannot reproduce this. Can you reproduce this with the standard blink sketch and nothing attached other than a single LED/relay? – jippie Jun 8 '14 at 17:20
  • @jippie When using the blink sketch, the relays do not turn on and off during the reset... Wonder what's happening – Nyxynyx Jun 8 '14 at 17:23
2

The ATmega2560 itself comes out of reset with all pins in high-Z (DDRx=0, PORTx=0). Your observations are likely due to the bootloader. Check the bootloader source to verify that it is responsible for this.

  • Thank you, sounds like this is a possible reason. How should I check the bootloader source in that Arduino? – Nyxynyx Jun 7 '14 at 20:38
  • Well, first you have to find it. Try the Arduino code repository, and failing that ask for it in the forums. – Ignacio Vazquez-Abrams Jun 8 '14 at 22:53
  • Is it possible to flash with another bootloader that is known to not have this issue? Additionally, the blink sketch does not cause the relays to turn on then off when Arduino is reset. – Nyxynyx Jun 8 '14 at 23:19
  • It is absolutely possible to flash it with another bootloader. That the blink sketch doesn't cause it raises suspicions though... – Ignacio Vazquez-Abrams Jun 8 '14 at 23:31
  • Could it be the relay board? I'm using the 5V version of this relay board: sainsmart.com/… – Nyxynyx Jun 8 '14 at 23:33
2

The relay board you are using has active low inputs to control the relays. In your sketch when you are initialising the pins as outputs they are by default set low (this is turning all your relays on). set the pins as outputs and set them high, they will be low for a very short time (too short for the relay to turn on effectively).

1

Just to add my five cents. I also experienced a relay, driven by a bipolar npn lowside. turning on while timers, Serial etc init and then turn off again. Using INTERNAL_PULLUP mode helped me as well.

have no idea why. It must have something to do with relays beeing current driven. Mine requires 20 mA at 5V

1

Assuming this is a normal feature of the Arduino,

It doesn't sound normal to me. Check with others to see if they have the same issue before you try to resolve an otherwise non existent problem.

how can we prevent this and ensure that the outputs do not flip to the HIGH state?

Design the relays to be active now.

0

There is an alternative to change the bootloader. Introduce a RC circuit in the relay driver that delay the rely to switch ON.

Note: Please add info about the relay and/or driver circuit for a better answer.

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.