Hendra Kusumah
Published © GPL3+

Room Monitor Throwie

A small and portable temperature, humidity, and light monitor that can be placed instantly anytime.

IntermediateFull instructions provided2 hours3,290

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
Adafruit DHT22 temperature and humidity sensor
×1
Photo resistor
Photo resistor
×1

Software apps and online services

Arduino IDE
Arduino IDE
Cayenne
myDevices Cayenne

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

wemos dht2

wemos ldr

wemos dht1

Code

room_throwie.ino

Arduino
// This example shows how to connect to Cayenne using a manually specified Ethernet connection and send/receive sample data.

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266.h>
#include "DHT.h"

#define DHTPIN 2     // what digital pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
// Your network name and password.
char ssid[] = "ssid";
char wifiPassword[] = "password";

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


unsigned long lastMillis = 0;

void setup() {
  Serial.begin(9600);
  dht.begin();
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
   delay(2000);
   //Read the light value
   int lightValue = analogRead(A0)/10.24;
  
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  Cayenne.loop();

  //Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
  if (millis() - lastMillis > 10000) {
    lastMillis = millis();
    //Write data to Cayenne here. This example just sends the current uptime in milliseconds.
    Cayenne.virtualWrite(0, h);
    //Some examples of other functions you can use to send data.
    Cayenne.celsiusWrite(1, t);
    Cayenne.luxWrite(2, lightValue);
    //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
  }
}

//Default function for processing actuator commands from the Cayenne Dashboard.
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

Credits

Hendra Kusumah

Hendra Kusumah

15 projects • 68 followers
Love hacking and making new things from IoT to robotics

Comments