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?

asked Jun 6, 2014 at 21:24
5
  • How are the relays connected to the pins? Is there a pull-up or pull-down resistor? Commented Jun 6, 2014 at 22:09
  • @Craig The relays are connected directly to Arduino's pins. There's no pull-up or pull-down resistors Commented Jun 7, 2014 at 20:36
  • But there are flyback diodes, right? Commented Jun 8, 2014 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? Commented Jun 8, 2014 at 17:20
  • @jippie When using the blink sketch, the relays do not turn on and off during the reset... Wonder what's happening Commented Jun 8, 2014 at 17:23

5 Answers 5

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.

answered Jun 6, 2014 at 21:47
5
  • Thank you, sounds like this is a possible reason. How should I check the bootloader source in that Arduino? Commented Jun 7, 2014 at 20:38
  • Well, first you have to find it. Try the Arduino code repository, and failing that ask for it in the forums. Commented Jun 8, 2014 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. Commented Jun 8, 2014 at 23:19
  • It is absolutely possible to flash it with another bootloader. That the blink sketch doesn't cause it raises suspicions though... Commented Jun 8, 2014 at 23:31
  • Could it be the relay board? I'm using the 5V version of this relay board: sainsmart.com/… Commented Jun 8, 2014 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).

sa_leinad
3,2182 gold badges23 silver badges51 bronze badges
answered Sep 6, 2014 at 5:52
1
  • 3
    too short for the... ? Commented Sep 6, 2014 at 11:18
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

answered Apr 26, 2017 at 19:56
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.

answered Aug 6, 2014 at 6:10
0

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.

answered Apr 26, 2017 at 21:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.