ArduinoMEGA 2560 ve Ethernet Kabuğu ile yapılan Web üzerinden Kontrol Projesi


 Arduino: RGB Dongusu
ArduinoMEGA 2560 ve Ethernet Kabuğu ile yapılan Web üzerinden Kontrol Projesi
MikroDenetleyicilerin her alanda yer alması ile birlikte akıllı bina otomasyonları yapmak oldukça kolaylaştı. İnternetin var olduğu her yer ile birlikte de bu akıllı sistemlere uzaktan ulaşmak ve kontrol etmek oldukça kolay. Bu uygulamaların en kolay örneklerden birini de Arduino ile birlikte zahmetsizce gerçekleştirmek mümkün.

Projemizde;
1 Adet ArduinoMEGA 2560 (ArduinoMEGA2560);
1 Adet Ethernet Kabuğu (ArduinoEthernetShield);
1 Adet Arduino Röle Dizisi (8 Channel Relay Module);

kullanıyoruz. Bunların dışında sistemin beslemesi (Arduino girişi ve Röle Dizisi 5 volt ile çalışıyor) için LM7805 devresi ve herhangibi bir ağa bağlı Ethernet kablosu yetiyor.

ArduinoMEGA 2560 üzerinde kullanabileceğimiz, 54 tane I/O pini mevcut. Ancak elimizdeki röle kartı 8 kanal olduğu için biz burada 8 kanal çıkış ve analog girişleri kullanacağız.

Devre Şeması;

Arduino: Web Kontrol=


/*
  ETHERNET CONTROLLER PROJESİ
 
Arduino Mega 2560 ve Wiznet Ethernet Kabugu 
ile yapilan WEB CONTROLLER PROJESİ
 
http://www.erkancil.net
 
  Erkan CIL
  WEB CONTROLLER PROJESİ
  06/05/2012
 
 */

#include 
#include 
#include 

#define P(name) static const prog_uchar name[] PROGMEM 


// internet sayfasında gösterilecek ON / OFF butonlarının gösterimi
// see: http://www.motobit.com/util/base64-decoder-encoder.asp
P(led_on) = "";

P(led_off) = "";



// MAC adresi atama
// IP adresi atama
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,186);


char buffer[8]; 
EthernetServer server(80);

void setup()
{
  // Ethernet Baglantisini Kurma
  Ethernet.begin(mac, ip);
  server.begin();
}
// Ana Döngü Blogu
void loop()
{
  
  EthernetClient client = server.available();
  if (client) {
   
    boolean currentLineIsBlank = true;
    TextFinder finder(client );
    int type = 0;
    while (client.connected()) {
      if (client.available()) {
           


        if(finder.getString("","/", buffer,sizeof(buffer))){
          if(strcmp(buffer, "GET ") == 0 )
            type = 1;
          else if(strcmp(buffer,"POST ") == 0)
            type = 2;
          Serial.print("Type = ");
          Serial.println(type);
          
          if(finder.getString( "", "/", buffer, sizeof(buffer) ))
          {
            Serial.print(buffer);
            Serial.print("|");
            if(strcasecmp(buffer, "analog") == 0)
              showAnalog(client);
            else if(strcasecmp(buffer, "digital") == 0)
              showDigital(client);
            else if(strcasecmp(buffer, "aboutme") == 0)
              aboutMe(client);
            else if(strcmp(buffer, "private")== 0)
              showPrivate(client, finder, type == 2);
            else
              unknownPage(client, buffer);
            break;
          }
        }
      }
      
      delay(1);
      client.stop();
    }
  }
}

