Many relay modules are active low: the relay turns on when the input pin is LOW. Change your code to match the module, and set the pin before you enable the output.
What the message means
Opto-isolated relay boards often pull the relay on when the input goes low. So digitalWrite(pin, HIGH) turns it off, and the reverse. Floating pins during boot can also click the relay.
Fix it in this order
- Test with a LED or a multimeter on the contacts, not the mains. Find which level turns the relay on.
- Invert your logic in code, for example with two constants RELAY_ON and RELAY_OFF.
- Write the off level to the pin before calling pinMode(pin, OUTPUT) so the relay does not click at start-up.
- Power the module from the supply it needs, usually 5 V, and check its separate JD-VCC jumper if present.
- Never touch mains wiring. Use a certified enclosure and have mains work done by someone qualified.
- Use a flyback diode across DC coils or motors you switch.
Why it happens
Many relay modules are active-low: the relay switches on when the input pin is pulled low and off when it is high. With the pin floating or set the wrong way at start-up, the relay behaves opposite to what you expect.
Write HIGH to the pin before you set it as an output so the relay does not click at boot, and invert your logic if needed. Check the markings and the trigger jumper on the module.
If you see this, do this
| You see | Do this |
|---|---|
| Relay is on at power-up | Active-low input and a floating pin. |
| It clicks but the load does not run | Check the contact wiring (COM and NO). |
Related
safety relay wiring guide, Arduino resets when the motor starts.
Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.