Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; GeSHi has a deprecated constructor in /home/pcbauwfj/schremote/lib/geshi/geshi.php on line 259
Ethernet to GPIO - Network Driven Relays by SR01E12
SCH-REMOTE.COM

Application note: Ethernet to GPIO - Network Driven Relays

Ethernet relay demo

Preface

In this application note is shown how to drive 4 lamps by a PC with an Ethernet connection. It is built with 4 relays, driven by GPIO ports of SR01E12. Four ports of SR01E12 are configured to output. Each one drives an indication LED and transistor that open and close a relay. On demo board exist 3,3V regulator for the Ethernet bridge and 5V regulator for the relays.

Just adding relays, the board can be extended to drive up to 12 outputs. Outputs can be extended to many more by using shift registers like 74HC595.

Schematic

Ethernet to Relay Schematic

Board require 6,5-9V 400mA power supply to POWER connector. It can be provided by wall power adapter. Each relay has normally open and normally closed output. Relays used in design can handle up to 250V 5A load.

Software

GUI QT C++ Application

Ethernet to Relay Software Ethernet to Relay Software

The user interface is built with QT framework. It is split in 2 dialogs, first is to obtain all network interfaces, search for SR01E12 boards and select one of them. Second dialog has 4 buttons to toggle the relays.

Command line C Application

A very simple command line tool to drive the relays. Whole source code is:


Deprecated: Function create_function() is deprecated in /home/pcbauwfj/schremote/lib/geshi/geshi.php on line 4736
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "libschremote.h"
 
#define FIRST_RELAY_PIN 8
 
int main(int argc, char *argv[])
  {
  SR_HANDLE srh;
  int relay;
 
  if (argc < 3)
    {
    printf("Usage SrRelay <ip> <relay 1-4> <on|off>");
    return 0;
    }
 
  srh = sr_open_eth(argv[1]);
  if (!srh)
    {
    printf("Failed to allocate a handle\n");
    return 0;
    }
 
  relay = atoi(argv[2]);
  if (relay < 1 || relay > 4)
    {
    printf("Invalid relay number\n");
    return 0;
    }
 
  if (stricmp(argv[3], "on") == 0)
    {
    printf("Relay %d ON: ", relay);
    if (!sr_pin_setup(srh, FIRST_RELAY_PIN + relay-1, sr_pt_dout_high)) printf("FAIL\n");
    else printf("OK\n");
    }
  else //assume off
    {
    printf("Relay %d OFF: ", relay);
    if (!sr_pin_setup(srh, FIRST_RELAY_PIN + relay-1, sr_pt_dout_low)) printf("FAIL\n");
    else printf("OK\n");
    }
  }
 

To compile, is needed just to add the libschremote library to the project. For example in VC is done like: "cl SrRelay.cpp /link libschremote.lib". Sample usage of executable is: "SrRelay 192.168.1.119 1 on".

Download

SrRelay QT GUI ExecQT GUI version - Executable file with all needed libraries
SrRelay QT GUI SrcQT GUI version - Source code (requires QT framework)
SrRelay Cmd ExecCommand Line version - Executable file with all needed libraries
SrRelay Cmd SrcCommand Line version - Source code

Gallery

Ethernet to Relays
Ethernet to Relays
Ethernet to Relays
Ethernet to Relays
Full Size

* On grayed area of evaluation board are placed components not related to the project.

Follow us on: Facebook Youtube