// Analog Giris Sayfasinin Olustrulmasi
void showAnalog(EthernetClient client)
{
  
  Serial.println("analog");
  Serial.println("page");
  sendHeader(client,"Multi-page example-Analog");
  client.println("
\r\n"); client.println("

ANALOG PINS

\r\n"); client.println(""); for (int i = 0; i < 16; i++) { client.print(""); } client.println("
analog pin "); client.print(i); client.print("  "); client.print(analogRead(i)); client.println("
"); client.println("
\r\n"); client.println(""); } // Dijital Giris Sayfasinin Olustrulmasi void showDigital(EthernetClient client) { Serial.println("digital"); sendHeader(client,"Multi-page example-Digital"); client.println("
\r\n"); client.println("

DIGITAL PINS

\r\n"); client.println(""); for (int i = 2; i < 6; i++) { pinMode(i, INPUT); digitalWrite(i, HIGH); // turn on pull-ups client.print(""); } client.println("
digital pin "); client.print(i); client.print("  "); if(digitalRead(i) == LOW) printP(client, led_off); else printP(client, led_on); client.println("
"); client.println("
\r\n"); client.println(""); } // Dijital Kontrol Sayfasinin Olustrulmasi void showPrivate(EthernetClient client, TextFinder finder, boolean isPost) { Serial.println("private"); if(isPost) { Serial.println("isPost"); finder.find("\n\r"); Serial.println("searching for parms"); while(finder.findUntil("pinD", "\n\r")){ int pin = finder.getValue(); // the pin number int val = finder.getValue(); // 0 or 1 Serial.print(pin); Serial.print("="); Serial.println(val); pinMode(pin, OUTPUT); digitalWrite(pin, val); } } sendHeader(client,"Multi-page example-Private"); client.println("
\r\n"); client.println("

DIGITAL INPUTS

\r\n"); client.println(""); // show the input pins for (int i = 2; i < 6; i++) { // pins 2-5 are inputs pinMode(i, INPUT); digitalWrite(i, HIGH); // turn on pull-ups client.print(""); } client.println("
digital input "); client.print(i); //client.print(" "); //client.print("  "); //client.print(" "); client.print("  "); if(digitalRead(i) == LOW) //client.print("Low"); printP(client, led_off); else //client.print("high"); printP(client, led_on); client.println("
"); for(int bosluk=0; bosluk<4; bosluk++){ client.println("
"); } client.println("

DIGITAL OUTPUTS

\r\n"); client.println(""); for (int i = 6; i < 10; i++) { client.print(""); } for (int i = 14; i < 54; i++) { client.print(""); } client.println("
digital output "); client.print(i); client.print(" "); htmlButton(client, " ON ", "pinD", i, "1"); /* client.print(" "); */ client.print(" "); htmlButton(client, " OFF ", "pinD", i, "0"); client.print(" "); if(digitalRead(i) == LOW) //client.print("Low"); printP(client, led_off); else //client.print("high"); printP(client, led_on); client.println("
digital output "); client.print(i); client.print(" "); htmlButton(client, " ON ", "pinD", i, "1"); /* client.print(" "); */ client.print(" "); htmlButton(client, " OFF ", "pinD", i, "0"); client.print(" "); if(digitalRead(i) == LOW) //client.print("Low"); printP(client, led_off); else //client.print("high"); printP(client, led_on); client.println("
"); client.println("
\r\n"); client.println("\r\n"); for(int bosluk=0; bosluk<4; bosluk++){ client.println("
\r\n"); } } // create an HTML button void htmlButton( EthernetClient client, char * label, char *name, int nameId, char *value) { P(buttonBegin) = "

"; printP(client, buttonEnd); } // Bulunamama Sayfasinin Olustrulmasi void unknownPage(EthernetClient client, char *page) { Serial.print("Unknown : "); Serial.println("page"); sendHeader(client,"Unknown Page"); client.println("

Bilinmeyen Sayfa !

"); client.println("

Hata : Bilinmeyen Sayfa !

\r\n"); client.println(""); } // Hakkinda Yardim Sayfasinin Olustrulmasi void aboutMe(EthernetClient client) { Serial.print("aboutme : "); Serial.println("page"); sendHeader(client,"About Me"); client.println("
\r\n"); client.println("

About Me

"); client.println("

Bu gomulu web uzerinden kontrol

\r\n"); client.println("

sistemi Erkan Cil tarafindan

\r\n"); client.println("

Arduino Mega 2560 ve Wiznet Ethernet

\r\n"); client.println("

kabugu kullanilarak gerceklestirilmistir.

\r\n"); client.println("

ilkbahar / 2012

\r\n"); client.println("http://www.erkancil.net/Hakkimda\r\n"); for(int bosluk=0; bosluk<4; bosluk++){ client.println("
\r\n"); } client.println("

This embedded web controller

\r\n"); client.println("

project coding by Erkan Cil

\r\n"); client.println("

with using Arduino Mega 2560

\r\n"); client.println("

and Wiznet Ethernet shield.

\r\n"); client.println("

spring / 2012

\r\n"); client.println("http://www.erkancil.net/About Me\r\n"); //client.println(page); client.println("
\r\n"); client.println(""); } void sendHeader(EthernetClient client, char *title) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type text/html"); client.println("\r\n"); client.println(" \r\n"); client.println(" \r\n"); client.println(" \r\n"); client.println(" \r\n"); client.println("erkancil - WebControl Project \r\n"); client.println("\r\n"); client.println("\r\n"); client.println("\r\n"); client.println("\r\n"); client.println("
\r\n"); client.println("\r\n"); client.println("\r\n"); client.println("
\r\n"); client.println("

WEB CONTROLLER v2.1

\r\n"); client.println("\r\n"); client.println("
\r\n"); client.println("

BU WEBSERVER GOMULU BIR SISTEM UZERINDEDIR

\r\n"); client.print("
/Analog Pins/
"); client.print("
/Digital Pins/
"); client.print("
/WEB Kontrol/
"); client.print("
/aboutME/
"); client.println("
  • "); client.println("http://www.erkancil.net
  • \r\n"); client.println("
    \r\n"); client.println("
    \r\n"); client.println("
    \r\n"); client.println(""); } void printP(EthernetClient client, const prog_uchar *str) { // copy data out of program memory into local storage, write out in // chunks of 32 bytes to avoid extra short TCP/IP packets // from webduino library Copyright 2009 Ben Combee, Ran Talbott uint8_t buffer[32]; size_t bufferEnd = 0; while (buffer[bufferEnd++] = pgm_read_byte(str++)) { if (bufferEnd == 32) { client.write(buffer, 32); bufferEnd = 0; } } if (bufferEnd > 1) client.write(buffer, bufferEnd - 1); }

    Çalışmanın Videosu;

    1. Henüz hiç yorum yok.
    (yayınlanmayacak)