Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h> //Library untuk konek ke Wi-Fi
- #include <ThingerESP8266.h> //Library untuk terhubung ke Thinger
- #define USERNAME "idn8ac" //Username Thinger IO
- #define DEVICE_ID "MCU8C" //Device ID Thinger IO
- #define DEVICE_CREDENTIAL "HxvZ5Glq3HjMNh" //Device Credential
- #define SSID "KILLUA" //SSID Wi-Fi
- #define SSID_PASSWORD "nada124@" //Password Wi-Fi
- #define pinYL A0 //pin Analog YL-69
- #define WaterPump D0 //Pin Relay 1
- ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
- //Aktifkan Fungsi Thinger IO
- int outputValue; //Variabel untuk Output YL-69
- void setup() {
- pinMode(WaterPump, OUTPUT); //Set Relay 1 sebagai Output
- digitalWrite(WaterPump, HIGH); //Set nilai Relay 1 = 1
- thing.add_wifi(SSID, SSID_PASSWORD); //Mencoba terhubung ke Wi-Fi dan Thinger IO
- //Fungsi untuk Kontrol Relay 2 dengan Topik Watering
- thing["Watering"] << [](pson& in){
- if(in.is_empty()){
- in = (bool) digitalRead(WaterPump);
- }
- else{
- digitalWrite(WaterPump, in ? HIGH : LOW);
- }
- };
- //Mengirim Pembacaan Sensor YL-69 ke Thinger IO
- thing["Soil_Moisture"] >> [](pson& out){
- outputValue = analogRead(pinYL);
- outputValue = map(outputValue, 1024, 250, 0, 100);
- out["Moisture"] = outputValue;
- };
- }
- void loop() {
- //Menjalankan fungsi Thinger IO
- thing.handle();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement