Industriële fabricage
Industrieel internet der dingen | Industriële materialen | Onderhoud en reparatie van apparatuur | Industriële programmering |
home  MfgRobots >> Industriële fabricage >  >> Manufacturing Technology >> Productieproces

ARTIK + MKR1000 + DHT11 + MQTT

Componenten en benodigdheden

Arduino MKR1000
× 2
DHT11 temperatuur- en vochtigheidssensor (4 pinnen)
× 1
LED (generiek)
× 2

Apps en online services

Samsung ARTIK Cloud voor IoT
Arduino IDE

Over dit project

Dit project maakt gebruik van twee MKR1000's met DHT11 als sensor en LED's als metafooractoren. De echte actuatoren kunnen de airconditioning en de plafondventilator zijn. Het DHT11-apparaat voor temperatuur en vochtigheid stuurt gegevens naar de ARTIK-cloud. Er zijn regels ingesteld om commando's naar de rode en gele LED's te sturen.

Arduino IDE instellen

Installeer met Arduino IDE's Library Manager de volgende bibliotheken.

Installeer WiFi101 (zie deze handleiding)

Installeer MQTT door Joel Gaehwiler

ArduinoJson installeren

Opmerking:raadpleeg mijn eerder bericht voor meer informatie over het werken met ARTIK cloud.

Stel de DHT11 temperatuur- en vochtigheidssensor in

Maak een apparaattype aan (DHT11-sensor )

Sluit een apparaat aan (DHT11-sensor A1 )

Verbind de fysieke apparaten

.

Stel de ARTIK cloud MQTT-parameters in

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

Berichten verzenden naar ARTIK cloud.

