Julian O'Hern
Published © GPL3+

Lane Tech HS - PCL - Automatic Fan

Turn on a fan automatically with a Particle Photon using temperature sensing and the Blynk app.

IntermediateFull instructions provided3 hours766
Lane Tech HS - PCL - Automatic Fan

Things used in this project

Hardware components

DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Adafruit MPL115A2
×1
Photon
Particle Photon
×1
Relay (generic)
×1

Software apps and online services

Blynk
Blynk

Story

Read more

Schematics

home_automation_UgybBGNR00.fzz

Code

Code

Arduino
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_MPL115A2.h"
#include <Wire.h>
#include <Adafruit_DHT.h>



#define DHTPIN 2 // what pin we’re connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);
Adafruit_MPL115A2 mpl115a2;

//blynk auth code
char auth[] = "YourAuthToken";

//int Relay = 1;

void setup() {
Serial.begin(9600);
Blynk.begin(auth);
//Particle.publish("sms/4263749", "Welcome to the Particle Cloud!", PRIVATE);

dht.begin();
mpl115a2.begin();
}

void loop() {
// Wait a few seconds between measurements.
Blynk.run();
delay(2000);

// 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.getHumidity();
// Read temperature as Celsius
// float t = dht.getTempCelcius();
// Read temperature as Farenheit
float f = dht.getTempFarenheit();

float pressureKPA = mpl115a2.getPressure();
 
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

// Compute heat index
// Must send in temp in Fahrenheit!
//float hi = dht.getHeatIndex();
//float dp = dht.getDewPoint();
//float k = dht.getTempKelvin();
Blynk.virtualWrite(1, String(pressureKPA));
Blynk.virtualWrite(2, String(f));
Blynk.virtualWrite(3, String(h));

if (f > 80) {
    pinMode(D6, OUTPUT);
}
else if (f < 70) {
    pinMode(D6, INPUT);
}

Particle.publish("Pressure (kPa)", String(pressureKPA));
Particle.publish("Humidity (%)", String(h));
Particle.publish("Temperature (F)", String(f));
delay(5000);
}


BLYNK_WRITE(V0)
{
  int pinValue = param.asInt();
  
  if (pinValue == 1) {
      pinMode(D6, OUTPUT);
      //digitalWrite(D6, HIGH);
      Particle.publish("Val", "1");
  }
  if (pinValue == 0) {
      pinMode(D6, INPUT);
      //digitalWrite(D6, LOW);
      Particle.publish("Val", "0");
  }
}

Credits

Julian O'Hern

Julian O'Hern

2 projects • 1 follower

Comments