Manufaktur industri
Industri Internet of Things | bahan industri | Pemeliharaan dan Perbaikan Peralatan | Pemrograman industri |
home  MfgRobots >> Manufaktur industri >  >> Manufacturing Technology >> Proses manufaktur

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Komponen dan Perlengkapan

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud
Arduino MKR1000
× 2
Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud
DHT11 Temperature & Humidity Sensor (4 pins)
× 1
Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud
LED (generic)
× 2

Aplikasi dan Layanan Online

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud
Samsung ARTIK Cloud for IoT
Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud
Arduino IDE

Tentang Proyek Ini

Proyek ini menggunakan dua MKR1000 dengan DHT11 sebagai sensor dan LED sebagai aktor metafora. Aktor nyata bisa menjadi pendingin udara dan kipas langit-langit. Perangkat suhu dan kelembaban DHT11 mengirim data ke ARTIK cloud. Aturan telah diatur untuk mengirim perintah ke LED Merah dan Kuning.

Pengaturan Arduino IDE

Dengan Library Manager Arduino IDE, instal library berikut.

Instal WiFi101 (lihat panduan ini)

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Instal MQTT oleh Joel Gaehwiler

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Instal ArduinoJson

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Catatan: Lihat postingan sebelumnya saya untuk mengetahui detail tentang bekerja dengan ARTIK cloud.

Pengaturan sensor suhu dan kelembaban DHT11

Buat jenis perangkat (Sensor DHT11)

Hubungkan perangkat (Sensor DHT11 A1)

Hubungkan perangkat fisik

.

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Pengaturan parameter MQTT ARTIK cloud

char mqttCloudServer[] = "api.artik.cloud"; int mqttCloudPort = 8883; char mqttCloudClientName[] = "ARTIK-Arduino"; char mqttCloudUsername[] = "[device-id]"; char mqttCloudPassword[] = "[device-token]"; char mqttCloudDataOut[] = "/v1.1/messages/[device-id]"; WiFiSSLClient ipCloudStack; MQTTClient mqttCloudClient; 

Mengirim pesan ke ARTIK cloud.

