Advertisement
andretafta

Soil_Relay + Thinger IO

Sep 6th, 2020 (edited)
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h> //Library untuk konek ke Wi-Fi
  2. #include <ThingerESP8266.h> //Library untuk terhubung ke Thinger
  3. #define USERNAME "idn8ac" //Username Thinger IO
  4. #define DEVICE_ID "MCU8C" //Device ID Thinger IO
  5. #define DEVICE_CREDENTIAL "HxvZ5Glq3HjMNh" //Device Credential
  6. #define SSID "KILLUA" //SSID Wi-Fi
  7. #define SSID_PASSWORD "nada124@" //Password Wi-Fi
  8. #define pinYL A0 //pin Analog YL-69
  9. #define WaterPump D0 //Pin Relay 1
  10.  
  11. ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
  12. //Aktifkan Fungsi Thinger IO
  13. int outputValue; //Variabel untuk Output YL-69
  14.  
  15. void setup() {
  16. pinMode(WaterPump, OUTPUT); //Set Relay 1 sebagai Output
  17. digitalWrite(WaterPump, HIGH); //Set nilai Relay 1 = 1
  18. thing.add_wifi(SSID, SSID_PASSWORD); //Mencoba terhubung ke Wi-Fi dan Thinger IO
  19.  
  20.  
  21. //Fungsi untuk Kontrol Relay 2 dengan Topik Watering
  22. thing["Watering"] << [](pson& in){
  23. if(in.is_empty()){
  24. in = (bool) digitalRead(WaterPump);
  25. }
  26. else{
  27. digitalWrite(WaterPump, in ? HIGH : LOW);
  28. }
  29. };
  30.  
  31.  
  32. //Mengirim Pembacaan Sensor YL-69 ke Thinger IO
  33. thing["Soil_Moisture"] >> [](pson& out){
  34. outputValue = analogRead(pinYL);
  35. outputValue = map(outputValue, 1024, 250, 0, 100);
  36. out["Moisture"] = outputValue;
  37. };
  38. }
  39. void loop() {
  40. //Menjalankan fungsi Thinger IO
  41. thing.handle();
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement