project ROBOTIK

membuat sklah otomatis

kode arduino yang di upload

/*
 * ESP8266 NodeMCU LED Control over WiFi Demo
 * Originally by:
 * https://circuits4you.com
 * Modified by:
 * http://gurucanggih.com
 */
 
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
 
//SSID and Password of your WiFi router 
//(this is dummy, it will create wifi station "Wifi Switch" instead)
const char* ssid_name = "mbskertek";
const char* ssid_pass = "rasiapaswordnya";

//Variables
int w=0, z=0;
int statusCode;
const char* ssid = "mbskertek";
const char* passphrase = "rasiapaswordnya";
String st;
String content;
int status_led=0;

#define LED 2
 
//Declare a global object variable from the ESP8266WebServer class.
ESP8266WebServer server(80); //Server on port 80

//bool testWifi(void);
//void launchWeb();
//void setupAP(void);
//void createWebServer();

bool testWifi(void)
{
  int c = 0;
  Serial.println("Waiting for Wifi to connect");
  while ( c < 20 ) {
    if (WiFi.status() == WL_CONNECTED)
    {
      return true;
    }
    delay(500);
    Serial.print("*");
    c++;
  }
  Serial.println("");
  Serial.println("Connect timed out, opening AP");
  return false;
}

void launchWeb()
{
  Serial.println("");
  if (WiFi.status() == WL_CONNECTED)
    Serial.println("WiFi connected");
  Serial.print("Local IP: ");
  Serial.println(WiFi.localIP());
  Serial.print("SoftAP IP: ");
  Serial.println(WiFi.softAPIP());
  createWebServer();
  // Start the server
  server.begin();
  Serial.println("Server started");
} 

void setupAP(void)
{
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);  
  WiFi.softAP("Wifi Switch - MBS Kertek canggih", ""); //create Wifi Station, without password
  Serial.println("softap");
  launchWeb();
  Serial.println("over");
}
 
void createWebServer()
{
 {
    server.on("/", []() {
      Serial.println("Home page");
      
      content = "<!DOCTYPE HTML>\r\n<html>";
      content += "<head><title>saklar lampu WIFI - mbswonosobo.com</title></head>";
      content += "<h1>Wifi saklar lampu - mbswonosobo.com</h1>";
      content += "<h1>Kelompok - ??????????</h1>";
        content += "<p>Anggota Kelompok :</p>";
       content += "<p>John Doe</p>";
         content += "<p>Jane Doe</p>";
           content += "<p>Fulan </p>";
             content += "<p>Fulanah</p>";
               content += "<p>Habib</p>";
                 content += "<p>Habibah</p>";
      if(status_led==0)
      {
        content += "Lampu Mati!<br>";
        content += "Klik untuk menghidupkan <a href=\"ledOn\"><button>ON</button></a><br>";
      }
      else
      {
        content += "LAmpu Hidup!<br>";
        content += "Klik Untuk mematikan <a href=\"ledOff\"><button>OFF</button></a><br>";
      }
      content += "</html>";
      server.send(200, "text/html", content);
    });
 
    server.on("/ledOn", []() {     
      Serial.println("Light on page");
      digitalWrite(LED,LOW); //LED is connected in reverse
      status_led=1;
      
      content = "<!DOCTYPE HTML>\r\n<html>";
      content += "<head><meta http-equiv=\"refresh\" content=\"2;url=/\"><title>Wifi Light Switch - Gurucanggih.com</title></head>";
      content += "Light is ON";
      content += "</html>";
      server.send(200, "text/html", content);
    });

    server.on("/ledOff", []() { 
      Serial.println("Light off page");
      digitalWrite(LED,HIGH); //LED is connected in reverse
      status_led=0; 
      
      content = "<!DOCTYPE HTML>\r\n<html>";
      content += "<head><meta http-equiv=\"refresh\" content=\"2;url=/\"><title>Wifi Light Switch - Gurucanggih.com</title></head>";
      content += "Light is OFF";
      content += "</html>";
      server.send(200, "text/html", content);
    });
  } 
}

void setup(void){
  //Onboard LED port Direction output
  pinMode(LED,OUTPUT); 
  //Power on LED state off
  digitalWrite(LED,HIGH);  
  
  Serial.begin(115200);
  while (!Serial) {
    ;
  }  
  Serial.setDebugOutput(true);  
  WiFi.disconnect();
  delay(10);
  ESP.wdtFeed(); //reset watchdog
  
  WiFi.begin(ssid_name, ssid_pass);
  Serial.printf("Waiting for AP connection ...\n");
  if (testWifi())
  {
    Serial.println("Succesfully Connected!!!");
    return;
  }
  else
  {
    Serial.println("Turning the HotSpot On");
    launchWeb();
    setupAP();// Setup HotSpot
  }
 
  Serial.println();
  Serial.println("Waiting.");
  
}

void loop(void){
  server.handleClient();
}

hubungkan led ke kabel dan hubungkan kabel lampu satu ke pin 3.3v atau 3v dan kabel lampu yang satunya ke pin D4

/*
 * ESP8266 NodeMCU LED Control over WiFi Demo
 * Originally by:
 * https://circuits4you.com
 * Modified by:
 * http://gurucanggih.com
 */
 
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
 
//SSID and Password of your WiFi router 
//(this is dummy, it will create wifi station "Wifi Switch" instead)
const char* ssid_name = "mbskertek";
const char* ssid_pass = "rasiapaswordnya";

