DIY Project : An “openPowerSwitch” 1/…

Abstract : Prototyping a DIY “powerSwitch”, i.e. an ethernet (then HTTP/TCP/IP) controlable device, that switches AC (220/230V) plugs — Part one : getting a prototyping board with relays, and evaluation.

Introduction, project context.

At work, I sometime use some special mains named “e-PowerSwitch“, basically some switched plugs that one can control from network (or serial RS-232 link for the commercial product we have at the office).

Such devices are quite expensive. When, on an occasion, my own was preempted by another project, I decided that nothing in such a device is hard to do nowadays. It was, then, a luck to design a prototype (and learn new things, like, why not eventually Kicad prototyping, and produce a one-block PCB for this project).

Driving electromecanical relays with GPIOs

My first toughts, initiating that project, were about all hardware details about electromecanical relays, in order to (maybe, eventually) produce my own design of a board. But, Keep cool : I quickly ordered an 8 relays “all-incluse” board for 7€, quick delivery included !

Let me quote some facts, I learned last years about electronics, and switching relays from an MCU.

Typical problems are driving current into the relay coil, which is often too much for an MCU… A typical solution is to hook a switching transitor to  draw the current into the coil ; but then it leads to another problem : when the relay switches off, the electromagnically stored energy flows back and can then damage the transitor. A “free-wheeling” diode that drive the current back to Vcc (it actually flows back into the coil, and the diode, and so on until energy is dissipated).


Simple design for MCU/relay interface. (Click image for source and more info)

There are better implementations using MOSFET, for instance…

Relay board overview

The 7€ board I got for the prototype even uses optocouplers for GPIO voltage adaptation (versus a required 5V Vcc for the relays).


There are 11 input pins for this board (but 13 exposed ! let’s explain tha t8 pins are input pins for relays. There are pulled high internally and need to be pulled down to switch the related relay ON. The main “bus” of the board exposes the 8 inputs, Vcc and Gnd, 10 pins.

A second “pinholder” is very badly designed… But it’s the same on many clones you’ll cross on the interwebz. The wrongest choice here is to expose GND near Vcc were a jumper is provided… 1/10 inch wide, perfectly fitting.


Never, ever, neither…

Either you SHORT the 5V Vcc to the optocouplers ref voltage, either, you provide another voltage ref, say 3.3V for coupling a rapsberry pi (though you still need to provide a stable 5V Vcc !)… But do NOT SHORT Vcc and GND. Your voltage supplier will acknowledge your efforts.

A little test implementation


Very simple, only connect Vcc, GND to the Arduino board power output, and A1..5 pins (avr’s PORTC pins 1..5) to relays board IN1..5.

The code for this sketche can be found on Github (as promised, this time I did not use the Serial class from Arduino API).


We have a suitable board to start the prototype and drive 220V AC mains.

Experimentation (with no load) showed me that something is poor in my connections, at least two “Dupont” cables, as relays 2 and 3 (1..5 plugged) were twitching (led blinking and switching sound… It was quick ! good relays !)

Now let’s implement a minimal TCP/IP stack upon an hardware ethernet controler, and we’re nearly done with that !


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s