Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
MOHD ANIS BIN AZINAN
Published © GPL3+

Switch on a lamp anywhere over the internet using website

Switch on a lamp using your own website. You can access the website through any devices with web browser which installed on that devices.

BeginnerFull instructions provided2,890
Switch on a lamp anywhere over the internet using website

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
Resistor 1k ohm
×1
Resistor 2k ohm
×1
Relay 5V
×1

Hand tools and fabrication machines

Breadboard
Jumper Wire
240VAC Lamp

Story

Read more

Schematics

CIRCUIT DIAGRAM PDF

Code

Arduino Sketch

Arduino
Please change WIFI SSID Name and Password.
Please change URL for your website..
int output1=0;

void setup() {
  // put your setup code here, to run once:
  pinMode(8,OUTPUT);//FOR output1
  
  Serial.begin(115200);

  int connectionSuccess=0;

  while(connectionSuccess==0)
  {
    Serial.println("AT+RST\r\n");
    delay(2000);
  
    while(Serial.available()>0)
    {
      char c=Serial.read();
    }
  
    Serial.println("AT+CWMODE=1\r\n");
    delay(2000);
  
    while(Serial.available()>0)
    {
      char c=Serial.read();
    }
  
    Serial.println("AT+CWJAP=\"TP-Link_F338\",\"20955250\"\r\n");
    delay(5000);
  
    while(Serial.available()>0)
    {
      //char c=Serial.read();
      if(Serial.find('K')==true)
      {
        connectionSuccess=1;
      }
    }
  }
}

void loop() {
  // put your main code here, to run repeatedly:

  String requestGet="GET /index.php HTTP/1.0\r\nHost: switchonthelamp.atwebpages.com\r\nAccept: */*\r\nContent-Type: text/html; charset=UTF-8\r\n";

  Serial.println("AT+CIPSTART=\"TCP\",\"switchonthelamp.atwebpages.com\",80\r\n");
  delay(1000);
  while(Serial.available()>0)
  {
    char c=Serial.read();
  }
 
  Serial.println("AT+CIPSEND="+String(requestGet.length()+2)+"\r\n");
  delay(100);
  while(Serial.available()>0)
  {
    char c=Serial.read();
  }

  //RECEIVE DATA FROM SERVER AND SEARCH FOR KEY BETWEEN TWO HASH TAG
  //----------------------------------------------------------------
  int firstHash=0;
  int secondHash=0;
  String tempText;
  Serial.println(requestGet);
  char arrayByte[1000];
  int saizHuruf=Serial.readBytesUntil('^',arrayByte,1000);
  for(int i=0;i<saizHuruf;i++)
  {
    char a=arrayByte[i];
    tempText+=a;
    if(a=='#'&&firstHash==0)
    {
      firstHash=i;
    }
    if(a=='#'&&firstHash!=0)
    {
      secondHash=i;
    }
  }

  if(firstHash!=0&&secondHash!=0)
  {
    String result=tempText.substring(firstHash,secondHash+1);
    Serial.println(result);

    //OUTPUT 1
    int output1temp=(String(result.charAt(1))).toInt();
    if(output1temp!=output1)
    {
      output1=output1temp;
      if(output1==1)
      {
        digitalWrite(8,HIGH);
      }
      else
      {
        digitalWrite(8,LOW);
      }
    }
    //OUTPUT 1
  }
  //----------------------------------------------------------------
  //RECEIVE DATA FROM SERVER AND SEARCH FOR KEY BETWEEN TWO HASH TAG
  
  delay(1000);
  Serial.println("AT+CIPCLOSE\r\n");
  delay(2000);
  while(Serial.available()>0)
  {
    char c=Serial.read();
  }
  delay(1000);
}

Credits

MOHD ANIS BIN AZINAN
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.