Wesley Floyd
Published © GPL3+

Blynk Controlled Space Heater Thermostat

Blynk app allows selection of a desired temperature. A space heater turns on once actual temperature drops below desired temperature.

AdvancedWork in progress5 hours3,487
Blynk Controlled Space Heater Thermostat

Things used in this project

Hardware components

Photon
Particle Photon
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Particle Relay Shield
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
DC Adapter
To power relay shield
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Blynk
Blynk

Hand tools and fabrication machines

Wire Strippers
Phillips Head Screw Driver
Soldering iron (generic)
Soldering iron (generic)
optional

Story

Read more

Schematics

Overall Circuit

DHT22, photon and relay shield hook up

Code

heater thermostat

Arduino
Paste the code will need to include blynk and pietTech_DHT libraries
Code is commented with help as well as with some trials I may return to later
// This #include statement was automatically added by the Particle IDE.
#include "PietteTech_DHT/PietteTech_DHT.h"

// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"

/*char auth[] = "Blynk authorization code here";


void setup() {

Serial.begin(9600);
delay(5000);
Blynk.begin(auth);
}
void loop() {
    Blynk.run();
}*/
//started pasting code

// system defines
#define DHTTYPE  DHT22              // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN   2        	    // Digital pin for communications
#define DHT_SAMPLE_INTERVAL   60000  // Sample every minute

//declaration
void dht_wrapper(); // must be declared before the lib initialization

// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);

// globals
unsigned int DHTnextSampleTime;	    // Next time we want to start sample
bool bDHTstarted;		    // flag to indicate we started acquisition
int n;                              // counter

//this is coming from http://www.instructables.com/id/Datalogging-with-Spark-Core-Google-Drive/?ALLSTEPS
char resultstr[64]; //String to store the sensor data

//DANGER - DO NOT SHARE!!!!
char auth[] = "blynk toke here"; // Put your blynk token here
//DANGER - DO NOT SHARE!!!!

char VERSION[64] = "0.04";

#define READ_INTERVAL 60000
double tmp = 32; //ADDED V2
double low = 65; //ADDED V2
double high = 70; //ADDED V2
//double heatsetting = LOW;
void setup()
{

  Blynk.begin(auth);
 
 DHTnextSampleTime = 0;  // Start the first sample immediately
 Particle.variable("result", resultstr, STRING);

 Particle.publish("DHT22 - firmware version", VERSION, 60, PRIVATE);
 pinMode(D6, OUTPUT); // I ADDED THIS 2nd VERSION
 
 Particle.variable("temp", tmp); //ADDED V2
 Particle.variable("low", low); //ADDED V2
 Particle.variable("high", high); //ADDED V2
}


// This wrapper is in charge of calling
// must be defined like this for the lib work
void dht_wrapper() {
    DHT.isrCallback();
}

void loop()
{

  Blynk.run(); // all the Blynk magic happens here
  
  //Turn heater on ADDED V2
  //while(heatsetting == HIGH){
  if(tmp < low){ //ADDED V2
      digitalWrite(D3,HIGH); //ADDED V2
  }
  else{
      digitalWrite(D3,LOW);
  }
  //turn heater off added v2
  /*
  if (tmp > high){
      digitalWrite(D3, LOW);
  }
*/  
  //}

  // Check if we need to start the next sample
  if (millis() > DHTnextSampleTime) {
      
	if (!bDHTstarted) {		// start the sample
	    DHT.acquire();
	    bDHTstarted = true;
	}

 if (!DHT.acquiring()) {		// has sample completed?

  float temp = (float)DHT.getFahrenheit();
  tmp = temp; //ADDED V2
  int temp1 = (temp - (int)temp) * 100;

  char tempInChar[32];
  sprintf(tempInChar,"%0d.%d", (int)temp, temp1);
  Particle.publish("The temperature from the dht22 is:", tempInChar, 60, PRIVATE);

  //virtual pin 1 will be the temperature
  Blynk.virtualWrite(V1, tempInChar);
 
  //google docs can get this variable
  sprintf(resultstr, "{\"t\":%s}", tempInChar);

  float humid = (float)DHT.getHumidity();
  int humid1 = (humid - (int)humid) * 100;

  sprintf(tempInChar,"%0d.%d", (int)humid, humid1);
  Particle.publish("The humidity from the dht22 is:", tempInChar, 60, PRIVATE);

  //virtual pin 2 will be the humidity
  Blynk.virtualWrite(V2, tempInChar);

  n++;  // increment counter
  bDHTstarted = false;  // reset the sample flag so we can take another
  DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL;  // set the time for next sample
 }
 
}

}
/*BLYNK_WRITE(V3) //Button Widget is writing to pin V3
{
int pinData = param.asInt();
digitalWrite(D3, pinData); //Turn ON//OFF heater
}*/

//Temperature Setting in Blynk on Virtual Pin 2
BLYNK_WRITE(V4) {
  int tempSetting = param.asInt();
  low = tempSetting;
    
}
/*BLYNK_WRITE(V5) {
  int heatsyst = param.asInt();
  heatsetting = heatsyst;
} */

Credits

Wesley Floyd

Wesley Floyd

1 project • 1 follower
Mechanical Engineering Student UNC Charlotte Appalachian State University Alum

Comments