Controlling a SPDT relay, OFF = HIGH, so that it remains OFF at start up

Yes, I initially tried to hold the relay signal high until my Spark App could do so. And I could not because I did not realise the relay signal needs not only voltage but also some current i.e. 3mA. My resistor was 10K. I need 1K or less but never tried anything that low.

So I followed @mstclair87’s suggestion - the 2N2222 worked a treat. It also allowed me to invert the code to something which seemed more intuitive (to me!) HIGH = ON and LOW = OFF.

But I will try the other way, with a 1K or 470R resister instead of the transistor, just to see if it works, when I get back home Tuesday. [I couldn’t get them to work either.]

I agree the coil resistance is quite low and your estimate of 100R is right - 33mA is being drawn from the 3v3 pin. On Tuesday I will move that to the Vin pin. Interestingly the mini-spec of the relay on eBay said it only drew 15-20mA.

In my hacking around, I’ve discovered that having the relays turned on by default is very useful for debugging. When I see the lights turn on and then off, I know my Core has finished flashing and rebooting. Gosh that’s handy when it’s inside a black box!

1 Like

I use Spark.publish( progname, __TIME__)as that gives the compile time - so then I know I really am running the latest version. Also, you could flash the LED on the Spark in the setup().

1 Like

I just got the 8 channel version of this board today. It’s very annoying to have the input reversed. I’ve tried 10k, 1k, and 470 pull up resistors, but they don’t help.

I did get the NPN inverter working but with 8 channels, that’s a lot of transistors. Is there another way to invert all 8 channels?

There are 8-channel inverter ICs. A 6-channel one is the 7404.

1 Like

A 74HC540 would be the classic inverting octal buffer that would work well with 3.3V input and a 5V supply.

2 Likes

LOL @bko I just found that part number after 30 minutes of looking and was just coming here to ask if it would work. Thank you!

Ordering some now from digikey. What other fun stuff should I add to my order while I’m at it so I’m not just ordering a few small ICs? :smile:

http://www.digikey.com/product-detail/en/SN74HC540N/296-8334-5-ND/376740

Well that’s an open-ended question! I am assuming you are looking for DIP packages for bread-boarding and not surface mount.

These 7 transistor darlington arrays are handy (but one short for your 8 relay board):

http://www.digikey.com/product-search/en?mpart=SN75468N&vendor=296

And you can never have enough 74HC595 for shift-register IO extenders:

http://www.digikey.com/product-detail/en/SN74HC595N/296-1600-5-ND/277246

There are about 100 million other parts you could order!

2 Likes

There is also another similar thread where I suggested a way to try to force the outputs high at power-up (well, tristate-on, really). The problem is there is always time between pinMode(D0,OUTPUT); and digitalWrite(D0,HIGH); so there is always a brief time when the output is low. The untested idea is to directly write the output pin to high before calling pinMode().

[Sorry for the triple post–website weirdness]

I know this is an old thread but… @KyleG

I’m in the same situation like @psb777 with the same relay. I see the solution is to use a 2N2222 transistor suggested by @mstclair87.

My question would be. Is there a difference between digitalWrite (D0, HIGH) and digitalWrite (D0, LOW) in terms of battery consumption, if we consider HIGH = OFF and LOW = ON for this relay?

Because in my case most of the time would be digitalWrite (D0, HIGH) = OFF (relay)

Thank you

@tylercpeacock can you take a look at this?