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
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.
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.
`