top of page

NodeMCU - DHT11 ile Sıcaklık ve Nem Değeri Okuma

Bu uygulamamızda NodeMCU ve DHT11 kullanarak ortamdaki sıcaklık ve nem değerlerini okuyacağız ve bu değerleri ARDUİNO IOT CLOUD uygulamasında anlık olarak göreceğiz.


Bu uygulamada kullanacağımız malzemeler;

  • NodeMCU

  • DHT11 Sıcaklık ve Nem Sensörü

  • Jumper Kablolar


Öncelikle devremizi şemada gördüğümüz şekilde kuruyoruz.




1)Arduino IoT Cloud’a giriş yapın.

2)Giriş yaptıktan sonra ADD VARIABLE butonuna tıklayın.



1)Değişkenimize(variable) isim verin.

2)Seçeneklerden Light’ı seçin.

3)Read & Write seçeneğini seçin.

4)ADD VARIABLE seçeneğini seçin.


1)Değişkenimize(variable) isim verin.

2)Seçeneklerden Relative Humidity’i seçin.

3)Read & Write seçeneğini seçin.

4)ADD VARIABLE seçeneğini seçin.


1)Değişkenimize(variable) isim verin.

2)Seçeneklerden Temperature Sensor(C’) seçin.

3)Read & Write seçeneğini seçin.

4)ADD VARIABLE diyin.



Dashboards’a tıklayın.



BUILD DASHBOARD butonuna basın.



1)ADD’a basın.

2)Robiduck’ı seçin.


CREATE WIDGETS diyin.


Things’e tıklayın.


Robiduck’ı seçin.


Sketch’e tıklayın.


Open full editor’e tıklayın.


Select Board or Port’a tıklayın.



1)BOARDS kısmına node yazın.

2)NodeMCU 1.0(ESP-12E Module)’ü seçin.

3)OK butonuna basın.


1)Aşağı yöndeki ok’a basın.

2)Board COM5 NodeMCU 1.0(ESP-12E Module)-CHANGE’i seçin.

3)Kodu yazın.

4)Sağ yondeki ok’a basıp kodumuzu NodeMCU’muza yükleyin.

Dashboards’a tekrar gelip uygulamamızı kontrol edebiliriz.


CODE:

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled 2"
 https://create.arduino.cc/cloud/things/2a44ea81-e85f-479e-8ddd-1071c2de0743 
  Arduino IoT Cloud Variables description
  The following variables are automatically generated and updated when changes are made to the Thing
  CloudLight lED_output;
  CloudTemperatureSensor temperature;
  CloudRelativeHumidity humidity;
  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"
#define DHTPIN 2    
#define DHTTYPE DHT11   
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
   dht.begin();
  pinMode(12,OUTPUT);
  // 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 
  float hum = dht.readHumidity();
  float temp = dht.readTemperature();  
  if (isnan(hum) || isnan(temp)  ){
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  humidity = hum;
  temperature = temp;
  Serial.print("Temperature: ");
  Serial.print(temp);
  Serial.print("°C");
  Serial.print(" Humidity: ");
  Serial.print(hum);
  Serial.print("%");
  Serial.println();
  delay(1000);
}
/*
  Since LEDOutput is READ_WRITE variable, onLEDOutputChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onLEDOutputChange()  {
  // Add your code here to act upon LEDOutput change
   if (lED_output == 1)
   {
   digitalWrite(12,HIGH);
   }
   else{
     digitalWrite(12,LOW);
   }
}

Son Paylaşımlar

banner300900.gif
banner300900.gif
bottom of page