산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Manufacturing Technology >> 제조공정

ARTIK + MKR1000 + DHT11 + MQTT

구성품 및 소모품

Arduino MKR1000
× 2
DHT11 온도 및 습도 센서(4핀)
× 1
LED(일반)
× 2

앱 및 온라인 서비스

Samsung ARTIK Cloud for IoT
Arduino IDE

이 프로젝트 정보

이 프로젝트는 DHT11을 센서로, LED를 메타포 액추에이터로 사용하는 두 개의 MKR1000을 사용합니다. 실제 작동기는 에어컨과 천장 선풍기일 수 있습니다. DHT11 온도 및 습도 장치는 데이터를 ARTIK 클라우드로 보냅니다. 빨간색과 노란색 LED에 명령을 보내도록 규칙이 설정되었습니다.

Arduino IDE 설정

Arduino IDE의 라이브러리 관리자를 사용하여 다음 라이브러리를 설치합니다.

WiFi101 설치(이 가이드 참조)

Joel Gaehwiler의 MQTT 설치

ArduinoJson 설치

참고:내 이전 게시물 ARTIK 클라우드 작업에 대한 세부 정보를 알아보세요.

DHT11 온도 및 습도 센서 설정

기기 유형 만들기(DHT11 센서 )

기기 연결(DHT11 센서 A1 )

물리적 장치 연결

.

ARTIK 클라우드 MQTT 매개변수 설정

<사전><코드>char mqttCloudServer[] ="api.artik.cloud"; 정수 mqttCloudPort =8883; char mqttCloudClientName[] ="ARTIK-Arduino"; char mqttCloudUsername[] ="[장치 ID]"; char mqttCloudPassword[] ="[장치 토큰]"; char mqttCloudDataOut[] ="/v1.1/메시지/[장치 ID]"; WiFiSSL클라이언트 ipCloudStack; MQTT클라이언트 mqttCloud클라이언트;

ARTIK 클라우드에 메시지 보내기.

