Arduino 5V relay project "flashes" on power-up of device

I am using an Arduino to control a 5V relay (spec SLA-05VDC-SL-C), but using a transistor to convert the signal into something the relay can recognise (see attached diagram from previous post).


I have set the high/low jumper to "L" and have initiated the startup with a "low" signal, but whenever I power on the arduino, the output of the relay "flashes" briefly (turns on then turns off).

The port setup code is here (the whole program is 300+ lines, so I will post subsets)
...
const relay= D0;
....
void setup()
{
....
digitalwrite(relay, LOW);
pinmode(relay, OUTPUT);
...

void loop()
{
....
digitalwrite(relay, HIGH);
...

Now when I use the opposite values (digitalwrite HIGH for initial value and LOW in the loop), it does the opposite, but does not "flash" the power on the relay.

So, I am assuming the power is automatically "on" for D0 on power-up and cannot be overridden beforehand in setup() and there are no BIOS / dip switch settings on the arduino to change this.

From what I understand of Relay voltage values, I cannot just reverse the logic on the 5V relay via dip switches and the port signals, as the difference is not enough to pull it down.

So, what other options are available to me? Regards, Ian

Please read and use the advice here: How to get the best out of this forum - Projects / General Guidance - Arduino Forum

Please add complete schematics, showing all powering, and the datasheet link to the relay.

There are some 20 different "Arduino", some of 3.3 volt, some of 5.0 volt....
Please tell exactly which one.

Generally, when people say "I'm using an Arduino", the assumption is that they're using an Uno R3. But on an Uno R3, there is no definition for D0. So even if complete, and syntatically correct, that sketch you showed would not compile.

But, assuming for a moment that you're referring to I/O 0, otherwise known as the Rx pin, that's connected through a 1K resistor to the Tx pin of either a CH340 or 16u2. The Tx pin, is should be noted, idles in a HIGH state.

All of which means, that until your sketch actually runs after the bootloader finishes, the input to the NPN transistor will be HIGH, it will turn on, grounding the IN signal to the relay, and turning it on. Once your sketch runs, it turns the output LOW, turning off the transistor, and turning off the relay.

Of course, all that could be utter nonsense, since you didn't tell us which kind of Arduino you were using.

1 Like

You should post your setup. D0 is arduino RX pin. On Esp8266 it's Gpio16 that is high on boot independently from your code.

Ah good point. Arduino is ESP8266, D0 is used for control of relay.

Should be:
digitalwrite(relay, HIGH);
pinmode(relay, OUTPUT);

Here is the PDF of the plan I am following, if that helps. Control is Low = off, High = on.
[Uploading: Device Access Box sketch 30A sensor_bb.pdf…] Hope pdf uplods.
`

try pdf upload again.
Device Access Box sketch 30A sensor_bb.pdf (975.9 KB)

So use some other pin, like D1 or D2.
D0 is briefly high on boot like I wrote..

Ah OK, that could work. thanks, will try it (may take a few weeks to recreate a new rig).

@kmin that has been tested and worked, thank you very much for your input. Left the jumpers as "Low" and initial value as "Low". Cheers, Ian

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.