Open top menu
sábado, 7 de fevereiro de 2015


O artigo de hoje é um dos projetos mais interessantes que podemos desenvolver com o Arduino, dando sequencia com os artigos de “Internet das coisas”, é um projeto para acionamento da placa de automação remotamente. O arduino Nano será configurado como WebServer disponibilizando uma página html para visualização e acionamento dos IOs da placa.

Versão do projeto com Mini EthernetShield
Versão do projeto com Ethernet Shield para Arduino

O chip WS5100 tem algumas vantagens em relação ao enc28j60, ele é suportado pelas bibliotecas oficiais do Arduino e como a pilha TCP/IP é executada no próprio shield, o arduino fica responsável apenas em executar o programa do projeto.

Mini Shield

Shield para Arduino

Os dois shields são 100% compatíveis com o projeto e código fonte, vamos ver em detalhes as conexões com o Automation Shield.

Pagina html para acionamento dos comandos e visualização dos status das chaves.


Lista de componentes
1 - Arduino NANO V3.0
1 - Placa Nano Automation Shield, a venda em nossa loja virtual.
1 - Fonte 12V
1 - Shield W5100 - MiniShield ou Ethernet Shield
3 - Chaves liga/desliga
3 - Resistores 10K
16 - Fios com conectores MODU para conexão do projeto

Conexões do projeto com mini Shield
Conexões do projeto com Ethernet Shield
A conexões com o EthernetShield foram realizadas pela parte traseira do shield.

Conexões das Saídas

Alimentação do W5100
Verifique o modelo do shield W5100. As novas versões possuem um regulador de tensão para 5V, nesse caso, podemos ligar direto na saída 5V da placa. algumas versões são alimentadas com 3,3V e deverão ser alimentadas através do pino 3v3 ou pelo conector ICSP,



Código Fonte
O código fonte do projeto é 100% compatível com os dois Shields de Ethernet. Recomendo usar a função F() para montagem do html para optimização da memória usada pelo scketch. A função F(), permite acessar as variáveis strings sem carregar na memória SRAM, o conteúdo da string é armazenado na memoria FLASH do Arduino.

/*
Sergio Mokshin
Automação Live - Jan /2015

*/

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

#include <Servo.h>
Servo myservo;  // create servo object to cLigadotrol a servo

byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0D, 0xA6, 0x09 }; //physical mac address
byte ip[] = {
  192, 168, 0, 177 }; // ip in lan
byte gateway[] = {
  192, 168, 0, 1 }; // internet access via router
byte subnet[] = {
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port


#define CHAVE_1 2
#define CHAVE_2 4
#define CHAVE_3 7

#define PIN_RED 3
#define PIN_GREEN 6
#define PIN_BLUE 5

String readString;

void setup(){


  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  Serial.begin(9600);

  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);

}

