12주차 스마트디바이스(Arduino Cloud 실습) - jungjaeyeol/jyeol03 GitHub Wiki

🌐 아두이노 클라우드(Arduino Cloud) 특징

🔹 1. IoT 기기 원격 제어 및 모니터링

  • 전 세계 어디서든 인터넷을 통해 장치 상태 확인 및 제어 가능

  • 예: 온도 센서 데이터 실시간 확인, LED 원격 ON/OFF 등

🔹 2. 다양한 기기 지원

  • 아두이노 공식 보드 외에도 ESP32, ESP8266 등 다양한 보드 호환

  • 라즈베리파이(Raspberry Pi)와도 연동 가능

🔹 3. 사용자 친화적 대시보드

  • 드래그 앤 드롭 방식으로 대시보드 구성

  • 슬라이더, 토글, 그래프 등을 쉽게 추가 가능

🔹 4. 자동 동기화 기능 (Sketch Sync)

  • 웹 에디터에서 작성한 코드 자동 저장 및 장치에 반영

🔹 5. IFTTT 및 Alexa 연동

  • "만약 ○○이면 ○○하라" 식의 자동화 설정 가능

  • 음성 인식 장치(Alexa)를 통한 제어도 가능

🔹 6. 보안 및 데이터 저장

  • SSL 암호화를 통한 안전한 데이터 전송

  • 데이터 로그 기록 및 과거 데이터 확인 가능

🔹 7. Arduino IoT Remote 앱 지원

  • 모바일 앱으로도 대시보드 접근 및 제어 가능

🔹 8. 클라우드 기반 펌웨어 업데이트

  • 원격으로 펌웨어 업그레이드 가능 (물리적 연결 불필요)

🌐 Arduino Cloud 실습

  • 하드웨어

  • 실습 코드
/* 이코드는 아두이노 IDE에서 컴파일 되지 않습니다.
  아두이노 IoT 클라우드에서 사용하시기 바랍니다. 
  https://create.arduino.cc/iot/things
*/
/*
  Sketch generated by the Arduino IoT Cloud Thing "ESP32"
  https://create.arduino.cc/cloud/things/cbf5bb30-7317-45b9-8559-d0d766bf6942

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float temperature;
  bool led_state;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#include "DHT.h"

int led_pin = 23;
int dh11_pin = 13;

DHT dht(dh11_pin, DHT11);

void setup() {
  pinMode(led_pin, OUTPUT);
  dht.begin();
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
  */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here
  // Read temperature as Celsius (the default)
  temperature = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(temperature)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  
  Serial.print(F("Temperature: "));
  Serial.println(temperature);
  
  delay(1000);
}

/*
  Since LedState is READ_WRITE variable, onLedStateChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onLedStateChange()  {
  // Add your code here to act upon LedState change
  Serial.print("LED state is changed : ");
  Serial.println(led_state);
  if (led_state) {
    digitalWrite(led_pin, HIGH);
  }
  else {
    digitalWrite(led_pin, LOW);
  }
}
  • Arduino Cloud 접속 후 회원가입
  • 회원가입 후 Things 클릭 후 프로젝트 이름 설정하

  • ADD 클릭 후 위 사진 처럼 설정하기
  • Associated Device Section 에서 Select Device 클릭, Third party device에서 ESP32, DOIT ESP32 DEVKIT V1 선택 후 이름 설정 하고 Device ID 와 Security Key 메모하기.
  • Network Section에서 네트워크 이름, 암호, Security Key 입력 후 저장
  • DashBoards > Sketch 에 들어가서 실습 코드 입력 후 Edit 클릭 후 ADD로 Switch, Chart 추가하고 연결하기

실습 결과

https://github.com/user-attachments/assets/791384dd-fdc9-4374-8639-30084e6aac29

  • Switch를 On 하면 Led가 켜지고 Off 하면 꺼지는 모습을 볼 수 있다.
  • Chart는 온도에 따라서 실시간으로 그래프가 움직이는걸 볼 수 있다.

느낀점

  • 이번 실습을 통해서 Arduino 앱에서 만에서 할 수 있는것이 아닌, Arduino Cloud 에서도 실습을 할 수 있다는걸 알게되었고 오히려 Arduino Cloud가 더 괜찮고 편하다고 생각하였다.

주의사항

  • 이번 실습도 마찬가지로 핫스팟을 ESP32랑 연결해야된다
  • Arduino Cloud Agent를 다운받지 않으면 실습인 진행이 되지 않는걸 확인하였다 (다운 받고 연결되었는지 확인하기)