ESP8266-12E, Arduino, DHT22, BMP180, Cayenne


#1

Nodemcu V.2 mit DHT22, BMP180 Sensoren verbinden und auf Cayenne Dashboarden

Nodemcu, DHT22, BMP180

-------Sketch---------

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include "DHT.h"
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h> // BMP180 SDA-D2  SCL-D1
#define DHTPIN 14 // DHT22 Datapin to D5-GPIO14
#define DHTTYPE DHT22
// WiFi network info.
char ssid[] = ""; 
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = ""; 
char password[] = ""; 
char clientID[] = "";

unsigned long lastMillis = 0;


Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10180);
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  dht.begin();
  Wire.begin(5, 4); // SDA, SDL
  if (!bmp.begin());
   
}


void loop() {
  Cayenne.loop();

  sensors_event_t event;

    float humidity = dht.readHumidity();

    float temp1 = dht.readTemperature();
    
    float pressure;
    bmp.getPressure(&pressure);
    
    float temp2;
    bmp.getTemperature(&temp2);

    
    Cayenne.virtualWrite(1, temp1, TYPE_TEMPERATURE, UNIT_CELSIUS);
    Cayenne.virtualWrite(2, temp2, TYPE_TEMPERATURE, UNIT_CELSIUS);
    Cayenne.virtualWrite(3, temp1-temp2, TYPE_TEMPERATURE, UNIT_CELSIUS);
    Cayenne.virtualWrite(4, pressure/100, TYPE_BAROMETRIC_PRESSURE, UNIT_PASCAL);
    Cayenne.virtualWrite(5, humidity, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT);
    
  }

Adding custom sensor - NDIR CO2 Sensor
#2

Very cool! Thank you for sharing.

~Benny


#3

Thanks Benny, I try to build something smart


#4

Great!


#5

Nice project write-up! It covers some widely used sensors too!


#6

Thanks


#7

It was my first project, i´am playing since 7 days with this fantastic toys.


#8

Thank you very much!! It works very well!!!