Translate

IOT Project Nodemcu ESP8266 Control Led Menggunakan Internet Server THINGSPEAK

IOT Project Nodemcu ESP8266 Control Led Menggunakan Internet Server THINGSPEAK


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat dikendalikan secara jarak jauh. Alat ini menggunakan NodeMCU ESP8266 yang mana telah dilengkapi dengan modul wifi. server yang digunakan adalah THINGSPEAK. untuk lebih jelasnya berikut adalah daftar komponen dan programnya.    




a. NodeMCU ESP8266




b. Led




c. Gambar Hasilnya






d. Program Arduino IDE

//alamat kendali
//https://api.thingspeak.com/update?api_key=TTPXYPWJTOC07JYW&field2=1&field3=1&field4=0

#include "ThingSpeak.h"
#include <ESP8266WiFi.h>

//Replace your wifi credentials here
const char* ssid     = "Hotspot Wifiku";
const char* password = "123456789";

//change your channel number here
unsigned long channel = 884148;

//2,3 and 4 are channel fields in thingspeak.
unsigned int led1 = 2;
unsigned int led2 = 3;
unsigned int led3 = 4;

WiFiClient  client;


void setup() {
  Serial.begin(115200);
  delay(100);

  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);
  digitalWrite(D1, 0);
  digitalWrite(D2, 0);
  digitalWrite(D3, 0);
  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.print("Netmask: ");
  Serial.println(WiFi.subnetMask());
  Serial.print("Gateway: ");
  Serial.println(WiFi.gatewayIP());
  ThingSpeak.begin(client);

}


void loop() {

  //get the last data of the fields
  int led_1 = ThingSpeak.readFloatField(channel, led1);
  int led_2 = ThingSpeak.readFloatField(channel, led2);
  int led_3 = ThingSpeak.readFloatField(channel, led3);

  if(led_1 == 1){
    digitalWrite(D1, 1);
    Serial.println("D1 is On..!");
  }
  else if(led_1 == 0){
    digitalWrite(D1, 0);
    Serial.println("D1 is Off..!");
  }

  if(led_2 == 1){
    digitalWrite(D2, 1);
    Serial.println("D2 is On..!");
  }
  else if(led_2 == 0){
    digitalWrite(D2, 0);
    Serial.println("D2 is Off..!");
  }

  if(led_3 == 1){
    digitalWrite(D3, 1);
    Serial.println("D3 is On..!");
  }
  else if(led_3 == 0){
    digitalWrite(D3, 0);
    Serial.println("D3 is Off..!");
  }
 
  Serial.println(led_1);
  Serial.println(led_2);
  Serial.println(led_3);
  delay(5000);

}





e. Program index.php

<html>
<head>
<title>LED ON/OFF</title>
</head>
<body>

<p align="center">
<font size="8">

<b>LAMPU 1 = &nbsp <a href="https://api.thingspeak.com/update?api_key=TTPXYPWJTOC07JYW&field2=1">ON </a></b> /
<b><a href="https://api.thingspeak.com/update?api_key=TTPXYPWJTOC07JYW&field2=0">OFF</a></b>
<br>
<b>LAMPU 2 = &nbsp <a href="https://api.thingspeak.com/update?api_key=TTPXYPWJTOC07JYW&field3=1">ON </a></b> /
<b><a href="https://api.thingspeak.com/update?api_key=TTPXYPWJTOC07JYW&field3=0">OFF</a></b>
<br>
<b>LAMPU 3 = &nbsp <a href="https://api.thingspeak.com/update?api_key=TTPXYPWJTOC07JYW&field4=1">ON </a></b> /
<b><a href="https://api.thingspeak.com/update?api_key=TTPXYPWJTOC07JYW&field4=0">OFF</a></b>
<br>

</font>
</p>

</body>
</html>





f. VIDEO HASILNYA







No comments:

Post a Comment