Tutorial ESP8266 tipe NodeMCU atau Wemos D1 Mini kontrol relay via internet dan firebase. Disini saya akan menjelaskan lengkap mulai dari cara menggunakan modul ESP8266 pada software Arduino IDE, sampai mengoperasikan modul ESP8266 untuk bisa menyalakan dan mematikan lampu dengan android. Komunikasi yang digunakan adalah internet dan tempat penyimpanan datanya adalah firebase.
Tutorial ini bisa menggunakan berbagai jenis board esp8266 seperti NodeMCU dan Wemos D1 Mini, maka saya akan tuliskan kata kunci disini juga tentang Wemos Kontrol Relay Firebase dan NodeMCu Kontrol Relay Firebase. Belajar IoT dengan Wemos atau Tutorial IoT dengan NodeMCU ESP82666.
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Jenis Board ESP yang Digunakan | Pilihan Board Pada Arduino IDE |
ESP8266 ESP-01 | Generic ESP8266 Module |
NodeMCU Lolin V3 | NodeMCU 1.0 (ESP – 12E Module |
NodeMCU Lua | NodeMCU 1.0 (ESP – 12E Module |
Wemos D1 Mini | Wemos D1 Mini Pro / Wemos D1 R2 & mini |
void setup() { // put your setup code here, to run once: pinMode (2, OUTPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(2, HIGH); delay(1000); digitalWrite(2, LOW); delay(1000); }
// // Copyright 2015 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // FirebaseDemo_ESP8266 is a sample that demo the different functions // of the FirebaseArduino API. #include <ESP8266WiFi.h> #include <FirebaseArduino.h> // Set these to run example. #define FIREBASE_HOST "kontrol-relay-45cd4.firebaseio.com" #define FIREBASE_AUTH "bM3t6vIacd5sx0RTSZo17dBaj44TmihqL6AfruwV" #define WIFI_SSID "anakkendali.com" #define WIFI_PASSWORD "bayardikitlimangewu" void setup() { Serial.begin(9600); // connect to wifi. WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("connecting"); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } Serial.println(); Serial.print("connected: "); Serial.println(WiFi.localIP()); Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); } int n = 0; void loop() { // set value Firebase.setFloat("number", 42.0); // handle error if (Firebase.failed()) { Serial.print("setting /number failed:"); Serial.println(Firebase.error()); return; } delay(1000); // update value Firebase.setFloat("number", 43.0); // handle error if (Firebase.failed()) { Serial.print("setting /number failed:"); Serial.println(Firebase.error()); return; } delay(1000); // get value Serial.print("number: "); Serial.println(Firebase.getFloat("number")); delay(1000); // remove value Firebase.remove("number"); delay(1000); // set string value Firebase.setString("message", "hello world"); // handle error if (Firebase.failed()) { Serial.print("setting /message failed:"); Serial.println(Firebase.error()); return; } delay(1000); // set bool value Firebase.setBool("truth", false); // handle error if (Firebase.failed()) { Serial.print("setting /truth failed:"); Serial.println(Firebase.error()); return; } delay(1000); // append a new value to /logs String name = Firebase.pushInt("logs", n++); // handle error if (Firebase.failed()) { Serial.print("pushing /logs failed:"); Serial.println(Firebase.error()); return; } Serial.print("pushed: /logs/"); Serial.println(name); delay(1000); }
// // Copyright 2015 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // FirebaseDemo_ESP8266 is a sample that demo the different functions // of the FirebaseArduino API. #include <ESP8266WiFi.h> #include <FirebaseArduino.h> // Set these to run example. #define FIREBASE_HOST "kontrol-relay-45cd4.firebaseio.com" #define FIREBASE_AUTH "bM3t6vIacd5sx0RTSZo17dBaj44TmihqL6AfruwV" #define WIFI_SSID "anakkendali.com" #define WIFI_PASSWORD "bayardikitlimangewu" void setup() { Serial.begin(9600); // connect to wifi. WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("connecting"); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } Serial.println(); Serial.print("connected: "); Serial.println(WiFi.localIP()); Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); pinMode (D3, OUTPUT); } int n = 0; void loop() { int val = Firebase.getInt("relay"); Serial.print("Relay: "); Serial.println(val); digitalWrite(D3, val); delay(1000); }
Cukup sekian apa yang bisa saya bagikan kali ini, semoga bermanfaat dan jangan lupa untuk membagikan artikel ini pada teman kalian.
Pendahuluan Dalam dunia pengembangan perangkat lunak yang terus berkembang, Kubernetes telah muncul sebagai alat kunci dalam orkestrasi…
Mengelola sebuah sekolah atau lembaga pendidikan adalah tugas yang kompleks dan penuh tantangan. Dengan berbagai…
Selamat datang di artikel kami tentang cara menginstal OpenVPN server di Ubuntu 20.04 di HuaweiCloud!…
Dalam dunia pengembangan aplikasi, salah satu hal yang menjadi penting adalah mengelola dan memonitor kontainer…
Tutorial led blinking. LED (Light Emitting Diode) merupakan salah satu komponen elektronik yang paling umum…
Tutorial LCD Display, ini merupakan salah satu komponen yang sering digunakan dalam project elektronika sebagai…