void sendToArtikCloud(부동 온도, 부동 습도) { loadBuffer(온도, 습도); // 현재 값을 버퍼에 로드 mqttCloudClient.publish(mqttCloudDataOut, buf); } 무효 loadBuffer(부동 온도, 부유 습도) { StaticJsonBuffer<200> jsonBuffer; JsonObject&데이터 쌍 =jsonBuffer.createObject(); dataPair["온도"] =온도; dataPair["습도"] =습도; dataPair.printTo(buf, sizeof(buf)); }  

LED 온도 및 습도 액추에이터 설정

기기 유형 생성(DHT11 Actor )

기기 연결(DHT11 Actor A1 )

물리적 장치 연결

ARTIK 클라우드 MQTT 매개변수 설정

// ARTIK Cloud MQTT 매개변수 char mqttCloudServer[] ="api.artik.cloud"; 정수 mqttCloudPort =1883; char mqttCloudClientName[] ="ARTIK-Arduino"; char mqttCloudUsername[] ="[장치 ID]"; char mqttCloudPassword[] ="[장치 토큰]"; char mqttCloudActionsIn[] ="/v1.1/actions/[장치 ID]"; WiFi클라이언트 ipCloudStack; MQTT클라이언트 mqttCloud클라이언트;  

MQTT 작업을 수신합니다.

void messageReceived(String topic, String payload, char * bytes, unsigned int length) { Serial.print("topic="); Serial.println(주제); Serial.print("페이로드="); Serial.println(페이로드); Serial.print("바이트="); Serial.println(바이트); Serial.print("길이="); Serial.println(길이); parseBuffer(페이로드); }  

ARTIK 클라우드에서 작업을 구문 분석하고 처리합니다.

void parseBuffer(문자열 페이로드) { StaticJsonBuffer<200> jsonBuffer; 문자열 json =페이로드; JsonObject&루트 =jsonBuffer.parseObject(json); const char* nameparam =root["작업"][0]["이름"]; const int actionLEDRed =root["작업"][0]["매개변수"]["led_red"]; const int actionLEDYellow =루트["작업"][0]["매개변수"]["led_yellow"]; Serial.print("이름="); Serial.println(이름 매개변수); Serial.print("led_red="); Serial.println(액션LED레드); Serial.print("led_yellow="); Serial.println(액션LEDYellow); 직렬.println(); if (actionLEDRed ==1) { if (savedRedValue !=actionLEDRed) { digitalWrite(LED_RED_PIN, HIGH); 저장된적색값 =actionLEDRed; } 저장된 레드타임 =millis(); } else { if (savedRedValue !=actionLEDRed) { if (millis() - storedRedTime> RED_DELAY) { digitalWrite(LED_RED_PIN, LOW); 저장된적색값 =actionLEDRed; } } } if (actionLEDYellow ==1) { if (savedYellowValue !=actionLEDYellow) { digitalWrite(LED_YELLOW_PIN, HIGH); saveedYellowValue =actionLEDYellow; } 저장된 노란색 시간 =millis(); } else { if (savedYellowValue !=actionLEDYellow) { if (millis() - storedYellowTime> YELLOW_DELAY) { digitalWrite(LED_YELLOW_PIN, LOW); saveedYellowValue =actionLEDYellow; } } } }  

규칙 만들기

4가지 규칙이 있습니다:

<울>
  • IF DHT11 센서 A1 온도가 32도 이상, 습도가 34도 이상 그런 다음 led_red =1, led_yellow =1‌인 setValue 작업을 DHT11 Actor A1에 보냅니다.
  • <울>
  • IF DHT11 센서 A1 온도가 32도 이상, 습도가 35도 미만 그런 다음 led_red =1, led_yellow =0인 setValue 작업을 DHT11 Actor A1에 보냅니다.
  • <울>
  • IF DHT11 센서 A1 온도가 33도 미만이고 습도가 34도 이상인 경우 그런 다음 led_red =0, led_yellow =1인 setValue 작업을 DHT11 Actor A1에 보냅니다.
  • <울>
  • IF DHT11 센서 A1 습도가 35도 미만이고 온도가 33도 미만인 경우 그런 다음 led_red =0, led_yellow =0인 setValue 작업을 DHT11 Actor A1에 보냅니다.
  • 데모 비디오

    온도가 가열(LED 켜짐) 및 냉각(LED 꺼짐)될 때까지 기다려야 합니다. 빨간색 LED는 37초에 켜지고 1:13초에 꺼집니다. 데모 비디오는 온도 변화만 보여줍니다. DHT11 센서 주변의 온도를 변경하기 위해 헤어드라이어를 사용했습니다.

    .

    <섹션 클래스="섹션 컨테이너 섹션 축소 가능" id="코드">

    코드

    <울>
  • artik_dht11_sensor.ino
  • artik_led_actor.ino
  • artik_dht11_sensor.inoC/C++
    #include #include #include #include "DHT.h#define DHTPIN 2 // 어떤 디지털 핀에 연결되어 있는지#define DHTTYPE DHT11 / / DHT 11DHT dht(DHTPIN, DHTTYPE);const char* _SSID ="[Wi-Fi SSID]";const char* _PASSWORD ="[Wi-Fi 비밀번호]"; // ARTIK Cloud MQTT paramschar mqttCloudServer[] ="api.artik.cloud";int mqttCloudPort =8883;char mqttCloudClientName[] ="ARTIK-Arduino";char mqttCloudUsername[] ="[장치 ID]"; char mqttCloudPassword[] ="[장치 토큰]"; char mqttCloudDataOut[] ="/v1.1/메시지/[장치 ID]"; WiFiSSLClient ipCloudStack;MQTTClient mqttCloudClient;char buf[128];float 온도, 습도;int n =0;void getNextSample(float* 온도, float* 습도){ // 측정 사이에 몇 초 동안 기다립니다. 지연(2000); // 온도 또는 습도를 읽는 데 약 250밀리초가 걸립니다! // 센서 판독값은 최대 2초 '오래됨'(매우 느린 센서) *Humidity =dht.readHumidity(); // 온도를 섭씨로 읽습니다(기본값) *Temperature =dht.readTemperature(); // 온도를 화씨로 읽습니다. (isFahrenheit =true) // float f =dht.readTemperature(true); //printf("Temp=%.2f, Pres=%.2f, Humi=%.2f\n", Temp_c__f, Pres_hPa__f, Humi_pct__f); Serial.print("온도="); Serial.println(*온도); Serial.print("습도="); Serial.println(*습도);} 무효 설정() { Serial.begin(57600); dht.begin(); // 와이파이 설정 WiFi.begin(_SSID, _PASSWORD); 동안 (WiFi.status() !=WL_CONNECTED) { 지연(500); Serial.print("."); } 직렬.println(); Serial.println("와이파이 연결됨"); Serial.print("IP 주소:"); Serial.println(WiFi.localIP()); mqttCloudClient.begin(mqttCloudServer, mqttCloudPort, ipCloudStack); Serial.println("ARTIK 클라우드 연결 시작"); 직렬.println(); 동안 (!mqttCloudClient.connect(mqttCloudClientName, mqttCloudUsername, mqttCloudPassword)) { Serial.print("*"); 지연(500); }}void messageReceived(문자열 주제, 문자열 페이로드, char * 바이트, 부호 없는 정수 길이) {}void sendToArtikCloud(부동 온도, 부동 습도) { loadBuffer(온도, 습도); // 현재 값을 버퍼에 로드 mqttCloudClient.publish(mqttCloudDataOut, buf);}void loadBuffer(float temperature, float 습도) { StaticJsonBuffer<200> jsonBuffer; JsonObject&데이터 쌍 =jsonBuffer.createObject(); dataPair["온도"] =온도; dataPair["습도"] =습도; dataPair.printTo(buf, sizeof(buf));} 무효 루프() { if (++n> 10) { Serial.println("중지됨."); 출구(0); } mqttCloudClient.loop(); 지연(1000); getNextSample(&온도, 습도); Serial.println("출시 중..."); 직렬.println(); sendToArtikCloud(온도, 습도); 지연(15000);}
    artik_led_actor.inoC/C++
    #include #include #include #define LED_RED_PIN 11#define LED_YELLOW_PIN 13#define RED_DELAY 5000#define YELLOW_DELAY 10000WiFi_SID ="[WiFi_SID char* ]";const char* _PASSWORD ="[Wi-Fi 비밀번호]"; // ARTIK Cloud MQTT paramschar mqttCloudServer[] ="api.artik.cloud";int mqttCloudPort =1883;char mqttCloudClientName[] ="ARTIK-Arduino";char mqttCloudUsername[] ="[장치 ID]"; char mqttCloudPassword[] ="[장치 토큰]"; char mqttCloudActionsIn[] ="/v1.1/actions/[장치 ID]"; WiFiClient ipCloudStack;MQTTClient mqttCloudClient;char buf[128];int storedRedValue, storedYellowValue;unsigned long storedRedTime, storedYellowTime;void setup() { Serial.begin(57600); 핀모드(LED_RED_PIN, 출력); 핀모드(LED_YELLOW_PIN, 출력); 저장된적색값 =저장됨황색값 =0; // 와이파이 설정 WiFi.begin(_SSID, _PASSWORD); 동안 (WiFi.status() !=WL_CONNECTED) { 지연(500); Serial.print("."); } 직렬.println(); Serial.println("와이파이 연결됨"); Serial.print("IP 주소:"); Serial.println(WiFi.localIP()); mqttCloudClient.begin(mqttCloudServer, mqttCloudPort, ipCloudStack); Serial.println("ARTIK 클라우드 연결 시작"); 직렬.println(); 동안 (!mqttCloudClient.connect(mqttCloudClientName, mqttCloudUsername, mqttCloudPassword)) { Serial.print("*"); 지연(500); } mqttCloudClient.subscribe(mqttCloudActionsIn);} 무효 messageReceived(문자열 주제, 문자열 페이로드, char * 바이트, 부호 없는 정수 길이) { Serial.print("topic="); Serial.println(주제); Serial.print("페이로드="); Serial.println(페이로드); Serial.print("바이트="); Serial.println(바이트); Serial.print("길이="); Serial.println(길이); parseBuffer(페이로드);} 무효 parseBuffer(문자열 페이로드) { StaticJsonBuffer<200> jsonBuffer; 문자열 json =페이로드; JsonObject&루트 =jsonBuffer.parseObject(json); const char* nameparam =root["작업"][0]["이름"]; const int actionLEDRed =root["작업"][0]["매개변수"]["led_red"]; const int actionLEDYellow =루트["작업"][0]["매개변수"]["led_yellow"]; Serial.print("이름="); Serial.println(이름 매개변수); Serial.print("led_red="); Serial.println(액션LED레드); Serial.print("led_yellow="); Serial.println(actionLEDYellow); 직렬.println(); if (actionLEDRed ==1) { if (savedRedValue !=actionLEDRed) { digitalWrite(LED_RED_PIN, HIGH); 저장된적색값 =actionLEDRed; } 저장된 레드타임 =millis(); } else { if (savedRedValue !=actionLEDRed) { if (millis() - storedRedTime> RED_DELAY) { digitalWrite(LED_RED_PIN, LOW); 저장된적색값 =actionLEDRed; } } } if (actionLEDYellow ==1) { if (savedYellowValue !=actionLEDYellow) { digitalWrite(LED_YELLOW_PIN, HIGH); saveedYellowValue =actionLEDYellow; } 저장된 노란색 시간 =millis(); } else { if (savedYellowValue !=actionLEDYellow) { if (millis() - storedYellowTime> YELLOW_DELAY) { digitalWrite(LED_YELLOW_PIN, LOW); saveedYellowValue =actionLEDYellow; } } } } 무효 루프() { mqttCloudClient.loop(); 지연(500); }

    제조공정

    1. DHT11 센서(LED 및 피에조 스피커 포함)
    2. Arduino 스파이봇
    3. FlickMote
    4. 수제 TV B-Gone
    5. 마스터 시계
    6. 나를 찾기
    7. Arduino Power
    8. Tech-TicTacToe
    9. Arduino Quadruped
    10. Mkr1000 핀아웃:IoT 프로젝트에 선호되는 선택