void sendToArtikCloud(float temperature, float humidity) { loadBuffer(temperature, humidity); // muat nilai saat ini ke buffer mqttCloudClient.publish(mqttCloudDataOut, buf); } void loadBuffer(float temperature, float humidity) { StaticJsonBuffer<200> jsonBuffer; JsonObject& dataPair = jsonBuffer.createObject(); dataPair["temperature"] = temperature; dataPair["humidity"] = humidity; dataPair.printTo(buf, sizeof(buf)); } 

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Pengaturan aktuator suhu dan kelembaban LED

Buat jenis perangkat (Aktor DHT11)

Hubungkan perangkat (Aktor DHT11 A1)

Hubungkan perangkat fisik

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Pengaturan parameter MQTT ARTIK cloud

// PARAMETER MQTT ARTIK Cloud char mqttCloudServer[] = "api.artik.cloud"; int mqttCloudPort = 1883; char mqttCloudClientName[] = "ARTIK-Arduino"; char mqttCloudUsername[] = "[device-id]"; char mqttCloudPassword[] = "[device-token]"; char mqttCloudActionsIn[] = "/v1.1/actions/[device-id]"; WiFiClient ipCloudStack; MQTTClient mqttCloudClient; 

Menerima tindakan MQTT.

void messageReceived(String topic, String payload, char * bytes, unsigned int length) { Serial.print("topic="); Serial.println(topic); Serial.print("payload="); Serial.println(payload); Serial.print("bytes="); Serial.println(bytes); Serial.print("length="); Serial.println(length); parseBuffer(payload); } 

Uraikan dan proses tindakan dari ARTIK cloud.

void parseBuffer(String payload) { StaticJsonBuffer<200> jsonBuffer; String json = payload; JsonObject& root = jsonBuffer.parseObject(json); const char* nameparam = root["actions"][0]["name"]; const int actionLEDRed = root["actions"][0]["parameters"]["led_red"]; const int actionLEDYellow = root["actions"][0]["parameters"]["led_yellow"]; Serial.print("name="); Serial.println(nameparam); Serial.print("led_red="); Serial.println(actionLEDRed); Serial.print("led_yellow="); Serial.println(actionLEDYellow); Serial.println(); if (actionLEDRed == 1) { if (savedRedValue != actionLEDRed) { digitalWrite(LED_RED_PIN, HIGH); savedRedValue = actionLEDRed; } savedRedTime = millis(); } else { if (savedRedValue != actionLEDRed) { if (millis() - savedRedTime > RED_DELAY) { digitalWrite(LED_RED_PIN, LOW); savedRedValue = actionLEDRed; } } } if (actionLEDYellow == 1) { if (savedYellowValue != actionLEDYellow) { digitalWrite(LED_YELLOW_PIN, HIGH); savedYellowValue = actionLEDYellow; } savedYellowTime = millis(); } else { if (savedYellowValue != actionLEDYellow) { if (millis() - savedYellowTime > YELLOW_DELAY) { digitalWrite(LED_YELLOW_PIN, LOW); savedYellowValue = actionLEDYellow; } } } } 

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Buat Aturan

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Ada 4 aturan:

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Video Demo

Perhatikan bahwa Anda perlu menunggu suhu panas (LED menyala) dan mendingin (LED mati). LED merah menyala pada detik ke 37 dan mati pada 1:13 detik. Video demo hanya menunjukkan perubahan suhu. Saya menggunakan pengering rambut untuk mengubah suhu di sekitar sensor DHT11.

.

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Arduino MKR1000 + Sensor DHT11: Demo IoT MQTT di Samsung ARTIK Cloud

Kode

artik_dht11_sensor.inoC/C++
#include <MQTTClient.h> #include <ArduinoJson.h> #include <WiFi101.h> #include "DHT.h" #define DHTPIN 2 // pin digital mana kita terhubung #define DHTTYPE DHT11 // DHT 11 DHT dht(DHTPIN, DHTTYPE); const char* _SSID = "[Wi-Fi SSID]"; const char* _PASSWORD = "[Wi-Fi Password]"; // PARAMETER MQTT ARTIK Cloud char mqttCloudServer[] = "api.artik.cloud"; int mqttCloudPort = 8883; char mqttCloudClientName[] = "ARTIK-Arduino"; char mqttCloudUsername[] = "[device-id]"; char mqttCloudPassword[] = "[device-token]"; char mqttCloudDataOut[] = "/v1.1/messages/[device-id]"; WiFiSSLClient ipCloudStack; MQTTClient mqttCloudClient; char buf[128]; float temperature, humidity; int n = 0; void getNextSample(float* Temperature, float* Humidity) { // Tunggu beberapa detik antara pengukuran. delay(2000); // Membaca suhu atau kelembaban memakan waktu sekitar 250 milidetik! // Pembacaan sensor mungkin juga 'lama' hingga 2 detik (sensor sangat lambat) *Humidity = dht.readHumidity(); // Baca suhu dalam Celsius (default) *Temperature = dht.readTemperature(); // Baca suhu dalam Fahrenheit (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("Temperature="); Serial.println(*Temperature); Serial.print("Humidity="); Serial.println(*Humidity); } void setup() { Serial.begin(57600); dht.begin(); // Pengaturan WiFi WiFi.begin(_SSID, _PASSWORD); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); Serial.println("WiFi connected"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); mqttCloudClient.begin(mqttCloudServer, mqttCloudPort, ipCloudStack); Serial.println("start ARTIK Cloud connect"); Serial.println(); while (!mqttCloudClient.connect(mqttCloudClientName, mqttCloudUsername, mqttCloudPassword)) { Serial.print("*"); delay(500); } } void messageReceived(String topic, String payload, char * bytes, unsigned int length) {} void sendToArtikCloud(float temperature, float humidity) { loadBuffer(temperature, humidity); // muat nilai saat ini ke buffer mqttCloudClient.publish(mqttCloudDataOut, buf); } void loadBuffer(float temperature, float humidity) { StaticJsonBuffer<200> jsonBuffer; JsonObject& dataPair = jsonBuffer.createObject(); dataPair["temperature"] = temperature; dataPair["humidity"] = humidity; dataPair.printTo(buf, sizeof(buf)); } void loop() { if (++n > 10) { Serial.println("Stopped."); exit(0); } mqttCloudClient.loop(); delay(1000); getNextSample(&temperature, &humidity); Serial.println("Publishing..."); Serial.println(); sendToArtikCloud(temperature, humidity); delay(15000); } 
artik_led_actor.inoC/C++
#include <MQTTClient.h> #include <ArduinoJson.h> #include <WiFi101.h> #define LED_RED_PIN 11 #define LED_YELLOW_PIN 13 #define RED_DELAY 5000 #define YELLOW_DELAY 10000 const char* _SSID = "[Wi-Fi SSID]"; const char* _PASSWORD = "[Wi-Fi Password]"; // PARAMETER MQTT ARTIK Cloud char mqttCloudServer[] = "api.artik.cloud"; int mqttCloudPort = 1883; char mqttCloudClientName[] = "ARTIK-Arduino"; char mqttCloudUsername[] = "[device-id]"; char mqttCloudPassword[] = "[device-token]"; char mqttCloudActionsIn[] = "/v1.1/actions/[device-id]"; WiFiClient ipCloudStack; MQTTClient mqttCloudClient; char buf[128]; int savedRedValue, savedYellowValue; unsigned long savedRedTime, savedYellowTime; void setup() { Serial.begin(57600); pinMode(LED_RED_PIN, OUTPUT); pinMode(LED_YELLOW_PIN, OUTPUT); savedRedValue = savedYellowValue = 0; // Pengaturan WiFi WiFi.begin(_SSID, _PASSWORD); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); Serial.println("WiFi connected"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); mqttCloudClient.begin(mqttCloudServer, mqttCloudPort, ipCloudStack); Serial.println("start ARTIK Cloud connect"); Serial.println(); while (!mqttCloudClient.connect(mqttCloudClientName, mqttCloudUsername, mqttCloudPassword)) { Serial.print("*"); delay(500); } mqttCloudClient.subscribe(mqttCloudActionsIn); } void messageReceived(String topic, String payload, char * bytes, unsigned int length) { Serial.print("topic="); Serial.println(topic); Serial.print("payload="); Serial.println(payload); Serial.print("bytes="); Serial.println(bytes); Serial.print("length="); Serial.println(length); parseBuffer(payload); } void parseBuffer(String payload) { StaticJsonBuffer<200> jsonBuffer; String json = payload; JsonObject& root = jsonBuffer.parseObject(json); const char* nameparam = root["actions"][0]["name"]; const int actionLEDRed = root["actions"][0]["parameters"]["led_red"]; const int actionLEDYellow = root["actions"][0]["parameters"]["led_yellow"]; Serial.print("name="); Serial.println(nameparam); Serial.print("led_red="); Serial.println(actionLEDRed); Serial.print("led_yellow="); Serial.println(actionLEDYellow); Serial.println(); if (actionLEDRed == 1) { if (savedRedValue != actionLEDRed) { digitalWrite(LED_RED_PIN, HIGH); savedRedValue = actionLEDRed; } savedRedTime = millis(); } else { if (savedRedValue != actionLEDRed) { if (millis() - savedRedTime > RED_DELAY) { digitalWrite(LED_RED_PIN, LOW); savedRedValue = actionLEDRed; } } } if (actionLEDYellow == 1) { if (savedYellowValue != actionLEDYellow) { digitalWrite(LED_YELLOW_PIN, HIGH); savedYellowValue = actionLEDYellow; } savedYellowTime = millis(); } else { if (savedYellowValue != actionLEDYellow) { if (millis() - savedYellowTime > YELLOW_DELAY) { digitalWrite(LED_YELLOW_PIN, LOW); savedYellowValue = actionLEDYellow; } } } } void loop() { mqttCloudClient.loop(); delay(500); } 

Proses manufaktur

  1. Proyek Sensor Suhu & Kelembaban DHT11 dengan Indikator LED dan Speaker Piezo
  2. Membuat Spybot Arduino yang Dikontrol melalui Bluetooth
  3. FlickMote: Remote IR Kendali Gestur untuk Rumah Cerdas
  4. DIY Arduino TV B-Gone: Remote Universal untuk Semua TV
  5. Bangun Jam Master LED Kustom dengan Alarm – Terlihat dari Jarak 12 Meter
  6. Find Me: Pelacak Item Cerdas dengan Arduino dan Bluetooth
  7. Solusi Daya Teroptimasi untuk Proyek Arduino
  8. Tic Tac Toe Arduino dengan Matriks LED MAX7219 dan Kotak Kardus
  9. Membuat Robot Quadruped Arduino Cerdas: Panduan Langkah demi Langkah
  10. Pinout MKR1000 Dijelaskan: Papan Andalan untuk Pengembangan IoT