Good Morning,
I've this scenario: During that ArduinoMega is "booting Up" the relay (switch when is low) is stay low then turned on and after when entry into loop go into the correct state ... that means that my load (for example a lamp) change state without to be managed during this time and this is not correct ...
I've checked the code and it's good and I've tried several pin...
First of all, you should not use pin 13. A system led is connected to pin 13, and it might blink during booting.
Also avoid pin 0 and 1, they are for RX and TX to upload a sketch.
To set the pre-defined state of the relays, we have to know what kind of relays and how it is connected.
It is a module with relays ? Can you give a link to that module ? Or a schematic ?
Good Morning,
the board 2560
the relays is power on with logic state 0.
so is connected with pin 14 (I've tried to change pin for example use 8 or 9 but the reult is the same).
and i didn't use 13 or 1 ...
for the relay there is only a transistor that manage a relays ... in attchment the photo thanks for support me ...
is happen the same if i put a led instead of relay ... during the setup I'm attaching and then detaching interrupt
I can't find the brand and type of that relay module.
That transistor is normally a NPN transistor and a high level at 'IN' activates the Relay.
So I don't understand why a '0' activates the relay.
Did you connect it correctly ?
VCC to Arduino 5V pin.
GND to Arduino GND pin.
IN to Arduino pin 14.
Can you see the type of the transistor ? I'm 99% certain that it must be a NPN transistor that is activated with a logical '1'.
What is going on in your sketch ?
Can you upload your sketch between code tags (use the '#'-button above the text field).
void setup() {
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // this depends on whether you have connected the load to the relay on the NC or NO position...
}
hi,
Iam also having the same problem, I have included the said in my sketch, but not working,
I think thr arduino bord, when powerd on, it makes all the pins HIGH for a moment and then only turns to the instructed state,
Iam using a uno r3 board,
regards,
adal.
During power-up the pins of the Arduino are all input pins.
So the voltage level is high impedance or floating.
That is not a problem with an opto-coupler or transistor. They need some current to be activated. Since there is no current, they are not activated during power up.
I don't know what is going on. Show us how it is wired, which relay module, the sketch, photos and so on. Perhaps we can detect a problem somewhere.
I know for a fact that upon boot all IO pins are set to "input" so anything connected to them might see a floating voltage hence the somewhat "unreliable" behavior.
I would, in this case, put a pull down resistor of, say, 10K between the pin and ground ensuring a "LOW" during the startup phase.
Caltoa:
That transistor is normally a NPN transistor and a high level at 'IN' activates the Relay.
So I don't understand why a '0' activates the relay.
Actually, on a lot of these el-cheapo chinese units, the circuit consists of a high-side PNP driver, rather than the low-side NPN driver (which you would expect).
Thus - the logic is reversed, and a logic-level LOW turns on the relay, while a logic-level HIGH turns it off.
You can fix this in your code, but this doesn't fix what happens at startup.
You could probably put a TTL hex inverter/buffer after the pin to invert the output (and leave your code alone), and this would fix the problem; its a bit of a hack - but so is the cheap relay unit.
/I honestly don't know why they continue to use this circuit; one would think an NPN system would be better, make logic sense, and possible be cheaper...unless there's a glut of PNP transistors in China?
Test the relay module independent of the Arduino. Then use a pullup or pulldown resistor as needed. Don't use pin 13 when you hookup to the Arduino, the bootloader usually pulses that pin.