SHIELD ETHERNET WIZnet W5100

Hello guys! No post anterior falamos sobre o ENC26J60 , hoje falaremos sobre o que por muito tempo foi por muito tempo o queridinho de todos, WIZnet W5100. Custando por volta de R$50,00,possui slot para SDCard de 2Gb ou 4Gb ,este Shield Ethernet desenvolvido pela WIZnet e é compatível com os protocolos de rede : TCP, UDP, ICMP, IPv4, ARP, IGMP, PPPoE.

1000701-1

Permite até 4 conexões simultâneas e por possui uma memoria interna um pouco maior que o ENC26J60, seu desempenho de torna muito mais fluido, respeitando o limite do hardware , claro! Neste projeto vamos acionar 8 cargas através da pagina web.

whatsapp-image-2016-12-08-at-08-49-41
NAVEGADOR NO CELULAR
sem-titulo
NAVEGADOR NO PC

MATERIAL:

  • ARDUINO MEGA;
  • JUMPERS;
  • RELE 8 CANAIS;

ESQUEMA:

O Fritzing não disponibiliza o modulo relay, então tive que improvisar. os esquema do relay usa:

Alimentação externa 12V

Resistor 220Ω

Capacitor 1000µF

CI ULN2803A

ralay

CÓDIGO:

CÓDIGO:

O código é um exemplo encontrado na biblioteca EtherCard.h

 /*
 Web Server
 ADAPTADO POR JORGE WALLACE EM 08/12/2016
 */

#include <SPI.h>
#include <Ethernet.h>


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x2D }; // <---- MAC ADRESS, PODE DEIXAR ESTE POR PADRÃO, POREM SE FOR USAR MAIS DE UM NA MESMA REDE É MELHOR MODIFICAR PARA NÃO DA ERRO 
byte gateway[] = { 192, 168, 0, 1 }; // <------- AQUI VAI O GATEWAY O END. DO SEU ROTEADOR OU PONTO DE ACESSO.
byte subnet[] = { 255, 255, 255, 0 }; // <------- MASCARÁ DE SUB-REDE
IPAddress ip(192,168,0,199); // <------- ENTREÇO DE IP QUE VOCÊ IRÁ ATRIBUIR AO SEU SHIELD 
EthernetServer server(80); // <------- PORTA DE CONEXÃO HTTP

/*-------------------------------------------INICIO------------------------------------------*/ 
// DECLARAÇÃO DO RELÉ , CADA CANAL PARA UMA PORTA DIGITAL ,USEI ESSA SEQUENCIA POR COMODIDADE PARA USAR OS FIOS NO ARDUINO MEGA
#define RELE_1 22
#define RELE_2 24
#define RELE_3 26
#define RELE_4 28
#define RELE_5 30
#define RELE_6 32
#define RELE_7 34
#define RELE_8 36
/*-------------------------------------------FIM---------------------------------------------*/ 

String readString;

void setup() {
 
 /*-------------------------------------------INICIO------------------------------------------*/ 
 // DECLARAÇÃO DOS CANAIS DO RELE COMO SAÍDAS E AS INICIANDO EM ESTADO HIGH, A DEPENDER DO SEU RELÉ O ESTADO INICIAL PODE SER LOW 
 pinMode(RELE_1, OUTPUT); 
 digitalWrite(RELE_1, HIGH); 
 
 pinMode(RELE_2, OUTPUT); 
 digitalWrite(RELE_2, HIGH); 
 
 pinMode(RELE_3, OUTPUT); 
 digitalWrite(RELE_3, HIGH); 
 
 pinMode(RELE_4, OUTPUT); 
 digitalWrite(RELE_4, HIGH); 
 
 pinMode(RELE_5, OUTPUT); 
 digitalWrite(RELE_5, HIGH); 
 
 pinMode(RELE_6, OUTPUT); 
 digitalWrite(RELE_6, HIGH); 
 
 pinMode(RELE_7, OUTPUT); 
 digitalWrite(RELE_7, HIGH); 
 
 pinMode(RELE_8, OUTPUT); 
 digitalWrite(RELE_8, HIGH); 
 /*-------------------------------------------FIM---------------------------------------------*/ 
 
 
 
 // ABERTURA DA COMUNICAÇÃO SERIAL
 Serial.begin(9600);
 while (!Serial) {
 ; 
 }


 // STARTA A CONEXÃO COM O SERVIDOR
 /*-------------------------------------------INICIO------------------------------------------*/ 
 Ethernet.begin(mac, ip);
 server.begin();
 Serial.print("server is at ");
 Serial.println(Ethernet.localIP()); 
 /*-------------------------------------------FIM---------------------------------------------*/ 
 
}


