5V Relay to Spark Core

Dear All,

I am thinking of buying the Spark Core and use it as a wireless on/off switch for my room’s lights. I found these relays on ebay
http://www.ebay.com/itm/5pcs-5V-1-Channel-Relay-Module-Shield-for-Arduino-AVR-ARM-PIC-DSP-SRD-05VDC-SL-C/121140625276?_trksid=p2050601.c100085.m2372&_trkparms=aid%3D111001%26algo%3DREC.SEED%26ao%3D1%26asc%3D20140211132617%26meid%3D8165531821435841162%26pid%3D100085%26prg%3D20140211132617%26rk%3D1%26rkt%3D4%26sd%3D121140625276%26clkid%3D8165533367084631485&_qi=RTM1562569

I am a software engineer and new to all the hardware stuff. How can I wire this relay to the core?

Thank you

1 Like

Spark Core is powerfully able to do this. You can do this by following instructions -
You can use 2 channel/4 channel (depend on no. of appliances u want to control) relay board.

If you are powering spark core by USB cable then
VIN Spark => VCC Relay (because relay needs 5v power and if u want to use Spark 3.3V pin then need to external power for relay So VIN pin is fine)
GND Spark => GND Relay
D0 pin => IN1 relay
D1 pin => IN2 relay…so on

Now in Spark Build write some code to check or you can make App to control electric appliances using ur device id and access token.

Another part of relay, you can use AC/DC source. Connect one wire with NO and another with COM pin.
Now you can control electric appliances.
( Be aware in the case of AC power supply & be alert about polarity)

@mrabie:
Typically, two pins on the switching side of the relay (the one with the pins) would suffice, one for the input and the other for GND.
This relay has 3 pins. One might be power, which is 5V. It can be fed through Vin. The input can be D7, for example. You can use Tinker to control this.
This relay also has 3 sockets, like any other relay. The datasheet of the relay states which of the two is N/C (Normally Closed) and the other is N/O (Normally Open). The common should go to the AC source and either N/C or N/O should go to one light.

Alternatively, you can use the relay shield from :spark: since it’s a lot easier to use.

Thank you so much for the information. I’ll play with the devices and update you with the product :smile:

Sorry for the confusion, but I understand that the VIN on Spark drives a 3.3v but the VCC of the relay needs 5v. In this case I will need an external power to power up the relay, or VIN will be sufficient? I’ll be powering the Spark core using a USB cable.

So USB cable provides 5v to the core, but in the documentation it says that the VIN pin regulates the voltage and drops it down to 3.3v. Am I understanding this correctly?

Thank in advance for the clarification.

The VIN pin is connected to the USB power before they go into the 3.3V regulator, so when you’re powering it from USB, the VIN pin provides 5V straight from the USB power source.

The regulator is the first section in the schematic. UVCC is the USB 5V connector and RAW is the VIN pin.

1 Like

Thank you for posting this!! I have 2 projects that I’ve been blocked on because the parts I had required 5V and I’d not had a chance to order 3.3V equivalents.

3 Likes

Thank you for the clarification :smiley:

quick update…I received my Spark Core today, attached the Relay GND -> Spark Core GND, Relay VCC -> Spark Core VIN, Relay IN1, IN2 -> Spark Core D0, D1 respectively and it worked like a charm.

Thank you all for your great help

2 Likes

This will not work with ALL the relays out there. I have two different ones made by different people, one works on the 3.3v and the other doesn’t. They still see the 3.3 V as a low signal.

just recently got some relays from ebay. See link

If I connect as indicated above in this chat. attached the Relay GND -> Spark Core GND, Relay VCC -> Spark Core VIN, Relay IN1 -> Spark Core D7

The relay closes(relay led on) when D7 = Low and opens when D7 = High. If I disconnect IN1 from D7 then relay opens. Using normally open connector.

Why would this be? How do I get it to switch correctly?
Thanks

@fletch, the modules use inverse logic so that with D7 = HIGH, the relay is open and D7 = LOW, the relay closes. By default, all outputs are set to LOW on reset, including D7. The simplest way to fix this is to “invert” your program logic and set D7 to HIGH at the start (in setup). Then to activate the relay, set it LOW. Otherwise, you will need a logic inverter between the pin and the relay to do what you can do in your code. :smile:

I tried changing my code to inverse logic which worked, but there was a gotcha. I am controlling the gate
to my house. To open or close the gate I mimic the press button on the handset, I short the wires to the
switch. The problem is if the power goes off and comes on, the relay comes on as “closed” which effectively opens the gate and then when the Spark starts up it opens the relay, but the gate is now open.

Why would they make a relay like this?

Do you think a pull-up resistor could help here?

As long the Core is not up to speed, the pins should be high impedance and an external pull-up would provide the opening HIGH for the relay, till the Core overrules the pull-up.

@fletch, @ScruffR has a great idea but there was some discussion on this in an older topic:

You may want to swtich to an analog pin (A0-A7) instead of a digital pin (D0-D7) for your control line as it seems the power-up glitch is not seen on those pins. Just in case this is confusing, the analog pins CAN be used as digital pins with the same pinMode() command. Combine that with @ScruffR’s suggestion and and see what happens.:slight_smile:

Tolako 5v Relay Module for Arduino (Works with Official Arduino Boards) from Amazon did not work with Photon. The input voltage from Photon is only 2.5V with digit write and 2.2V with analog write at value 255. The relay is working if I short the VIN to input. So I know this delay will work if the input is close to 5v, but 2.5v is not close enough.

Would somebody please post some models that they tested out? Thanks.

I used the SainSmart 2 and 8 channel relays

If you have a PNP transistor, you can use it as a high-side switch to send a 5V signal to the module.

I believe the problem is you are trying to use the "analog" pin as a PWM output instead of as a digital output. As stated earlier in this thread:

So simply set the Ax pin as pinMode(Ax, OUTPUT), where Ax is the "A" pin you want to use and then use digitalWrite(Ax, HIGH/LOW) to control the output. You measured odd voltage because you were using the pin in PWM mode by doing analogWrite(Ax, value). Measuring a PWM pulse with a multimeter will give you an odd reading due to the varying duty cycle. :wink:

@peekay123, I encountered same issue and didn’t resolve with usage of analog pin too, however I didn’t tried for external pull-up registers. Instead I tried something unconventional, based on my observation, by just setting pin modes (INPUT and OUTPUT) and it worked. But I am not sure if this is correct way. Please suggest. Thanks.