void sendToArtikCloud(float temperatuur, float vochtigheid) { loadBuffer(temperatuur, vochtigheid); // laad huidige waarden in de buffer mqttCloudClient.publish (mqttCloudDataOut, buf); } void loadBuffer (float-temperatuur, float-vochtigheid) { StaticJsonBuffer<200> jsonBuffer; JsonObject&dataPair =jsonBuffer.createObject(); dataPair["temperatuur"] =temperatuur; dataPair["vochtigheid"] =vochtigheid; dataPair.printTo(buf, sizeof(buf)); }  

Stel de LED-temperatuur- en vochtigheidsactuatoren in

Maak een apparaattype (DHT11 Actor )

Sluit een apparaat aan (DHT11 Actor A1 )

Verbind de fysieke apparaten

ARTIK cloud MQTT-parameters instellen

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

MQTT-acties ontvangen.

void messageReceived(String topic, String payload, char * bytes, unsigned int length) { Serial.print("topic="); Serial.println(onderwerp); Serial.print("payload="); Serial.println(lading); Serieel.print("bytes="); Serieel.println(bytes); Serieel.print("length="); Serial.println(lengte); ontledenBuffer (lading); }  

Parseer en verwerk de acties van ARTIK cloud.

void parseBuffer(String-payload) { StaticJsonBuffer<200> jsonBuffer; String json =lading; JsonObject&root =jsonBuffer.parseObject(json); const char* nameparam =root["acties"][0]["naam"]; const int actionLEDRed =root["actions"][0]["parameters"]["led_red"]; const int actionLEDYellow =root["actions"][0]["parameters"]["led_yellow"]; Serial.print("naam="); Serial.println(naamparam); Serial.print("led_red="); Serial.println(actionLEDRed); Serial.print("led_yellow="); Serial.println(actionLEDYellow); Serieel.println(); if (actionLEDRed ==1) {if (savedRedValue!=actionLEDRed) {digitalWrite(LED_RED_PIN, HIGH); saveRedValue =actionLEDRed; } saveRedTime =millis(); } else {if (savedRedValue!=actionLEDRed) {if (millis() - savedRedTime> RED_DELAY) {digitalWrite(LED_RED_PIN, LOW); saveRedValue =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; } } } }  

Regels maken

Er zijn 4 regels:

  • IF DHT11 Sensor A1 temperatuur is meer dan 32 en vochtigheid is meer dan 34 DAN stuur naar DHT11 Actor A1 de actie setValue met led_red =1, led_yellow =1‌
  • IF DHT11 Sensor A1 temperatuur is meer dan 32 en vochtigheid is minder dan 35 DAN stuur naar DHT11 Actor A1 de actie setValue met led_red =1, led_yellow =0‌
  • ALS DHT11 Sensor A1 temperatuur lager is dan 33 en vochtigheid hoger is dan 34 DAN stuur naar DHT11 Actor A1 de actie setValue met led_red =0, led_yellow =1
  • ALS DHT11 Sensor A1 vochtigheid lager is dan 35 en temperatuur lager is dan 33 DAN stuur naar DHT11 Actor A1 de actie setValue met led_red =0, led_yellow =0‌

Demovideo

Houd er rekening mee dat u moet wachten tot de temperatuur is opgewarmd (LED aan) en afgekoeld (LED uit). De rode LED gaat aan na 37 seconden en gaat uit na 1:13 seconden. De demovideo toont alleen temperatuurveranderingen. Ik heb een föhn gebruikt om de temperatuur rond de DHT11-sensor te veranderen.

.

Code

  • artik_dht11_sensor.ino
  • artik_led_actor.ino
artik_dht11_sensor.inoC/C++
#include #include #include #include "DHT.h"#define DHTPIN 2 // met welke digitale pin we zijn verbonden#define DHTTYPE DHT11 / / DHT 11DHT dht(DHTPIN, DHTTYPE);const char* _SSID ="[Wi-Fi SSID]";const char* _PASSWORD ="[Wi-Fi-wachtwoord]"; // ARTIK Cloud MQTT paramschar mqttCloudServer[] ="api.artik.cloud";int mqttCloudPort =8883;char mqttCloudClientName[] ="ARTIK-Arduino";char mqttCloudUsername[] ="[apparaat-id]"; char mqttCloudPassword[] ="[apparaat-token]"; char mqttCloudDataOut[] ="/v1.1/messages/[apparaat-id]"; WiFiSSSLient ipCloudStack;MQTTClient mqttCloudClient;char buf[128];float temperatuur, vochtigheid;int n =0;void getNextSample(float* Temperature, float* Humidity){ // Wacht een paar seconden tussen metingen. vertraging (2000); // Het lezen van temperatuur of vochtigheid duurt ongeveer 250 milliseconden! // Sensormetingen kunnen ook tot 2 seconden 'oud' zijn (het is een zeer trage sensor) *Vochtigheid =dht.readHumidity(); // Lees temperatuur als Celsius (de standaardinstelling) *Temperature =dht.readTemperature(); // Lees temperatuur als 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("Temperatuur="); Serial.println(*Temperatuur); Serial.print("Vochtigheid="); Serial.println(*Vochtigheid);}void setup() {Serial.begin(57600); dht.begin(); // Wifi-instelling WiFi.begin (_SSID, _PASSWORD); while (WiFi.status() !=WL_CONNECTED) { delay(500); Serieel.print("."); } Serieel.println(); Serial.println("WiFi verbonden"); Serial.print("IP-adres:"); Serial.println(WiFi.localIP()); mqttCloudClient.begin(mqttCloudServer, mqttCloudPort, ipCloudStack); Serial.println ("start ARTIK Cloud connect"); Serieel.println(); while (!mqttCloudClient.connect(mqttCloudClientName, mqttCloudUsername, mqttCloudPassword)) { Serial.print("*"); vertraging (500); }}void messageReceived (String-onderwerp, String-payload, char * bytes, niet-ondertekende int-lengte) {}void sendToArtikCloud (float-temperatuur, float-vochtigheid) { loadBuffer (temperatuur, vochtigheid); // laad huidige waarden in de buffer mqttCloudClient.publish(mqttCloudDataOut, buf);}void loadBuffer (float temperatuur, float vochtigheid) { StaticJsonBuffer<200> jsonBuffer; JsonObject&dataPair =jsonBuffer.createObject(); dataPair["temperatuur"] =temperatuur; dataPair["vochtigheid"] =vochtigheid; dataPair.printTo(buf, sizeof(buf));}void loop() { if (++n> 10) { Serial.println("Gestopt."); uitgang (0); } mqttCloudClient.loop(); vertraging (1000); getNextSample(&temperatuur, &vochtigheid); Serial.println("Publiceren..."); Serieel.println(); sendToArtikCloud (temperatuur, vochtigheid); vertraging (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 10000const char* _SSID ="[Wi-Fi SSID ]";const char* _PASSWORD ="[Wi-Fi-wachtwoord]"; // ARTIK Cloud MQTT paramschar mqttCloudServer[] ="api.artik.cloud";int mqttCloudPort =1883;char mqttCloudClientName[] ="ARTIK-Arduino";char mqttCloudUsername[] ="[apparaat-id]"; char mqttCloudPassword[] ="[apparaat-token]"; char mqttCloudActionsIn[] ="/v1.1/actions/[apparaat-id]"; WiFiClient ipCloudStack;MQTTClient mqttCloudClient;char buf[128];int savedRedValue, savedYellowValue;unsigned long savedRedTime, savedYellowTime;void setup() { Serial.begin(57600); pinMode (LED_RED_PIN, UITGANG); pinMode (LED_YELLOW_PIN, UITGANG); SavedRedValue =SavedYellowValue =0; // Wifi-instelling WiFi.begin (_SSID, _PASSWORD); while (WiFi.status() !=WL_CONNECTED) { delay(500); Serieel.print("."); } Serieel.println(); Serial.println("WiFi verbonden"); Serial.print("IP-adres:"); Serial.println(WiFi.localIP()); mqttCloudClient.begin(mqttCloudServer, mqttCloudPort, ipCloudStack); Serial.println ("start ARTIK Cloud connect"); Serieel.println(); while (!mqttCloudClient.connect(mqttCloudClientName, mqttCloudUsername, mqttCloudPassword)) { Serial.print("*"); vertraging (500); } mqttCloudClient.subscribe(mqttCloudActionsIn);}void messageReceived(String topic, String payload, char * bytes, unsigned int lengte) { Serial.print("topic="); Serial.println(onderwerp); Serial.print("payload="); Serial.println(lading); Serieel.print("bytes="); Serieel.println(bytes); Serieel.print("length="); Serial.println(lengte); parseBuffer(payload);}void parseBuffer(String payload) { StaticJsonBuffer<200> jsonBuffer; String json =lading; JsonObject&root =jsonBuffer.parseObject(json); const char* nameparam =root["acties"][0]["naam"]; const int actionLEDRed =root["actions"][0]["parameters"]["led_red"]; const int actionLEDYellow =root["actions"][0]["parameters"]["led_yellow"]; Serial.print("naam="); Serial.println(naamparam); Serial.print("led_red="); Serial.println(actionLEDRed); Serial.print("led_yellow="); Serial.println(actionLEDYellow); Serieel.println(); if (actionLEDRed ==1) {if (savedRedValue!=actionLEDRed) {digitalWrite(LED_RED_PIN, HIGH); saveRedValue =actionLEDRed; } saveRedTime =millis(); } else {if (savedRedValue!=actionLEDRed) {if (millis() - savedRedTime> RED_DELAY) {digitalWrite(LED_RED_PIN, LOW); saveRedValue =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(); vertraging (500); }

Productieproces

  1. DHT11-sensor met LED's en een piëzo-luidspreker
  2. Arduino Spybot
  3. FlickMote
  4. Zelfgemaakte tv B-Gone
  5. Hoofdklok
  6. Vind mij
  7. Arduino Power
  8. Tech-TicTacToe
  9. Arduino Quadruped
  10. De temperatuur en vochtigheid op Blynk aflezen met DHT11
  11. Mkr1000 Pinout:een voorkeurskeuze voor IoT-projecten