Easy Remote ESP8266 Temperature & Humidity Monitor With Cayenne

As I look to get my 9-year-old son more involved with coding and IoT projects, I decided to do a quick ESP8266 based temperature & humidity monitor to stick in the freezer next to his ice cream.

We are using a DHT22 Temperature & Humidity sensor in this project.

When trying to get your kids involved in such things, I think it works better to start with short easy projects and work your way up to more complex projects. That way they do not lose interested too quickly.

Companies like Blynk and Cayenne make it really easy to take your projects to the next step and make them accessible with your smartphone.

I had posted about this project on Facebook and people wanted to see the code so I am posting it below the pics. In a few days, I will do a video walkthrough of how I set it up on the Cayenne Dashboard.

If you are looking for a good kit to get started with ESP8266 Projects, our friends at Squiz have put together a great one you can get on Amazon here(affiliate link): Arduino WiFi ESP8266 Starter Kit for IoT

Monitor your Ice Cream with Easy Remote ESP8266 Temperature & Humidity Monitor With Cayenne in Freezer

Screenshot of Easy Remote ESP8266 Temperature & Humidity Monitor Cayenne Smartphone App

Screenshot of Easy Remote ESP8266 Temperature & Humidity Monitor Cayenne Smartphone App GraphPicture of Wiring for Easy Remote ESP8266 Temperature & Humidity Monitor With Cayenne

 

[code]
#define CAYENNE_PRINT Serial
#include
#include

#define DHTPIN D5 // what pin the DHT is connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)

const int TEMPERATURE_INTERVAL = 30;
unsigned long last_temperature_sent = 0;

const int HUMIDITY_INTERVAL = 30;
unsigned long last_humidity_sent = 0;
String display_temp;
String display_humid;

DHT dht(DHTPIN, DHTTYPE);

// Your network name and password.
char ssid[] = “Your WiFi SSID”;
char wifiPassword[] = “Your WiFi PWD”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “Your Cayenne MQTT Username”;
char password[] = “Your Cayenne MQTT Password”;
char clientID[] = “Your Cayenne MQTT Client ID”;

void getSendTemperature() {
if (millis() – last_temperature_sent >= TEMPERATURE_INTERVAL * 1000UL || last_temperature_sent == 0) {
float temperature = dht.readTemperature(true);

if (isnan(temperature)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
display_temp = temperature;
Serial.print(“Temperature: “);
Serial.print(temperature);

Serial.println(” °F”);
Cayenne.virtualWrite(8, temperature);
last_temperature_sent = millis();
}
}

void getSendHumid() {
if (millis() – last_humidity_sent >= HUMIDITY_INTERVAL * 1000UL || last_humidity_sent == 0) {
float humidity = dht.readHumidity();

if (isnan(humidity)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
display_humid = humidity;
Serial.print(“Humidity: “);
Serial.print(humidity);
Serial.println(” %”);
Cayenne.virtualWrite(9, humidity);
last_humidity_sent = millis();
}
}

void setup() {
// put your setup code here, to run once:
Serial.begin(230400);
dht.begin();
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
// put your main code here, to run repeatedly:
getSendTemperature();
getSendHumid();
Cayenne.loop();
}

//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”);
}
[/code]