Luke ShevlinElijah Mateola
Published

IoT LED Temperature Monitor

The LED Temperature monitor can tell yo if your room is hot or if it's just your mind playing tricks with a blink of the eye!

IntermediateFull instructions provided6 hours858
IoT LED Temperature Monitor

Things used in this project

Hardware components

Jumper wires (generic)
Jumper wires (generic)
×15
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×3
Photo resistor
Photo resistor
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Resistor 4.75k ohm
Resistor 4.75k ohm
×1
Photon
Particle Photon
×2

Software apps and online services

Maker service
IFTTT Maker service
Google Sheets
Google Sheets

Story

Read more

Schematics

Temperature Sensor Photon

LED Photon Subscribe

Code

Temperature Sensor

C/C++
// 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() {
    
    // temp 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("temperature", String(temperature), PRIVATE);
    digitalWrite(D7,HIGH);
    delay(5000);
    digitalWrite(D7,LOW);
    Particle.publish("humidity", String(humidity) + "%", PRIVATE);
    delay(5000);
    Particle.publish("light", String(light) + "%", PRIVATE);
    delay(5000);
   
    }

Temperature Sensor Subscribe

C/C++
//Sets pin D4 as the power toggle pin
const int tog = D4;
const int tog1 = D2;
//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);
    pinMode(tog1, 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(tog1, HIGH);
    //Subscribes the device to the  temperature data coming from the first photon and send it to the temperature handler function
    Particle.subscribe("temperature", 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 >= 23){
        //At a temperature greater than 23 deg C it close the circuit and turns on the Yellow light
        digitalWrite(tog, HIGH);
    }
    else if (temperature <= 22){
        //At temperatures lower than 22 deg C it will open the circuit and turn off the Yellow light
        digitalWrite(tog, LOW);
    }
    if (temperature <= 22){
        //At a temperature greater than 20 deg C it closes the circuit and turns on the Green light
        digitalWrite(tog1, HIGH);
    }
    else if (temperature >= 22){
        //At temperatures lower than 19 deg C it will close the circuit and turn off the Green light
        digitalWrite(tog1, 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

Luke Shevlin

Luke Shevlin

1 project • 0 followers
Elijah Mateola

Elijah Mateola

1 project • 0 followers

Comments