void loop() {
 
 EthernetClient client = server.available();
 
 if (client) {
 Serial.println("new client");
 
 boolean currentLineIsBlank = true;
 while (client.connected()) {
 
 if (client.available()) {
 
 char c = client.read();
 
 if (readString.length() < 100) {
 
 readString += c; 
 }
 
 Serial.write(c);
 
 
 if (c == '\n' && currentLineIsBlank) {
 /*-------------------------------------------INICIO------------------------------------------*/ 
 client.println("HTTP/1.1 200 OK");
 client.println("Content-Type: text/html");
 client.println("Connection: close"); 
 client.println("Refresh: 2"); 
 client.println();
 client.println("<!DOCTYPE HTML>");
 client.println("<html>");
 client.println("<HEAD>");
 client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
 client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
 //client.println("<link rel=\"stylesheet\" type=\"text/css\" href="bootstrap/css/bootstrap.min.css" />");
 client.println("<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css' rel='stylesheet'></link>");
 client.println("</HEAD>");
 client.println("<title>ARDUDINO - Automacao Residencial</title>");
 client.println("<body background='#0c0c0c'>");
 client.println(" <style type='text/css'>");
 client.println("table");
 client.println(" { ");
 client.println("display: table;");
 client.println("border-collapse: separate;");
 client.println("border-spacing: 5px;");
 client.println("}");

 client.println("</style>");
 client.println("<img alt='ARDUDINO' src='https://ardudino.files.wordpress.com/2016/12/ardudino2.png?w=971'/><br/>");
 client.print("<center> <p> <h1>Automacao Residencial Ardudino v1.0 </h1></p> ");
 
 /*----------------------------------CONTROLANDO OS RELES 1------------------------------------*/
 /*-------------------------------------------INICIO------------------------------------------*/ 
 /*-------------------------------------------RELÉ 1-----------------------------------------*/
 client.println("<center>");
 client.println("<table border='0' width=400 height=150 ALIGN='center'>");
 client.println("<tr >");
 client.println("<tr >"); 
 client.println("<td>");
 client.println("CARGAS");
 client.println("</td>");
 client.println("<td colspan='2' align=center> ");
 client.println("ACIONAMENTO");
 client.println("</td>");
 client.println("<td>");
 client.println("STATUS");
 client.println("</td>");
 client.println("</tr >"); 
 client.println("</tr >"); 
 client.println("<tr >"); 
 client.println("<td>");
 client.println("SALA ");
 client.println("</td>"); 
 client.println("<td>"); 
 client.println("<a class='btn btn-success btn-lg' href='/rele1/ON' type='button'>ON</button>");
 client.println("</td>");
 client.println("<td>"); 
 client.println("<a class='btn btn-danger btn-lg' href='/rele1/OFF' type='button'>OFF</button>");
 client.println("</td>");
 client.println("</td>");
 client.println("<td >");
 if (!digitalRead(RELE_1))
 { 
 client.print("<p style=\"font-family:arial;color:green;font-size:15px;\">ON</p>");
 }
 else
 {
 client.print("<p style=\"font-family:arial;color:red;font-size:15px;\">OFF</p>");
 }
 client.println("</td>");
 client.println("</tr>");
 client.println("</tr>");
 
 /*-------------------------------------------RELÉ 2------------------------------------------*/
 client.println("<tr >"); 
 client.println("<td>");
 client.println("COZINHA ");
 client.println("</td>"); 
 client.println("<td>"); 
 client.println("<a class='btn btn-success btn-lg' href='/rele2/ON' type='button'>ON</button>");
 client.println("</td>");
 client.println("<td>"); 
 client.println("<a class='btn btn-danger btn-lg' href='/rele2/OFF' type='button'>OFF</button>");
 client.println("</td>");
 client.println("</td>");
 client.println("<td >");
 if (!digitalRead(RELE_2))
 { 
 client.print("<p style=\"font-family:arial;color:green;font-size:15px;\">ON</p>");
 }
 else
 {
 client.print("<p style=\"font-family:arial;color:red;font-size:15px;\">OFF</p>");
 }
 client.println("</td>");
 client.println("</tr>");
 client.println("</tr>");
 /*-------------------------------------------RELÉ 3------------------------------------------*/
 client.println("<tr >"); 
 client.println("<td>");
 client.println("BANHEIRO ");
 client.println("</td>"); 
 client.println("<td>"); 
 client.println("<a class='btn btn-success btn-lg' href='/rele3/ON' type='button'>ON</button>");
 client.println("</td>");
 client.println("<td>"); 
 client.println("<a class='btn btn-danger btn-lg' href='/rele3/OFF' type='button'>OFF</button>");
 client.println("</td>");
 client.println("</td>");
 client.println("<td >");
 if (!digitalRead(RELE_3))
 { 
 client.print("<p style=\"font-family:arial;color:green;font-size:15px;\">ON</p>");
 }
 else
 {
 client.print("<p style=\"font-family:arial;color:red;font-size:15px;\">OFF</p>");
 }
 client.println("</td>");
 client.println("</tr>");
 client.println("</tr>");
 /*-------------------------------------------RELÉ 4------------------------------------------*/
 client.println("<tr >"); 
 client.println("<td>");
 client.println("QUARTO ");
 client.println("</td>"); 
 client.println("<td>"); 
 client.println("<a class='btn btn-success btn-lg' href='/rele4/ON' type='button'>ON</button>");
 client.println("</td>");
 client.println("<td>"); 
 client.println("<a class='btn btn-danger btn-lg' href='/rele4/OFF' type='button'>OFF</button>");
 client.println("</td>");
 client.println("</td>");
 client.println("<td >");
 if (!digitalRead(RELE_4))
 { 
 client.print("<p style=\"font-family:arial;color:green;font-size:15px;\">ON</p>");
 }
 else
 {
 client.print("<p style=\"font-family:arial;color:red;font-size:15px;\">OFF</p>");
 }
 client.println("</td>");
 client.println("</tr>");
 client.println("</tr>");
 /*-------------------------------------------RELÉ 5------------------------------------------*/
 client.println("<tr >"); 
 client.println("<td>");
 client.println("GARAGEM ");
 client.println("</td>"); 
 client.println("<td>"); 
 client.println("<a class='btn btn-success btn-lg' href='/rele5/ON' type='button'>ON</button>");
 client.println("</td>");
 client.println("<td>"); 
 client.println("<a class='btn btn-danger btn-lg' href='/rele5/OFF' type='button'>OFF</button>");
 client.println("</td>");
 client.println("</td>");
 client.println("<td >");
 if (!digitalRead(RELE_5))
 { 
 client.print("<p style=\"font-family:arial;color:green;font-size:15px;\">ON</p>");
 }
 else
 {
 client.print("<p style=\"font-family:arial;color:red;font-size:15px;\">OFF</p>");
 }
 client.println("</td>");
 client.println("</tr>");
 client.println("</tr>");
 /*-------------------------------------------RELÉ 6------------------------------------------*/
 client.println("<tr >"); 
 client.println("<td>");
 client.println("JARDIM ");
 client.println("</td>"); 
 client.println("<td>"); 
 client.println("<a class='btn btn-success btn-lg' href='/rele6/ON' type='button'>ON</button>");
 client.println("</td>");
 client.println("<td>"); 
 client.println("<a class='btn btn-danger btn-lg' href='/rele6/OFF' type='button'>OFF</button>");
 client.println("</td>");
 client.println("</td>");
 client.println("<td >");
 if (!digitalRead(RELE_6))
 { 
 client.print("<p style=\"font-family:arial;color:green;font-size:15px;\">ON</p>");
 }
 else
 {
 client.print("<p style=\"font-family:arial;color:red;font-size:15px;\">OFF</p>");
 }
 client.println("</td>");
 client.println("</tr>");
 client.println("</tr>");
 /*-------------------------------------------RELÉ 7------------------------------------------*/
 client.println("<tr >"); 
 client.println("<td>");
 client.println("CASA DO CACHORRO ");
 client.println("</td>"); 
 client.println("<td>"); 
 client.println("<a class='btn btn-success btn-lg' href='/rele7/ON' type='button'>ON</button>");
 client.println("</td>");
 client.println("<td>"); 
 client.println("<a class='btn btn-danger btn-lg' href='/rele7/OFF' type='button'>OFF</button>");
 client.println("</td>");
 client.println("</td>");
 client.println("<td >");
 if (!digitalRead(RELE_7))
 { 
 client.print("<p style=\"font-family:arial;color:green;font-size:15px;\">ON</p>");
 }
 else
 {
 client.print("<p style=\"font-family:arial;color:red;font-size:15px;\">OFF</p>");
 }
 client.println("</td>");
 client.println("</tr>");
 client.println("</tr>");
 /*-------------------------------------------RELÉ 8------------------------------------------*/
 client.println("<tr >"); 
 client.println("<td>");
 client.println("VARANDA");
 client.println("</td>"); 
 client.println("<td>"); 
 client.println("<a class='btn btn-success btn-lg' href='/rele8/ON' type='button'>ON</button>");
 client.println("</td>");
 client.println("<td>"); 
 client.println("<a class='btn btn-danger btn-lg' href='/rele8/OFF' type='button'>OFF</button>");
 client.println("</td>");
 client.println("</td>");
 client.println("<td >");
 if (!digitalRead(RELE_8))
 { 
 client.print("<p style=\"font-family:arial;color:green;font-size:15px;\">ON</p>");
 }
 else
 {
 client.print("<p style=\"font-family:arial;color:red;font-size:15px;\">OFF</p>");
 }
 client.println("</td>");
 client.println("</tr>");
 client.println("</tr>");
 /*-------------------------------------------FIM---------------------------------------------*/
 client.println("</center>");
 client.println("<br />");
 client.println("</table>"); 
 
 
 /*-------------------------------------------INICIO------------------------------------------*/
 // COMEÇA AQUI A TRANSIÇÃO ENTRE O HTTP E O SHIELD
 /*-------------------------------------------RELÉ 1------------------------------------------*/
 if(readString.indexOf("/rele1/ON") >0)
 {
 digitalWrite(RELE_1, LOW); 
 }
 else{
 if(readString.indexOf("/rele1/OFF") >0)
 {
 digitalWrite(RELE_1, HIGH); 
 
 }
 }
 
 /*-------------------------------------------RELÉ 2------------------------------------------*/ 
 if(readString.indexOf("/rele2/ON") >0)
 {
 digitalWrite(RELE_2, LOW); 
 }
 else{
 if(readString.indexOf("/rele2/OFF") >0)
 {
 digitalWrite(RELE_2, HIGH); 
 }
 }
/*-------------------------------------------RELÉ 3------------------------------------------*/ 
 if(readString.indexOf("/rele3/ON") >0)
 {
 digitalWrite(RELE_3, LOW); 
 }
 else{
 if(readString.indexOf("/rele3/OFF") >0)
 {
 digitalWrite(RELE_3, HIGH); 
 }
 } 
 /*-------------------------------------------RELÉ 4------------------------------------------*/ 
 if(readString.indexOf("/rele4/ON") >0)
 {
 digitalWrite(RELE_4, LOW); 
 }
 else{
 if(readString.indexOf("/rele4/OFF") >0)
 {
 digitalWrite(RELE_4, HIGH); 
 
 }
 }
 /*-------------------------------------------RELÉ 5------------------------------------------*/ 
 if(readString.indexOf("/rele5/ON") >0)
 {
 digitalWrite(RELE_5, LOW); 
 }
 else{
 if(readString.indexOf("/rele5/OFF") >0)
 {
 digitalWrite(RELE_5, HIGH); 
 }
 }
/*-------------------------------------------RELÉ 6------------------------------------------*/ 
 if(readString.indexOf("/rele6/ON") >0)
 {
 digitalWrite(RELE_6, LOW); 
 }
 else{
 if(readString.indexOf("/rele6/OFF") >0)
 {
 digitalWrite(RELE_6, HIGH); 
 }
 }
 /*-------------------------------------------RELÉ 7------------------------------------------*/ 
 if(readString.indexOf("/rele7/ON") >0)
 {
 digitalWrite(RELE_7, LOW); 
 }
 else{
 if(readString.indexOf("/rele7/OFF") >0)
 {
 digitalWrite(RELE_7, HIGH); 
 }
 }
 /*-------------------------------------------RELÉ 8------------------------------------------*/ 
 if(readString.indexOf("/rele8/ON") >0)
 {
 digitalWrite(RELE_8, LOW); 
 }
 else{
 if(readString.indexOf("/rele8/OFF") >0)
 {
 digitalWrite(RELE_8, HIGH); 
 
 }
 } 
 client.println("<table border=\"0\">");
 client.println("<tr>");
 client.println("<td>"); 
 client.println("<hr> <p> By Jorge Wallace </p><p style=\"font-family:arial;color:blue;font-size:50px;\">Blog Ardudino</p>");
 client.println("</td>");
 client.println("</tr>"); 
 client.println("</table>"); 
 readString="";
 client.println("</body>"); 
 client.println("</html>");
 /*-------------------------------------------FIM---------------------------------------------*/ 
 break;
 }// if ( c == \n )
 
 
 if (c == '\n') {
 currentLineIsBlank = true;
 } 
 else if (c != '\r') {
 
 currentLineIsBlank = false;
 }
 
 }
 }
 
 delay(1);
 
 client.stop();
 Serial.println("client disonnected");
 
 }
 
}


 

Anúncios

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair /  Alterar )

Foto do Google

Você está comentando utilizando sua conta Google. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

Conectando a %s