Alan LueckeMalcolm Blades
Published

Light Identified Temperature Detection

We are using a temperature sensor to turn on a light that determines what to wear for the day.

IntermediateFull instructions provided12 hours5
Light Identified Temperature Detection

Things used in this project

Hardware components

DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
LED (generic)
LED (generic)
×5
Breadboard (generic)
Breadboard (generic)
×2
Argon
Particle Argon
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Photo resistor
Photo resistor
×1
Resistor 1k ohm
Resistor 1k ohm
×1

Software apps and online services

ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Photo Resistor and LED Circuit

This is the circuit diagram for the Photo Resistor and LEDs. The Particle Argon is powered by the computer and a power output is sent through a photo resistor. When there is light shining on the photo resistor, the circuit is activated and the corresponding LEDs will activate. When it is dark, the circuit will be open and the LEDs will not be activated. A 1k Ohm resistor is used to drop the voltage so that it is usable. A jumper cable is used to ground the LEDs on the other side of the breadboard. Each LED is connected to a separate pin that controls which one will be turned on. The blue LED is activated when the temperature reading is below 46 degrees Fahrenheit, the green LED is activated when the temperature is between 46 and 74 degrees Fahrenheit, and the red LED is activated when the temperature is above 74 degrees Fahrenheit. There is a yellow LED that will turn on when the humidity value is above 50, and there is a white LED that will turn on when the humidity value is below 50.

DHT11 Temperature and Humidity Circuit Diagram

This is the circuit diagram for the DHT11 Temperature and Humidity sensor. The Particle Argon is powered by the computer and then sends a power output to the DHT11 sensor. It is also grounded to GND on the Argon. The powered sensor then sends temperature and humidity data to the Argon through pin D2. This data is collected every 15 seconds by ThingSpeak.

Code

DHT11 Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

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

// This example assumes the sensor to be plugged into CONN2
#define DHTPIN 2     // what pin we're connected to

// Here we define the type of sensor used
#define DHTTYPE DHT11        // DHT 11


DHT dht(DHTPIN, DHTTYPE);

//bool humid = false;

TCPClient client;


unsigned long myChannelNumber = 2102726;
const char * myWriteAPIKey = "T4G4E2JWC7JDNIPM";

int LEDpin = D7;
int LEDGREEN = D3;


void setup() {
   
    ThingSpeak.begin(client);
   
        pinMode(D2, OUTPUT);
        pinMode(LEDpin, OUTPUT);
        pinMode(LEDGREEN,OUTPUT);
       
        dht.begin();
        Particle.subscribe("LightBright", LightBright, MY_DEVICES);
        Particle.subscribe("LightNight", LightNight, MY_DEVICES);



     
}




void LightBright(const char *event, const char *data){
    digitalWrite(LEDGREEN,HIGH);
        digitalWrite(LEDpin,LOW);
      Particle.publish("TEST", PUBLIC);

}
void LightNight(const char *event, const char *data){
    digitalWrite(LEDpin,HIGH);
        digitalWrite(LEDGREEN,LOW);
}

   
void loop() {
    // Wait a few seconds between measurements.
    delay(1000);

    // Sensor readings may also be up to 2 seconds
    // Read temperature as Celsius
    float t = dht.getTempCelcius();
    // Read temperature as Farenheit
    float f = dht.getTempFarenheit();
   
      float h = dht.getHumidity();


    ThingSpeak.setField(1,f);
        ThingSpeak.setField(2,h);
       
    Serial.print(dht.getTempFarenheit());
        Serial.print(dht.getTempFarenheit());
        
    

    Serial.println("f");
      Serial.println(" %");
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);  
    delay(5000); // ThingSpeak will only accept updates every 15 seconds.
   
   
                    // numerical value it will notify the other argon
   if (f < 46.0) {
       Particle.publish("TempCold", String(f), PUBLIC);
   } else if (f >= 46.0 && f < 74.0) {
       Particle.publish("TempWarm", String(f), PUBLIC);
   } else if (f >= 74.0) {
       Particle.publish("TempHot", String(f), PUBLIC);
   }
   
   
  if (h < 50){
      Particle.publish("Dry", String(h), PUBLIC);
  } else if (h > 50){
     Particle.publish("Raining", String(h), PUBLIC);
  }
}

