ETHERNET ENC28J60 + 2 Relay Modules

IMG_1377Arduino-Mega-2560-wiring-enc28j60

This sketch requires etherShield and ETHER_28J60 library.

You can download the library here

https://docs.google.com/file/d/0B4qM0hq-OmC1RHhEcXRNSmZ1YW8/

// A simple web server that turn a relay on or off”

#include “etherShield.h”
#include “ETHER_28J60.h”
#define RELAY1  22
#define RELAY2  23

static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};   // this just needs to be unique for your network,

static uint8_t ip[4] = {192, 168, 1, 3}; // IP address for the webserver

static uint16_t port = 240; // Use port 80 – the standard for HTTP  MAX port is 240.

ETHER_28J60 e;

void setup()
{
e.setup(mac, ip, port);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
digitalWrite(RELAY1,HIGH);
digitalWrite(RELAY2,HIGH);
}

void loop()
{
char* params;
if (params = e.serviceRequest())
{
e.print(“<h1><a href=’/?led1=off&led2=off’>cmos tjet</a></h1>”);
if (strcmp(params, “?led1=on&led2=off”) == 0)
{
pinMode(RELAY1, HIGH);
pinMode(RELAY2, LOW);
e.print(“<a href=’?led1=off&led2=off’><button style=’border: 1px solid #ff0000; border-left: 10px solid #ff0000′ type=’button’>RELAY 1 IS ON</button></a><a href=’?led1=on&led2=on’><br/><button style=’border: 1px solid #000; border-left: 10px solid #000′ type=’button’>RELAY 2 IS OFF</button></a>”);
}
else if (strcmp(params, “?led1=off&led2=on”) == 0)
{
pinMode(RELAY1, LOW);
pinMode(RELAY2, HIGH);
e.print(“<a href=’?led1=on&led2=on’><button style=’border: 1px solid #000; border-left: 10px solid #000′ type=’button’>RELAY 1 IS OFF</button></a><a href=’?led1=off&led2=off’><br/><button style=’border: 1px solid #ff0000; border-left: 10px solid #ff0000′ type=’button’>RELAY 2 IS ON</button></a>”);
}
else if (strcmp(params, “?led1=off&led2=off”) == 0)
{
pinMode(RELAY1, LOW);
pinMode(RELAY2, LOW);
e.print(“<a href=’?led1=on&led2=off’><button style=’border: 1px solid #000; border-left: 10px solid #000′ type=’button’>RELAY 1 IS OFF</button></a><a href=’?led1=off&led2=on’><br/><button style=’border: 1px solid #000; border-left: 10px solid #000′ type=’button’>RELAY 2 IS OFF</button></a>”);
}
else if (strcmp(params, “?led1=on&led2=on”) == 0)
{
pinMode(RELAY1, HIGH);
pinMode(RELAY2, HIGH);
e.print(“<a href=’?led1=off&led2=on’><button style=’border: 1px solid #ff0000; border-left: 10px solid #ff0000′ type=’button’>RELAY 1 IS ON</button></a><a href=’?led1=on&led2=off’><br/><button style=’border: 1px solid #ff0000; border-left: 10px solid #ff0000′ type=’button’>RELAY 2 IS ON</button></a>”);
}
e.respond();
}
}

Advertisements
This entry was posted in Arduino Project. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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