mikesoniat
Published © GPL3+

IoT HVAC Monitor

Monitors the fan speed, on/off cycles, temperature, and humidity of my HVAC system and posts data to ThingSpeak.com.

BeginnerFull instructions provided1 hour1,807
IoT HVAC Monitor

Things used in this project

Hardware components

SparkFun ESP8266 Thing - Dev Board
SparkFun ESP8266 Thing - Dev Board
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
3.7 V LiPo Battery
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
Dell X77M Fan
×1
MyPartsChest.com
×1

Software apps and online services

Arduino IDE
Arduino IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Fritzing Image

Code

IoT HVAC Monitor.ino

Arduino
/*
 IoT HVAC Monitor
 by My Parts Chest
 https://mypartschest.com
 July 2018 
*/

#include <ESP8266WiFi.h>
#include "ThingSpeak.h"
#include <DHTesp.h>
DHTesp dht;

// WiFi and Channel parameters
const char WIFI_SSID[] = "xxxxxxxxxx";
const char WIFI_PSK[] = "xxxxxxxxxx";
unsigned long CHANNEL_ID = 123456;
const char * WRITE_API_KEY = "xxxxxxxxxxxxxxxxxxx";

// Pin definitions
const int LED_PIN = 5; // Thing's onboard, green LED
const int ANALOG_PIN = A0; // The only analog pin on the Thing
const int DIGITAL_PIN = 14; // Digital pin to be read

// Global variables
WiFiClient client;
int OnOff = 0;

void setup() {
  //start serial
  Serial.begin(115200);

  // Set up LED for debugging
  pinMode(LED_PIN, OUTPUT);
  pinMode(DIGITAL_PIN, INPUT);

  //setup dht11
  dht.setup(DIGITAL_PIN, DHTesp::DHT11); // Connect DHT sensor
  
  // Connect to WiFi
  connectWiFi();
  
  // Initialize connection to ThingSpeak
  ThingSpeak.begin(client);

}

void loop() {

  // Call rht.update() to get new humidity and temperature values from the sensor.
  int analogReading = analogRead(ANALOG_PIN);

  float volts = (analogPIN / 1023.0);
  Serial.print("Voltage: ");
  Serial.println(volts);
  
  if (analogPIN > 25) //ignore noise
  {
    OnOff = 1;
  }
  else
  {
    OnOff = 0;
  }

  //get temp and humidity
  float humidity = dht.getHumidity();
  float temperature = dht.getTemperature();
  float tempInF = dht.toFahrenheit(temperature);
  
  //display temp and humidity
  Serial.print("Temperature (C): ");
  Serial.println(temperature, 1);
  Serial.print("Temperature (F): ");
  Serial.println(tempInF, 1);
  Serial.print("Humidity: ");
  Serial.println(humidity, 1);
  Serial.println();
  
  // If successful, push values to ThingSpeak.
  if (analogReading > 0)
  {
    // Turn LED on when sending data
    digitalWrite(LED_PIN, HIGH);
    Serial.println("Sending Data to Thingspeak..." );
    // Write the values to ThingSpeak channel
    ThingSpeak.setField(1, volts);
    ThingSpeak.setField(2, OnOff);
    ThingSpeak.setField(3, tempInF);
    ThingSpeak.setField(4, humidity);
    ThingSpeak.writeFields(CHANNEL_ID, WRITE_API_KEY);
    Serial.println("Data Sent" );
	digitalWrite(LED_PIN, LOW);
  }

  //Send data only once per minute
  delay(60000);
}

// Attempt to connect to WiFi
void connectWiFi() {

  delay(1000);
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WIFI_SSID);
  
  byte led_status = 0;

  // Set WiFi mode to station (client)
  WiFi.mode(WIFI_STA);

  // Initiate connection with SSID and PSK
  WiFi.begin(WIFI_SSID, WIFI_PSK);

  // Blink LED while we wait for WiFi connection
  while ( WiFi.status() != WL_CONNECTED ) {
    digitalWrite(LED_PIN, led_status);
    led_status ^= 0x01;
    delay(100);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  
  // Turn LED off when we are connected
  digitalWrite(LED_PIN, LOW);
}

Credits

mikesoniat

mikesoniat

6 projects • 19 followers
I've been an electronics hobbyist, hacker, maker for as long as I can remember. My current passions are robotics, AI, and machine learning.

Comments