Photoresistor Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>


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

TCPClient client;


int LEDPIN3 = D3; 
int LEDPIN4 = D4; 
int LEDPIN5 = D5; 
int LEDPIN6 = D6; 
int LEDPIN7 = D7; 
int photoresistor = A0; 
int analogValue; 

unsigned long myChannelNumber = 2102726;
const char * myWriteAPIKey = "T4G4E2JWC7JDNIPM";


void setup() {
  Serial.begin(9600);
  pinMode(D3, OUTPUT); // Blue light
  pinMode(D4, OUTPUT); // Green light
  pinMode(D5, OUTPUT); // red light
  pinMode(D6, OUTPUT); // Yellow light
  pinMode(D7, OUTPUT); // White light
  pinMode(photoresistor, INPUT);
  Particle.connect();
  Particle.subscribe("TempHot", TempHot, MY_DEVICES);
  Particle.subscribe("TempWarm", TempWarm, MY_DEVICES);
  Particle.subscribe("TempCold", TempCold, MY_DEVICES);
  Particle.subscribe("Dry", Dry, MY_DEVICES);
  Particle.subscribe("Raining", Raining, MY_DEVICES);
ThingSpeak.begin(client);
}


void loop(){
      analogValue = analogRead(photoresistor);
      ThingSpeak.setField(3,analogValue);
      Serial.println(" Light");
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);  
    delay(1000); // ThingSpeak will only accept updates every 15 seconds.
      
}


void TempHot(const char *event, const char *data){
  if (analogValue > 50) {
    digitalWrite(LEDPIN5, HIGH); // Turn on red light
   digitalWrite(LEDPIN3, LOW);
   digitalWrite(LEDPIN4, LOW);
   Particle.publish("LightBright", PUBLIC);
} else if  (analogValue < 50){
 digitalWrite(LEDPIN5, LOW); // Turn off red light
   digitalWrite(LEDPIN3, LOW);
   digitalWrite(LEDPIN4, LOW);
     Particle.publish("LightNight", PUBLIC);

}
}

void TempCold(const char *event, const char *data){
    if (analogValue > 50) {
     digitalWrite(LEDPIN3, HIGH); // Turn on blue light
    digitalWrite(LEDPIN4, LOW);
     digitalWrite(LEDPIN5, LOW);
        Particle.publish("LightBright", PUBLIC);
}
else if  (analogValue < 50){
 digitalWrite(LEDPIN5, LOW); // Turn off blue light
   digitalWrite(LEDPIN3, LOW);
   digitalWrite(LEDPIN4, LOW);
        Particle.publish("LightNight", PUBLIC);
}
}

void TempWarm(const char *event, const char *data){
    if (analogValue > 50) {
    digitalWrite(LEDPIN4, HIGH); // Turn on green light
    digitalWrite(LEDPIN3, LOW);
    digitalWrite(LEDPIN5, LOW);
       Particle.publish("LightBright", PUBLIC);
}
else if  (analogValue < 50){
 digitalWrite(LEDPIN5, LOW); // Turn off green light
   digitalWrite(LEDPIN3, LOW);
   digitalWrite(LEDPIN4, LOW);
        Particle.publish("LightNight", PUBLIC);
}
}

void Dry(const char *event, const char *data){
       if (analogValue > 50) {
      digitalWrite(LEDPIN7, HIGH); // Turn on white light
      digitalWrite(LEDPIN6, LOW);
}
else if  (analogValue < 50){
digitalWrite(LEDPIN7, LOW); // Turn off white light
      digitalWrite(LEDPIN6, LOW);
}
}
void Raining(const char *event, const char *data){
      if (analogValue > 50) {
    digitalWrite(LEDPIN6, HIGH); // Turn on yellow light
      digitalWrite(LEDPIN7, LOW);
}
else if  (analogValue < 50){
digitalWrite(LEDPIN7, LOW); // Turn off yellow light
      digitalWrite(LEDPIN6, LOW);
}
}

Credits

Alan Luecke

Alan Luecke

0 projects • 0 followers
Malcolm Blades

Malcolm Blades

0 projects • 0 followers

Comments

Add projectSign up / Login