//Variables
int w=0, z=0;
int statusCode;
const char* ssid = "mbskertek";
const char* passphrase = "rasiapaswordnya";
String st;
String content;
int status_led=0;

int milidetik =0;
int sdetik = 0;
int detik = 1000;
int smenit = 0;
long menit = 60*detik;
long sjam =0;
long jam = menit*60;

#define LED 2
#define LED2 5
//Declare a global object variable from the ESP8266WebServer class.
ESP8266WebServer server(80); //Server on port 80

//bool testWifi(void);
//void launchWeb();
//void setupAP(void);
//void createWebServer();

bool testWifi(void)
{
  int c = 0;
  Serial.println("Waiting for Wifi to connect");
  while ( c < 20 ) {
    if (WiFi.status() == WL_CONNECTED)
    {
      return true;
    }
    delay(500);
    Serial.print("*");
    c++;
  }
  Serial.println("");
  Serial.println("Connect timed out, opening AP");
  return false;
}

void launchWeb()
{
  Serial.println("");
  if (WiFi.status() == WL_CONNECTED)
    Serial.println("WiFi connected");
  Serial.print("Local IP: ");
  Serial.println(WiFi.localIP());
  Serial.print("SoftAP IP: ");
  Serial.println(WiFi.softAPIP());
  createWebServer();
  // Start the server
  server.begin();
  Serial.println("Server started");
} 

void setupAP(void)
{
  pinMode(LED2, OUTPUT);
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);  
  WiFi.softAP("Wifi Switch- pompa", ""); //create Wifi Station, without password
  Serial.println("softap");
  launchWeb();
  Serial.println("over");
}
 
void createWebServer()
{
 {
    server.on("/", []() {
      Serial.println("Home page");
      
      content = "<!DOCTYPE HTML>\r\n<html>";
      content += "<head><title>saklar lampu WIFI - mbswonosobo.com</title></head>";
      content += "<h1>Wifi saklar lampu - mbswonosobo.com</h1>";
      content += "<h1>Kelompok - 9a stria bajahitam putra 2</h1>";
                 content += "<p></p>";
      if(status_led==0)
      {
        content += "Lampu Mati!<br>";
        content += "Klik untuk menghidupkan <a href=\"ledOn\"><button>ON</button></a><br>";
      }
      else
      {
        content += "LAmpu Hidup!<br>";
        content += "Klik Untuk mematikan <a href=\"ledOff\"><button>OFF</button></a><br>";
      }
      content += "</html>";
      server.send(200, "text/html", content);
    });
 
    server.on("/ledOn", []() {     
      Serial.println("Light on page");
      digitalWrite(LED,LOW); //LED is connected in reverse
      status_led=1;
      
      content = "<!DOCTYPE HTML>\r\n<html>";
      content += "<head><meta http-equiv=\"refresh\" content=\"2;url=/\"><title>Saklar Pompa</title></head>";
      content += "Light is ON";
      content += "</html>";
      server.send(200, "text/html", content);
    });

    server.on("/ledOff", []() { 
      Serial.println("Light off page");
      digitalWrite(LED,HIGH); //LED is connected in reverse
      status_led=0; 
      
      content = "<!DOCTYPE HTML>\r\n<html>";
      content += "<head><meta http-equiv=\"refresh\" content=\"2;url=/\"><title>Saklar Pompa </title></head>";
      content += "Light is OFF";
      content += "</html>";
      server.send(200, "text/html", content);
    });
     server.on("/hoh", []() { 
      Serial.println("Light off page");
      digitalWrite(LED,HIGH); //LED is connected in reverse
      status_led=0; 
      
      content = "<!DOCTYPE HTML>\r\n<html>";
      content += "<head><meta http-equiv=\"refresh\" content=\"2;url=/\"><title>Saklar Pompa</title></head>";
      content += "Light is OFF";
      content += "</html>";
      server.send(200, "text/html", content);
    });
  } 
}

void setup(void){
  //Onboard LED port Direction output
  pinMode(LED,OUTPUT); 
  //Power on LED state off
  digitalWrite(LED,HIGH);  
  
  Serial.begin(115200);
  while (!Serial) {
    ;
  }  
  Serial.setDebugOutput(true);  
  WiFi.disconnect();
  delay(10);
  ESP.wdtFeed(); //reset watchdog
  
  WiFi.begin(ssid_name, ssid_pass);
  Serial.printf("Waiting for AP connection ...\n");
  if (testWifi())
  {
    Serial.println("Succesfully Connected!!!");
    return;
  }
  else
  {
    Serial.println("Turning the HotSpot On");
    launchWeb();
    setupAP();// Setup HotSpot
  }
 
  Serial.println();
  Serial.println("Waiting.");
 
}

void loop(void){
  server.handleClient();
   hitungdetik();
}

void  hitungdetik(void){
milidetik = milidetik+1;
if(milidetik == detik){
 //Serial.println("detik."+sdetik);
 milidetik = 0;
   sdetik = sdetik +1;
  }
  
if(sdetik == menit){
  sdetik =0;
   smenit = smenit +1;
   Serial.println("menit."+smenit);
    
  }
  
  if(smenit == jam){
  smenit =0;
   sjam = sjam +1;
   Serial.println("jam."+sjam);
   
  }
  
}

void lampu(){
  detik = detik +1;
  if (detik = 1000)
  {
     Serial.println("Lampu "+detik);
     digitalWrite(LED2,HIGH);
    }else{
     
     digitalWrite(LED2,LOW);
    }
      if (detik > 20000)detik = 1;
  }