Melissa ThaiFe Schultz
Published © GPL3+

Temperature Sensor

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

BeginnerFull instructions provided4 hours2,428
Temperature Sensor

Things used in this project

Hardware components

Photon
Particle Photon
Comes with photon kit. Two to communicate between.
×2
Solderless Breadboard Half Size
Solderless Breadboard Half Size
Comes with Photon Kit. Two to communicate between.
×2
Photo resistor
Photo resistor
Comes with Photon Kit.
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
Takes the temperature, humidity, and light measurements
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
SparkFun Resistor 4.7k Ohm
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
Comes with Photon kit to power device. Keep in mind that there needs to be a power source connected to this, such as a wall outlet or a computer.
×2

Software apps and online services

Maker service
IFTTT Maker service
Google Sheets
Google Sheets

Story

Read more

Schematics

Temperature Sensor Breadboard

This is the breadboard wiring for the temperature sensor. The temperature and humidity data is published into the cloud, which will then be picked up by the subscriber.

Photon Subscribe Breadboard

This is the photon particle that retrieve temperature data from the cloud and will either Toggle Digital Write HIGH if the temperature is greater than or equal to 20 degrees Celcius or Toggle a Digital Write LOW if the temperature is less than or equal to 19 degrees Celcius.

Code

Temperature Sensor Circuit

C/C++
This code is used for the breadboard with a temperature sensor on it. The temperature, humidity, and light data retrieved from the DHT 22 will show up on the particle console and these data are published into the cloud.
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>

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

// DHT parameters
#define DHTPIN 5
#define DHTTYPE DHT22

// Variables
int temperature;
int humidity;
int light;

// Pins
int light_sensor_pin = A0;

// DHT sensor
DHT dht(DHTPIN, DHTTYPE);

void setup() {
    
    // Start DHT sensor
    dht.begin();
}

void loop() {
    
    // Humidity measurement
    temperature = dht.getTempCelcius();
    
    // Humidity measurement
    humidity = dht.getHumidity();
    
    // Light level measurement
    float light_measurement = analogRead(light_sensor_pin);
    light = (int)(light_measurement/4096*100);
   
    // Publish data
    Particle.publish("temperature2807112", String(temperature), PRIVATE);
    digitalWrite(D7,HIGH);
    delay(2000);
    digitalWrite(D7,LOW);
    Particle.publish("humidity", String(humidity) + "%", PRIVATE);
    delay(2000);
    Particle.publish("light", String(light) + "%", PRIVATE);
    delay(2000);
   
    
  

    
}

Photon Subscribe

C/C++
This is the code that is used for the photon subscribe breadboard, where the data is retrieved from the cloud and the D7 LED either turns on/off based on the temperature parameters of digital write toggle commands.
//Sets pin D4 as the power toggle pin
const int tog = D7;

//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);

    //Subscribes the device to the  temperature data coming from the first photon and send it to the temperature handler function
    Particle.subscribe("temperature2807112", temperatureHandler, MY_DEVICES);
    //Compares the temperature value pulled from the cloud to the values set by the user to prevent the well from freezing
}
void loop() {
    if (temperature >= 20){
        //At a temperature greater than 20 deg C it opens the circuit and turns off the light
        digitalWrite(tog, HIGH);
    }
    else if (temperature <= 19){
        //At temperatures lower than 19 deg C it will close the circuit and turn on the light
        digitalWrite(tog, LOW);
    }
    else{
        //Reading any temperature in the "deadzone" between 15 and 20deg C restarts the loop
    }

}
//Takes the string data retrieved from the cloud and converts it to an integer value for comparison
void temperatureHandler(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

Melissa Thai

Melissa Thai

1 project • 3 followers
Fe Schultz

Fe Schultz

1 project • 2 followers

Comments