220v Relay

Hi guys. I’m a software dev - this is my first foray in to hardware, so any/all advice is appreciated!

For this project, I would like to create a remote controlled light switch. From the reading I’ve been doing, it seems the way to go about it would be to use a relay. I was looking at this 8A relay, but it needs 5v and it seems the electricimp only provides 3v. Am I correct in thinking that a Logic Level Converter will solve that problem?

From my limited understanding, I would hook up the Converter to the EI, and the relay to the converter. Is there anything else I would need? Am I even on the right path?

Is there recommended reading that where I can learn more about this stuff?

Thanks a ton!

Hi see http://devwiki.electricimp.com/doku.php?id=exampleswitch

The outline circuit digram shows [controller impee] which uses a transistor to switch the relay on & off. One part of the transistor [the base] goes to the imp output via a resistor, another part of it [collector] is connected to the 5v and the [emitter] goes to the coil of the relay.

Note this description is slightly different from the way impee controller digram works. I have this working with one of my imps.

What is the load your trying to switch with relay?

I saw that, but its mostly about the code and not the hardware. Being a software developer, I need a link the other way around :slight_smile:

For starters, I’m looking to switch 220v @ 1kW, so 4.5A (if I got that part correct).

It’s about code but the circuit digram shows how to drive the relay it has part no’s for most of the electronics, you just need a relay with a 5v coil.

Also for learning try the brilliant Adafruit http://learn.adafruit.com/

you just need a relay with a 5v coil

I thought the imp only dose 3.3v?

The imp’s 3.3V is enough to turn on the transistor, which then lets 5V into the relay and switches it. Though, and please don’t take this the wrong way, if you’re going to be using 220V then you should definitely get your circuit checked (if not designed and built in the first place) by someone who already knows about electrical engineering…


@peter no offense taken :slight_smile: I would love to have it checked by someone that know more than I do… I just don’t know anyone :frowning:

Something like this might be safer: https://www.sparkfun.com/products/11042

…though it’s still not housed. The relay is 5v but looking at the circuit, 3.3v will work fine for the control signal.

@Hugo I’m not afraid of a little soldering - and the other relays seem MUCH smaller. Is there really that much of an advantage?

Ah, the one you’re looking at isn’t a relay - it’s an SSR (solid state relay). This uses opto-isolated back-to-back FETs to switch electronically. It actually only needs about 1.4v to turn on, as all you’re doing it powering an LED inside the package… but you need a transistor still as it wants a minimum of 8mA.

Either use the sparkfun SSR control board (see related products) or solder up a similar circuit with an NPN transistor to boost the current from the imp. The sparkfun board has a schematic available.

Note the top comment on the sparkfun page though… that SSR doesn’t have much headroom to switch 230vac. You really want the higher rated one unless you’re doing 110vac.

@Hugo - thanks a lot. If nothing else, I’ve proven my noob status…
I’ll look in to that. In addition to @controlCloud’s link, I could really do with a good book to get me up to speed… any suggestions?

Everyone has to start somewhere! Starting with high voltage is brave :slight_smile:

I’m a bit old-school and would say “the art of electronics” is excellent, though a very long read and getting rather out of date these days. Anyone else have something more modern they can recommend?

Have you looked at one of these: http://www.radioshack.com/product/index.jsp?productId=3814337? The books are very well written and it would give you some basic parts and whatnot to experiment with…

Good book for free

I have a question about this relay that you posted from sparkfun…

...though it's still not housed. The relay is 5v but looking at the circuit, 3.3v will work fine for the control signal.
How would I send on/off signal to 3.3v pin. Or how would I set 3.3 volt on any other pin (1-9). I have sparkfun April board and this exact relay that you posted. I'm a newbie to hardware design... so any help is appreciated!


So, you need to power the relay board with 5v.

Connect the ground (driver side, not AC side!) of the relay board to the imp ground.
Connect a pin (say, pin 1) on the imp to the relay on/off signal
Use this to configure the pin: hardware.pin1.configure(DIGITAL_OUT);
Use this to turn the relay on: hardware.pin1.write(1);
Use this to turn the relay off: hardware.pin1.write(0);

If you’re using USB to power the april board, then you will have this 5v available on the VIN contact on the edge of the board. You could power the relay board from this.


Thanks for your fast reply!

Thats almost identical to what I did a few days ago. It seemed like there was not enough voltage in pin 1-9 to signal the relay to switch (in my original setup). The only difference is that I used hardware.pin1.configure(DIGITAL_OUT_OD_PULLUP).
Will hardware.pin1.configure(DIGITAL_OUT) give me 3.3v on pin1?

Yesterday I was trying the following, connecting april to control side of the relay board:
vin to 5v
ground to ground
pin 1 to relay on/off control
configuring pin1 as following: hardware.pin1.configure(DIGITAL_OUT_OD_PULLUP)

When I was sending “on” signal (hardware.pin1.write(1);), the light on the relay board was barely lighten, and the relay was not switching.
When I was briefly connecting 3.3v pin (from april board) to the relay on/off signal, I was getting a bright light on the relay and it was switching OK.

I’m in the office now and don’t have the imp with me, when I get home I will try hardware.pin1.configure(DIGITAL_OUT) and see if the relay will switch.

So I guess my question here, whats the main difference between hardware.pin1.configure(DIGITAL_OUT) and hardware.pin1.configure(DIGITAL_OUT_OD_PULLUP)
will hardware.pin1.configure(DIGITAL_OUT) give me 3.3v on pin 1?

I can post some pics of my setup if that will help understanding what I’m trying to do.


Thanks for the help, everything works with hardware.pin1.configure(DIGITAL_OUT)!

Yes, OD_PULLUP means you have a strong pull down and a weak pull up. This will work for a FET gate generally, but won’t work for a real transistor which requires some current to turn it on.