Christopher Mendez Martinez
Published © GPL3+

How to Automate Your Room With Arduino? ENC28j60 Android ...

Hey all of you! i've been working on automating my room, and i finally got it after a hard coding and many tries, and i'm glad to share w...

IntermediateFull instructions provided5 hours1,482
How to Automate Your Room With Arduino? ENC28j60 Android ...

Things used in this project

Hardware components

Relay (generic)
×1
Arduino Nano R3
Arduino Nano R3
×1
Custom fabricated PCB
OSH Park Custom fabricated PCB
×1
Bluetooth Low Energy (BLE) Module (Generic)
×1
TinyShield Proto Terminal Blocks
TinyCircuits TinyShield Proto Terminal Blocks
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Fritzing archive and image

Code

Code

Processing
Just copy it and upload it to your arduino board
//#include <IRremote.h>

#include <UIPEthernet.h> // Used for Ethernet
int on = 1;
int on1 = 1;
 int spk = 5;
//int RECV_PIN = 6;
int luz = 7;
 int a3 = 8;
 int a5 = 9;
 // void recibir();
 void internet();
// **** ETHERNET SETTING ****
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };                                       
IPAddress ip(10,0,0,14);                        
EthernetServer server(80);
         // stores the HTTP request

//IRrecv irrecv(RECV_PIN);

//decode_results results;

void setup() {
  
 //irrecv.enableIRIn(); // Start the receiver
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  pinMode(spk,OUTPUT);
  pinMode(a3,OUTPUT);
  pinMode(a5,OUTPUT);
  pinMode(luz, OUTPUT);
  
}

void loop() {

   
  // listen for incoming clients
  EthernetClient client = server.available();
  
 if (client) 
  {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    String buffer = ""; 
    while (client.connected()) 
    { 
      if (client.available()) 
      {
        char c = client.read();
        buffer+=c;
     
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) 
        { 
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println(); 
          client.println("<meta name=\'viewport\' content=\'width=device-width, initial-scale=1\'>");
          client.println("<link rel='stylesheet' href='https://goo.gl/wRTxw5'>");
          client.print("<a href='l'><button class='btn btn-info btn-block'><h2>LUZ</h2></button></a>");
          client.print("<a href='3'><button class='btn btn-danger btn-block'><h2>3</h2></button></a>");
          client.print("<a href='5'><button class='btn btn-danger btn-block'><h2>5</h2></button></a>");
          client.print("<a href='0'><button class='btn btn-danger btn-block'><h2>OFF</h2></button></a>");
          client.print("<a href='a'><button class='btn btn-success btn-block'><h2>AUDIO</h2></button></a>");
          //client.print("<a href='u'><button class='btn btn-warning btn-block'><h2><span>&#8679;</span></h2></button></a>"); 
          //client.print("<a href='d'><button class='btn btn-warning btn-block'><h2><span>&#8681;</span></h2></button></a>");    
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
          buffer=""; 
        }
        else if (c == '\r') 
        {
           if(buffer.indexOf("GET /l")>=0)
            { on = !on;
              digitalWrite(luz, on ? LOW:HIGH);
              
              }
          if(buffer.indexOf("GET /3")>=0)
           { digitalWrite(a5, LOW);
            digitalWrite(a3, HIGH);}
          if(buffer.indexOf("GET /5")>=0)
            { digitalWrite(a3, HIGH);
             digitalWrite(a5, HIGH);}
          if(buffer.indexOf("GET /0")>=0)
           { digitalWrite(a5, LOW);
            digitalWrite(a3, LOW);} 
          if(buffer.indexOf("GET /a")>=0)
           { on1 = !on1;
            digitalWrite(spk,on1 ? LOW:HIGH);}
         }
        else
        {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      } 
    }
    client.stop();
  }
}

/*void recibir ()
  {
   //digitalWrite(10,LOW);
  if (irrecv.decode(&results)) {
    
    Serial.println(results.value);
    if (results.value == 4021744257 ||results.value == 88334759) {
      on = !on;
      
      digitalWrite(bocina, on ? LOW : HIGH); //control de audio
      delay(250);
      }
      
    else if (results.value == 2645925549 ||results.value == 88341947) {
      on = !on;
      digitalWrite(luz, on ? HIGH : LOW);   //encender y apagar luz
      delay(250);
    }
    
    else if (results.value == 1180376831) {
      digitalWrite(abanico5, LOW);        //abanico en 3
      digitalWrite(abanico3, HIGH);
      delay(250); 
  }
     else if (results.value == 1190948241||results.value == 88280395) {
      digitalWrite(abanico3, HIGH);       //abanico en 5     
      digitalWrite(abanico5, HIGH);
      delay(250); 
  }
  else if (results.value == 1762767691) {
      digitalWrite(abanico3, LOW);        //apagar abanico   
      digitalWrite(abanico5, LOW);
      delay(250); 
  }
  
  
  irrecv.resume(); // Receive the next value
} 
  }*/
 

Credits

Christopher Mendez Martinez

Christopher Mendez Martinez

35 projects • 69 followers
Electronic Engineer and Tech YouTuber who loves automation, programming and sharing his knowledge with everyone.

Comments