Maker Pro
Maker Pro

Arduino - Keeping Outputs Low

Xenobius

May 15, 2012
125
Joined
May 15, 2012
Messages
125
Hi all,

I have a project and am using an Arduino (Atmega328P). Everything is flawless except for 1 thing. I have a relay connected to pin 13 and when I switch on the Arduino, for just a few milli seconds this relay is turned on.

I programmed THE VERY FIRST LINE to take pin 13 to LOW but apparently this is not enough. Do you have other options? I was thinking of actually making a 555 timer simply to delay by 1 second but this is obviously not the correct solution. I think a 350 - 500mS delay is more then enough for the Arduino to power on and execute the first line of code.

Attached is the circuit I am talking about.

Also as you can see I have a connector for a key switch and at the moment I am using it to switch on the relay manually after just 1 second but again this is not the correct solution.
D13 in the Diagram is connected directly to the micro controller.

Thanks all :)
X
 

Attachments

  • relay.jpg
    relay.jpg
    13.8 KB · Views: 281
Last edited:

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,772
Joined
Nov 17, 2011
Messages
13,772
The behaviour is possibly due to the pin being an input during and after reset (this is often the case with microcontroller's general purpose I/O so they will not issue an output signal during reset).
Even if you programmed teh first line to set the output LOW, it will still be an input during reset. And as far as I understand the arduino there is kind of a boot routine that will run before the µC comes to the first line of your code.
Now if the Pin D13 is an input during reset and a Pull-Up is configured for this pin by the arduino SW, then your relay will see an on-pulse.
As you may now want to change the arduino's HW or SW, one possible solution is to invert the drive signal. Make it low-active by using a PNP transistor. Put the PNP transistor into the VCC-connection of the relay. Remove the NPN, connect the coil to GND instead. Change the logic in your program such that
Relay-on=D13_Low
Relay_off=D13_High

An alternative would be to use an integrated reset controller IC with open drain output (Maxim, Texas Instruments and otthers). connect the output of the reset controller directly to the base of the relay driver transistor. Make the reset duration of the controller longer than the time it takes the arduino to pull D13 LOW. This is not an elegant solution but relieves you from the manual switch.

Harald
 

Xenobius

May 15, 2012
125
Joined
May 15, 2012
Messages
125
Hey thanks Harold. I think I will go for the PNP solution :)
I was thinking a little more and I figured... what if I could use a large capacitor somewherE? But this won't be elegant either right?


Thanks once again
X
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,772
Joined
Nov 17, 2011
Messages
13,772
You could put a capacitor between the base of the transistor and GND. But this would
1) not be elegant
2) sensitive to tolerances and aging of the capacitor
3) slow down the response of the relay once you set D13=High

Harald
 

Xenobius

May 15, 2012
125
Joined
May 15, 2012
Messages
125
Hi harold,

I think the only issue here is number 2 and maybe number 1 because I only switch on the relay once before I start using the hardware but again ... I wouldn't want it to be unsafe so I will change the transistor to pnp

Thanks
X
 

donkey

Feb 26, 2011
1,301
Joined
Feb 26, 2011
Messages
1,301
hey just a question could the fact that most arduino boards having a LED attached to pin 13 be part of the problem?
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,772
Joined
Nov 17, 2011
Messages
13,772
If the LED goes to Vcc: definitely yes.

We don't know which arduino Xenobius is using, but a quick look at some arduino schematics doesn't show the LEd you mention.
I've found this: http://arduino.cc/en/uploads/Main/Arduino-Fio-schematic.pdf where an LED is connected to D13, but this LED goes to GND and should not contribute to the problem.

Harald
 

Xenobius

May 15, 2012
125
Joined
May 15, 2012
Messages
125
hmm good point... i think ill just swap it with pin 12 or something. Its not like im bound to use pin 13 but I tought I could make use of that led

ill try it tonight
 

donkey

Feb 26, 2011
1,301
Joined
Feb 26, 2011
Messages
1,301
http://arduino.cc/en/Main/ArduinoBoardMega/
i know that one has LED13 which is a led on pin 13. I also found there is no way to deactivate said LED without desoldering it. there are others however that use the LED13.
the only reason I brought up the LED was the fact he was using pin 13 so a change of pin might help
 

Xenobius

May 15, 2012
125
Joined
May 15, 2012
Messages
125
Thanks for the reply. I had no time since and probably wont have tonight either but I will swap to pin 12 before I resume work and will let you know :)

Thanks again
 

Xenobius

May 15, 2012
125
Joined
May 15, 2012
Messages
125
Well what do you know :D ?
Swapped pin 13 with pin 12 and the relay is not switching on! :D

Thanks for the tip! I guess i'll keep the NPN configuration then.

X
 

donkey

Feb 26, 2011
1,301
Joined
Feb 26, 2011
Messages
1,301
no probs. I just got into arduino and first thing i learnt is to activate pin 13 to do a self check of sorts.
 
Top