Feature #3
The state of the output pin becomes HIGH (5V) when configuring the pin as output.
100%
Description
The relay are changing state at boot, which is unwanted behavior. Try the following:
https://forum.arduino.cc/index.php?topic=568603.0
So you're saying that setting them low turns the relay off - it just doesn't happen immediately when your sketch runs? That's expected, because during the time right after a reset, the bootloader runs, and during that time, the pins are INPUT. If the relay board has them connected to the gate of a mosfet (not unreasonable) the pins are floating and will pick up noise from the environment, potentially going high. To prevent this, use a pulldown resistor (10k should be fine, but really anything within an order of magnitude of that is fine) between the relay pins and ground, this will hold the pin in a defined state when it's not being driven.
Updated by Michel Gauvin over 5 years ago
- Subject changed from Test the state of the relay at boot. to The state of the output pin becomes HIGH (5V) when configuring the pin as output.
Updated by Michel Gauvin over 5 years ago
- Status changed from New to Closed
- % Done changed from 0 to 100
Applied the following solution.
-----------
The solution that mitigated the above glitch in my case (ATTiny85 / Digispark Board) was, as Edgar Bonet pointed out above, going through the INPUT_PULLUP phase:
pinMode(ch2, INPUT_PULLUP);
pinMode(ch2, OUTPUT);
digitalWrite(ch2, HIGH);