Amanda ByrneDuncan Houghtaling
Published © GPL3+

IOT Project: Temperature and Humidity Sensing

This project uses a DHT11 sensor to read the temperature and humidity and then displays these values on an LCD screen.

IntermediateFull instructions provided15 hours437
IOT Project: Temperature and Humidity Sensing

Things used in this project

Hardware components

Argon
Particle Argon
×2
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×24
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

DHT11 Photo

DHT11 Circuit Diagram

This circuit schematic shows the setup for the Argon with the DHT11 Sensor. Note that a Particle Photon is used in the circuit diagram in replace of an Argon, as the software used to create the diagram did not offer an Argon.

LCD Circuit Diagram

This shows the circuit schematic for the Argon and LCD screen. Note that the Argon is replaced with a Particle Photon for this schematic as the software used did not offer an Argon

Video Demonstration

ThinkSpeak: Live Temperature Data

ThinkSpeak: Live Humidity Data

Full Project Photo

LCD Photo

Code

LDC Screen Code

C/C++
This is the code that allows you to subscribe to recieve temperature and humidity data, as well as display this data on an LCD screen.
// This #include statement was automatically added by the Particle IDE.
#include <LiquidCrystal.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 D6     // what pin we're connected to

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

//DHT dht(DHTPIN, DHTTYPE);

LiquidCrystal lcd(5, 4, 3, 2, 1, 0);



void setup() {

  lcd.clear();
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("Temp");
  lcd.setCursor(0,1);
  lcd.print("Humid");
  Particle.subscribe("Amanda_Duncan_IOTf", f, ALL_DEVICES);
  Particle.subscribe("Amanda_Duncan_IOTh", h, ALL_DEVICES);
    // We open up a serial port to monitor the sensor values
    //Serial.begin(9600); 
   //Serial.println("DHT11 test!");

    //dht.begin();
}

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


    Particle.publish("Amanda_Duncan_IOT2",PUBLIC);
}

    void f(const char *event, const char *data) {
    
    // Print the data over serial
    lcd.setCursor(6,0);
    lcd.print(data);
    lcd.setCursor(10,0);
    lcd.print("F     ");
    }
    
    void h(const char *event, const char *data) {
    
    lcd.setCursor(7,1);
    lcd.print(data);
    lcd.setCursor(11,1);
    lcd.print("%     ");
    }
    

DHT11 Sensor and ThinkSpeak Code

C/C++
This is the code that recieves and extracts data from the DHT11 sensor as well as graphs it on ThinkSpeak.
// 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 D6     // 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 = 907102;
const char * myWriteAPIKey = "VNMAW6BVKGHFVMNY";


void setup() {
    
    ThingSpeak.begin(client);
    
 pinMode(D7, OUTPUT);
 Serial.begin(9600); 
 dht.begin();
 Particle.subscribe("Amanda_Duncan_IOT2", l, ALL_DEVICES);

}

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

    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 
    float h = dht.getHumidity();
    // Read temperature as Celsius
    float t = dht.getTempCelcius();
    // Read temperature as Farenheit
    float f = dht.getTempFarenheit();

    // Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t) || isnan(f)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
    }
    
    Particle.publish("Amanda_Duncan_IOTf", String (f), PUBLIC);
    Particle.publish("Amanda_Duncan_IOTh", String (h), PUBLIC);

  ThingSpeak.setField(1,h);
  ThingSpeak.setField(2,f);
  
  Serial.print(dht.getHumidity());
  Serial.println("h");
  Serial.print(dht.getTempFarenheit());
  Serial.println("t");

  
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);  

  delay(15000); // ThingSpeak will only accept updates every 15 seconds. 

}

    void l(const char *event, const char *data) {
        
            digitalWrite(D7, HIGH);
            delay(2000);
            digitalWrite(D7, LOW);
            delay(1000);
       
    }

Credits

Amanda Byrne

Amanda Byrne

1 project • 1 follower
Duncan Houghtaling

Duncan Houghtaling

1 project • 1 follower

Comments

Add projectSign up / Login