Hooking up the spark to arduino relay shield

How do I connect the spark to an existing arduino relay shield like this one…

Thanks

Hi @puddlerocks

This is very similar to the relay in this thread:

The inputs to this relay are active-low, so you need to write the output pin low to turn on the relay. Sometimes these are glitching on at core power up so a lot of folks are using some kind of inverter to drive them, turning them into active-high devices.

You wire it up by connecting two pins on the core to IN1 and IN1, GND to GND and +3.3V to VCC. You will likely need to connect JD-VCC (the relay power supply) +5V, which is available on the core VIN pin if you are using USB power. The other thread discusses adding an inverter to avoid the start-up glitch, if you need to do that.

Be careful with the high-voltage side of the relays!

1 Like

Hi @bko ,
Thanks for the quick answer. I think I am planning to power the Spark core using a Android mobile phone power supply that can provide 5 VDC ,1A. So is it safe to connect the VIN pin to JD-VCC?
One more thing, this may be a newbie question but how do I hook up a 12 V 1 A DC pump to this relay? I have a wall plug in adapter that can provide 12 VDC ,1A .

Thanks,

Hi @puddlerocks

Yes, I would think that you could use the Android power supply just fine here. Assuming the power supply has a micro USB connector going into the Spark core, you can use the VIN pin connected to JD-VCC, which will be USB +5V.

For the 12V side, you will want to keep that completely separate from the Spark core side. The relay board screw terminals have three terminals per relay, a normally open terminal, a center switch terminal and a normally closed terminal. You want to wire one side of the +12V power supply (let’s do the positive side) to the center switch terminal. Then the normally open or NO terminal to the positive lead of the pump. And then finally the negative side the 12V supply to the negative side of the pump to complete the circuit.

The startup current (called LRA or locked-rotor amps) of a motor or pump can be many times the running current of the motor, so you might need a 12V supply with more current, like a 5 or 6 amp supply. If the pump doesn’t spin, don’t leave it connected to power for long or it could burn out.

You can test this whole setup with software by taking the wire from IN1 or IN2 of the relay board and temporarily connecting it to GND rather than the Spark pin (don’t short the Spark pin to GND, however) . The pump should turn on when the relay input is grounded and turn off when it’s not.

I think you are going to want an inverter between the core and the relay board since the pump may turn on as the core is powering up. That is what that other thread is about.

Post some pictures if you are not sure and we can help you.

1 Like

That makes sense. I will try it soon and will post pics if I am stuck or successful. :smiley: Thanks once again @bko

2 Likes

Hi @bko
Everything works great. I just tested the module by pulling the ground low and high and the relay works nicely. Now, on the matter of using an inverter on the spark module, I am planning to power the spark core continuously through a 5V, 1A micro USB DC power supply. Since I will be continuously powering the spark core, do I really need an inverter?
I am first planning to trigger the 12 V pump on a timer everyday. I would like to run it for 5 mins every day. How do I do that? Once this works, I will try to control it over the cloud.

Thanks

Hi @puddlerocks

I am glad it is working for you! The only problem you will have without an inverter on the output is that the pump will turn on briefly when the core is powered up–after that things are fine.

For your time feature, you can use millis() which counts in milliseconds and rolls over approximately every 49 days. There are 86,400,000 milliseconds in 24 hours and 300,000 milliseconds in 5 minutes. Then you would have to restart spark the first time at the time you wanted it to pump every day, so it could just count from there. With a small amount of web control, you could make this easier.

Or you could use the built-in real-time clock but that feature is not quite complete. Very soon in the web IDE and available now if you do a local build.

Or you could use my network-based real-time clock shown in this posting:

<// blink an LED for a set amount of time
const int switchPin =  D7;         // the number of the LED pin

void setup()
{
  pinMode(ledPin, OUTPUT);
}

void loop() {
   digitalWrite(switchPin, HIGH);   // set the switch high
   for (long x=0; x < 86400000; x++) {     // Wait for 1 second
      delay(1);
   }
   digitalWrite(switchPin, LOW);   // set the LED on
   for (long x=0; x < 300000; x++) {     // Wait for 1 second
      delay(1);
   }
}/>


@bko Do you think this will work.I am just pulling D7 switch to which my relay is connected low for 5 mins in every 24 hours.

HI @puddlerocks

This will work, but it will only be approximately correct timing. It might be good enough for your application (with one small change).

For one thing, you have 5 extra minutes per day, so your should subtract the 300,000 ms from the 86,400,000ms, so that first loop should be 86,100,000 to get 24-hours.

But accumulating 1ms delays is just less accurate that using the counter value since the counter is a hardware timer based on the processor’s oscillator and the Spark cloud loop runs everytime you exit and re-entry the user loop() function and that takes some time too.

You could use one big delay instead of zillion small ones and that would be closer, but using millis or the real-time would be more accurate.

That’s interesting @bko . I am just going to use this for sometime and see how accurate this is going to be.
Lets say I do the 5 min correction you mentioned above, how accurate do you think this is going to be? I am planning to test this when I am on vacation for 20 days. Of course I will do more short term testing before I go on vacation. :wink:

Eventually I am planning to go the app / cloud route which is what I really want.

Hi @puddlerocks

I would think you would be within a minute or twenty over twenty days, so no problem for a vacation timer.

The crystal oscillator is only accurate to about +/- 5 seconds over 20 days, so without internet time from the Spark cloud or NTP, that would be the kind of error you might see. Adding some variability for the Spark loop should keep it under a minute or two.

Have fun!