Things used in this project

Hardware components:
12002 04
Breadboard (generic)
This project can be completed with a single photon. However, this is a class project and using two photons is a requirement. I used a longer breadboard so as to fit both photons on the same breadboard.
×1
Photon new
Particle Photon
×2
386 00
DHT11 Temperature & Humidity Sensor
The DHT11 may be slower than other available sensors but ease of use and the recommendations of friends led me to choose a DHT11 Breakout Board as my temperature monitor.
×1
Wall Outlet
The wall outlet will be used to wire a relay without the need to worry about the house's wiring.
×1
Relay (Single)
×1
Power Cable
×1
Software apps and online services:
Hackster
ThingSpeak API
Hand tools and fabrication machines:
Voltimeter
Wire Stripper

Schematics

DH11 Wiring Schematic
Wiring schematic of the DH11 temperature and humidity sensor. Exclude the use of the resistor.
Iot6 fxi4ieny0w
Wiring schematic for the relay.
Iot7 qfcmbe5zyp

Code

Data Collection Photon CodeC/C++
This program collects data from the DHT11 Sensor and publishes both to the Particle cloud and ThingSpeak for analysis.
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>
// DHT Pin Setting and DHT Type
#define DHTPIN 5
#define DHTTYPE DHT11
//Initialize the temperature and humidity variables as integers
int temperature;
int humidity;
//Set a constant string for the API node obtained from ThingSpeak
const String key = "5R0NW9ZKQAP0SO2M";
//Use the Library commands to confirm DHT Data pin and DHT Type (Type 11)
DHT dht(DHTPIN, DHTTYPE);
//Start the DHT protocols
void setup() {
  dht.begin();
}

void loop() {
  //Collects temperature data in Celsius, the fact that the Library spells it      "CelCius" is somewhat amusing
  temperature = dht.getTempCelcius();
  //Collects Humidity data as a percentage
  humidity = dht.getHumidity();
  //Publishes temperature and Humidity data to the cloud
  Particle.publish("tempC_clone222", String(temperature), PRIVATE);
  Particle.publish("hum_clone222", String(humidity), PRIVATE);
  //Publishes temperature and humidity to ThingSpeak 
  Particle.publish("thingSpeakWrite_All", "{ \"1\": \"" + String(temperature) + "\"," +
    "\"2\": \"" + String(humidity) + "\"," +
    //"\"3\": \"" + String(var2) + "\"," +
    //"\"4\": \"" + String(var3) + "\"," +
    //"\"5\": \"" + String(var4) + "\"," +
    "\"k\": \"" + key + "\" }", 60, PRIVATE);
    //Delays the loop for 1/2 hour or 1800 seconds
  delay(1800000);
}
Photon SwitchC/C++
This subscribes the Photon to the data of the first, and compares it to given values to determine whether it should turn the light on or off.
//Sets pin D4 as the power toggle pin
const int tog = D4;
//initializes temperature
int temperature;

void setup() {
    pinMode(tog, OUTPUT);
    //The relay is wired as normally closed and is non-latching so that if the photon loses power the light will remain on, setting the pin value to high defaults the light to the off position by opening the relay circuit.
    digitalWrite(tog, HIGH);
}
void loop() {
    //Subscribes the device to the  temperature data coming from the first photon and send it to the temperature handler function
    Particle.subscribe("temperature", tempHandler, MY_DEVICES);
    //Compares the temperature value pulled from the cloud to the values set by the user to prevent the well from freezing
    if (temperature >= 10){
        //At a temperature greater than 10 deg C it opens the circuit and turns off the light
        digitalWrite(tog, HIGH);
    }
    else if (temperature <= 5){
        //At temperatures lower than 5 deg C it will close the circuit and turn on the light
        digitalWrite(tog, LOW);
    }
    else{
        //Reading any temperature in the "deadzone" between 5 and 10 deg C restarts the loop
    }
}
//Takes the string data retrieved from the cloud and converts it to an integer value for comparison
void tempHandler(const char *event, const char *data){
    //sets a new string, which i have defined as "pew" to take in the temperature data
    String pew = data;
    //Converts this new string "pew" into the previously defined integer "temperature"
    temperature = pew.toInt();
}

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Drink Alert!!! (Beverage Can Monitor)
Easy
  • 340
  • 4

Full instructions

Tired of going to grab a soda only to find they're all gone!? Well now you have an alert system to let you know when you need to refill.

The Food Thief Catcher
Easy
  • 149
  • 4

Work in progress

Are you tired of all of your pesky roommates stealing your food? Me too, thats why we have the Food Thief Catcher!

Happy Wife =  Happy Life
Easy
  • 255
  • 3

Full instructions

Wife not a morning person? Improve your life by improving your wife's temperament in the morning. Fresh coffee makes wife happy!

Happy Wife = Happy Life

Team We Are Not Coders

Temperature Sensor
Easy
  • 390
  • 5

Full instructions

A photon that measures the temperature and humididty with a DHT 22 sensor and communicates the temperature data to another photon.

Motion Activated Room Light
Easy
  • 155
  • 4

Full instructions

With this project, you'll never have to search for the light switch in the dark again.

Alexa Controlled Photon Project Without Alexa Coding
Easy
  • 1,028
  • 13

Full instructions

The Patriot Alexa Smart Home Skill and IoT library allow you to voice control your Photon quickly and easily with no Alexa coding at all.

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback