Kamis, 11 Mei 2023

Membuat project di arduino iot cloud dengan esp32

 1. pilih IoT Cloud





2. Create Thing


3. ketik nama project "kontrol lampu", kemudian klik add variable



4. isi  seperti bawah ini dan klik add variable





5. klik selec device



6. Set up new device


7. set up 3rd party device



8. pilih esp32 - dev module



9. ketik nama device "SIMOR"



10. catat secret key dan centang lalu  klik continue



11. done



12. set wifi, klik configure dibawah network



13. ketik nama wifi, password, dan secret key yangdi dapatkan tadi, klik done



14.  pilih dashboard dan build 



15. ketik nama dashboard kemudian klik add



16. pilih switch



17.  ketik nama widget dan link kan ke variable lampu



18. pilih thing - variable lalu klik link variable



19.  pilih thing kemudian sketch



20. full sketch

  1. /* 
  2.   Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  3.   https://create.arduino.cc/cloud/things/3be0b915-d944-4d3e-bef2-732c82d105e3 
  4.   Arduino IoT Cloud Variables description
  5.   The following variables are automatically generated and updated when changes are made to the Thing
  6.   bool lampu;
  7.   Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  8.   which are called when their values are changed from the Dashboard.
  9.   These functions are generated with the Thing and added at the end of this sketch.
  10. */
  11. #include "thingProperties.h"
  12. #define relay 2 //setting pin kontrol
  13. void setup() {
  14.   // Initialize serial and wait for port to open:
  15.   Serial.begin(9600);
  16.   
  17.   pinMode(relay,OUTPUT);
  18.   // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  19.   delay(1500); 
  20.   // Defined in thingProperties.h
  21.   initProperties();
  22.   // Connect to Arduino IoT Cloud
  23.   ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  24.   
  25.   /*
  26.      The following function allows you to obtain more information
  27.      related to the state of network and IoT Cloud connection and errors
  28.      the higher number the more granular information you’ll get.
  29.      The default is 0 (only errors).
  30.      Maximum is 4
  31.  */
  32.   setDebugMessageLevel(2);
  33.   ArduinoCloud.printDebugInfo();
  34. }
  35. void loop() {
  36.   ArduinoCloud.update();
  37.   // Your code here 
  38.   
  39.   
  40. }
  41. /*
  42.   Since Lampu is READ_WRITE variable, onLampuChange() is
  43.   executed every time a new value is received from IoT Cloud.
  44. */
  45. void onLampuChange()  {
  46.   // Add your code here to act upon Lampu change
  47.   if (lampu==1)
  48.  {
  49. digitalWrite(relay,HIGH); // update this pin if your led is connected with another gpio
  50.  }
  51. if (lampu==0)
  52.  {
  53. digitalWrite(relay,LOW);
  54.  }

  55. }

yang tambahan hanya warna merah

21. upload


22. tunggu sampai selesai sambil minum kopi 









Tidak ada komentar:

Posting Komentar

Cara membuat datalogger blynk di spreadsheet / googlesheet menggunakan akun versi Free

  silahkan video di atas. semoga bermanfaat. jika masih kurang jelas bisa kontak saya