void loop(){

  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string
          readString += c;
          //Serial.print(c);
        }

        //if HTTP request has ended
        if (c == '\n') {

          Serial.println(readString);
       
          if(readString.indexOf("?S1Ligado") >0) {
            digitalWrite(A0, HIGH);
          }
          if(readString.indexOf("?S1Desligado") >0) {
            digitalWrite(A0, LOW);
          }

          if(readString.indexOf("?S2Ligado") >0) {
            digitalWrite(A1, HIGH);
          }
          if(readString.indexOf("?S2Desligado") >0) {
            digitalWrite(A1, LOW);
          }

          if(readString.indexOf("?S3Ligado") >0) {
            digitalWrite(A2, HIGH);
          }
          if(readString.indexOf("?S3Desligado") >0) {
            digitalWrite(A2, LOW);
          }

          if(readString.indexOf("?S4Ligado") >0) {
            digitalWrite(A3, HIGH);
          }
          if(readString.indexOf("?S4Desligado") >0) {
            digitalWrite(A3, LOW);
          }

          if(readString.indexOf("?red") >0) {
            analogWrite(PIN_RED, 255);
            analogWrite(PIN_GREEN, 0);            
            analogWrite(PIN_BLUE, 0);
          }

          if(readString.indexOf("?green") >0) {
            analogWrite(PIN_RED, 0);
            analogWrite(PIN_GREEN, 255);            
            analogWrite(PIN_BLUE, 0);
          }

          if(readString.indexOf("?blue") >0) {
            analogWrite(PIN_RED, 0);
            analogWrite(PIN_GREEN, 0);            
            analogWrite(PIN_BLUE, 255);
          }

          if(readString.indexOf("?white") >0) {
            analogWrite(PIN_RED, 255);
            analogWrite(PIN_GREEN, 255);            
            analogWrite(PIN_BLUE, 255);
          }


          if(readString.indexOf("?rgboff") >0) {
            analogWrite(PIN_RED, 0);
            analogWrite(PIN_GREEN, 0);            
            analogWrite(PIN_BLUE, 0);
          }

          int S1 = digitalRead(A0);
          int S2 = digitalRead(A1);
          int S3 = digitalRead(A2);
          int S4 = digitalRead(A3);

          int Chave1 = digitalRead(CHAVE_1);
          int Chave2 = digitalRead(CHAVE_2);
          int Chave3 = digitalRead(CHAVE_3);

          int LedR = analogRead(6);
          int LedG = analogRead(5);
          int LedB = analogRead(3);

          client.println(F("HTTP/1.1 200 OK")); //send new page
          client.println(F("Content-Type: text/html"));
          client.println();

          client.println(F("<HTML>"));
          client.println(F("<HEAD>"));
          client.println(F("<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css' rel='stylesheet'></link>"));
          client.println(F("</head>"));
          client.println(F("<body>"));
          client.println(F("<div class='jumbotron'>"));
          client.println(F("<h2>Interface de comando</h2>"));
          client.println(F("<div class='row'>"));
          client.println(F("<div class='col-md-10'>"));
          client.println(F("<table class='table table-bordered'>"));
          client.println(F("<tbody>"));
          //S 1
          client.println(F("<tr><td width=130px>S 1 - "));
          if(S1 == HIGH)
          {
            client.println(F("Ligado"));
            client.println(F("</td><td>"));
            client.println(F("<a class='btn btn-danger btn-lg' href='?S1Desligado'>Desligar</buttLigado>"));
          }
          else
          {
            client.println(F("Desligado"));
            client.println(F("</td><td>"));
            client.println(F("<a class='btn btn-success btn-lg' href='?S1Ligado'>Ligar</buttLigado>"));      
          }      
          client.println(F("</td></tr>"));


          //S 2
          client.println(F("<tr><td width=130px>S 2 - "));
          if(S2 == HIGH)
          {
            client.println(F("Ligado"));
            client.println(F("</td><td>"));
            client.println(F("<a class='btn btn-danger btn-lg' href='?S2Desligado'>Desligar</buttLigado>"));
          }
          else
          {
            client.println(F("Desligado"));
            client.println(F("</td><td>"));
            client.println(F("<a class='btn btn-success btn-lg' href='?S2Ligado'>Ligar</buttLigado>"));      
          }      
          client.println(F("</td></tr>"));


          //S 3
          client.println(F("<tr><td width=130px>S 3 - "));
          if(S3 == HIGH)
          {
            client.println(F("Ligado"));
            client.println(F("</td><td>"));
            client.println(F("<a class='btn btn-danger btn-lg' href='?S3Desligado'>Desligar</buttLigado>"));
          }
          else
          {
            client.println(F("Desligado"));
            client.println(F("</b></td><td>"));
            client.println(F("<a class='btn btn-success btn-lg' href='?S3Ligado'>Ligar</buttLigado>"));      
          }      
          client.println(F("</td></tr>"));


          //S 4
          client.println(F("<tr><td width=130px>S 4 - "));
          if(S4 == HIGH)
          {
            client.println(F("Ligado"));
            client.println(F("</td><td>"));
            client.println(F("<a class='btn btn-danger btn-lg' href='?S4Desligado'>Desligar</buttLigado>"));
          }
          else
          {
            client.println(F("Desligado"));
            client.println(F("</td><td>"));
            client.println(F("<a class='btn btn-success btn-lg' href='?S4Ligado'>Ligar</buttLigado>"));      
          }      
          client.println(F("</td></tr>"));


          //RGB
          client.println(F("<tr><td>RGB</td><td>"));
          client.println(F("<a class='btn btn-primary btn-lg' href='?blue' >Azul</a>&nbsp;"));
          client.println(F("<a class='btn btn-danger btn-lg' href='?red' >Vermelho</a>&nbsp;"));      
          client.println(F("<a class='btn btn-success btn-lg' href='?green' >Verde</a>&nbsp;"));      
          client.println(F("<a class='btn btn-default btn-lg' href='?white' >Branco</a>&nbsp;"));                  
          client.println(F("<a class='btn btn-link' href='?rgboff' >Desligar</a>&nbsp;"));                                                          
          client.println(F("</td></tr>"));




          client.println(F("<tr><td colspan=2>Chave 1 - "));
          if(Chave1 == HIGH)
          {
            client.println(F("<span class='glyphicon glyphicon-ok-circle' aria-hidden='true'></span>"));  
          }
          else
          {
            client.println(F("<span class='glyphicon glyphicon-ban-circle' aria-hidden='true'></span>"));  
          }

          client.println(F("<br>"));    

          client.println(F("Chave 2 - "));
          if(Chave2 == HIGH)
          {
            client.println(F("<span class='glyphicon glyphicon-ok-circle' aria-hidden='true'></span>"));  
          }
          else
          {
            client.println(F("<span class='glyphicon glyphicon-ban-circle' aria-hidden='true'></span>"));  
          }


          client.println(F("<br>"));    
          client.println(F("Chave 3 - "));

          if(Chave3 == HIGH)
          {
            client.println(F("<span class='glyphicon glyphicon-ok-circle' aria-hidden='true'></span>"));  
          }
          else
          {
            client.println(F("<span class='glyphicon glyphicon-ban-circle' aria-hidden='true'></span>"));  
          }

          client.println(F("<br>"));    
          client.println(F("<a class='btn btn-link' href='/'>Verificar status chaves</a>"));                                                          
       
       
          client.println(F("</td></tr>"));
       

          client.println(F("</tbody>"));
          client.println(F("</table>"));
          client.println(F("</div>"));

          client.println(F("</body>"));
          client.println(F("</html>"));

          delay(1);
          //stopping client
          client.stop();

          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

Vamos ver um vídeo do projeto com a versão mini Shield W5100


E com a versão Ethernet Shield para Arduino Uno


Projeto com WebServer e W5100 que automatiza um aquário, em breve será publicado no site.









Tagged

11 comentários :

  1. Como faço para adquirir a placa ?
    essa interface funciona com iphone 5 ?

    ResponderExcluir
    Respostas
    1. Julio, está diponível em estoque apenas a versão 2.0. Não funciona, ainda não foi desenvolvido o aplicativo para iOS.

      Excluir
  2. Ola você ainda tem esta placa a venda?

    ResponderExcluir
  3. Hi,

    Nice to meet you.

    We are the WIZnet Team in India.

    We have been searching some application references in which WIZnet solution is applied and found your project “Automation shield -webserver with w5100 . ". In the project Wiznet chip W5100 is used (Arduino ethernet shield). Your development looks very cool & smart.

    Recently we have developed WIZnet Museum (http://wiznetmuseum.com) site. This is an academic-purposed collection of open projects, tutorials, articles and etc from our global customers.
    If you are O.K. we would like to introduce your project and device in here. Hopefully, you will allow this.
    Hopefully, keep contacting us for the friendship.

    ResponderExcluir
  4. Hi,

    Nice to meet you.

    We are the WIZnet Team in India.

    We have been searching some application references in which WIZnet solution is applied and found your project “Automation shield -webserver with w5100. ". In the project Wiznet chip W5100 is used (Arduino ethernet shield). Your development looks very cool & smart.

    Recently we have developed WIZnet Museum (http://wiznetmuseum.com) site. This is an academic-purposed collection of open projects, tutorials, articles and etc from our global customers.
    If you are O.K. we would like to introduce your project and device in here. Hopefully, you will allow this.
    Hopefully, keep contacting us for the friendship.

    ResponderExcluir
  5. Hi,

    Nice to meet you.

    We are the WIZnet Team in India.

    We have been searching some application references in which WIZnet solution is applied and found your project “Automation shield -webserver with w5100. ". In the project Wiznet chip W5100 is used (Arduino ethernet shield). Your development looks very cool & smart.

    Recently we have developed WIZnet Museum (http://wiznetmuseum.com) site. This is an academic-purposed collection of open projects, tutorials, articles and etc from our global customers.
    If you are O.K. we would like to introduce your project and device in here. Hopefully, you will allow this.
    Hopefully, keep contacting us for the friendship.

    ResponderExcluir
  6. Como faço para adquirir a placa ?
    Nao achei link para compra.

    ResponderExcluir
  7. Como faço para adquirir a placa ?
    Nao encontrei link para compra ?

    ResponderExcluir
  8. desculpa minha ignorância, mas isso não é um aplicativo e sim um servidor usando o framework bootstrap, é acessado pelo navegador (browser)

    ResponderExcluir
  9. É possível acessar remotamente? Tipo eu estando viajando.

    ResponderExcluir
  10. Automatic algorithms have made it potential to change playing cards after each hand, rising the game’s transparency. You open an account and ship money to it utilizing wire transfer out of your local Korean financial institution. All respectable online sports activities betting websites supply NETELLER deposits through the cashier system on their web site. Key HighlightsThe casinos and gaming market consists 퍼스트카지노 of all types of betting and gaming. Since slots may be found in their lots of at online casinos, might be} daunting to figure out|to determine} what to play first. Your finest guess is to follow the group in this case and check out|and take a glance at} your hand at the online slots everyone else is enjoying in}.

    ResponderExcluir