Taylor HullTdougl11
Published

Temperature and Relative Humidity Sensor Setup

This is a temperature & relative humidity sensor and LCD display setup using two Particle Argon's and a DHT11 temperature & humidity sensor.

IntermediateShowcase (no instructions)762
Temperature and Relative Humidity Sensor Setup

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×15
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
Argon
Particle Argon
×2
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×2
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1

Software apps and online services

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

Story

Read more

Schematics

Picture of DHT11 Sensor Circuit

Picture of LCD Screen Circuit

Circuit Diagram for DHT11 Sensor

This circuit diagram shows how we wired our circuit for the DHT11 Sensor. The diagram uses a particle photon in place of the argon as the software Fritzing that we used to create the diagrams did not have the argon.

Circuit Diagram for LCD Screen

This circuit diagram shows how we wired our circuit for the LCD screen. The diagram uses a particle photon in place of the argon as the software Fritzing that we used to create the diagrams did not have the argon.

Live Temperature Monitor

Live Relative Humidity Monitor

Code

LCD Screen Code

C/C++
This is the code that is used allowing the LCD screen to recevie and display the data gathered by the humidity and temperature sensors
// 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 #include statement was automatically added by the Particle IDE.
#include <LiquidCrystal.h>

#define DHTPIN D6 //This defines the pin that is being used to access the LCD Screen

#define DHTTYPE DHT11 // This defines the sensors that are being used to obtain the temperature and humidity data


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

TCPClient client;

unsigned long myChannelNumber = 1250574;
const char * myWriteAPIKey = "6OZIWV6LDC51G5DA";

void setup() 
{
    lcd.begin(16, 2);
        lcd.setCursor(0,0);
    lcd.print("Tempur");
        lcd.setCursor(0,1);
    lcd.print("Humidity");

    ThingSpeak.begin(client);
    pinMode(D7, OUTPUT);

    Particle.subscribe("G45 Iot project Humid", humidity);
    Particle.subscribe("G45 Iot project Temp", temperature);
//This defines everything used in the rest of the code along
//The two subscribe statements correspond to the other argon which is sending the data collected to the LCD screen for it to be displayed
}


void loop() 
{
    // This gives time for the sensors to update and change the temperature and humidity values as they change
    delay(5000);
    
    
    Particle.publish("Group 45 IOT project", PRIVATE);
//This sends the confirm signal to the data recording argon to ensure that they are communicating with each other well
}
    void temperature(const char *event, const char *temperature)
{
        lcd.setCursor(8.,0);
            lcd.print(temperature);
        lcd.setCursor(10,0);
            lcd.print("F     ");
     
          ThingSpeak.setField(1, temperature);
          ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
          
            digitalWrite(D7, HIGH);
                delay(2000);
            digitalWrite(D7, LOW);
                delay(500);
    //This indicates to the LCD argon that the temperature and humidity data has been received, ensuring that communication between the devices has been achieved
}

    
    void humidity(const char *event, const char *humidity)
{
        lcd.setCursor(10,1);
            lcd.print(humidity);
        lcd.setCursor(11,1);
            lcd.print("%     ");
            
          ThingSpeak.setField(2, humidity);
          ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
}
//These last two sets of code prints the received data next to the corresponding title allowing for easy recognition of the number presented

Temperature and Humidity Sensor Code

C/C++
This code is written specifically for the argon connected to the sensor that measures the relative humidity and the temperature of the room and then exports that data to the cloud for retrieval by the LCD argon board.
// 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 <ThingSpeak.h>

//This identifies the primary pin output to be read by the DHT sensor
#define DHTPIN D5    

//Defines what the type of the DHT sensor we are using is.
#define DHTTYPE DHT11        

DHT dht(DHTPIN, DHTTYPE);

bool humid = false;

TCPClient client;

//Identifies what ThingSpeak channel and specific channel set to send the data to and write to
unsigned long ThingSpeakChannelNum = 1244806;
const char * APIWriteKey = "TDB5CCVLGVT70DBN";


void setup() 
{
    ThingSpeak.begin(client);
    
 pinMode(D5, OUTPUT);
 pinMode(D7, OUTPUT);
  Serial.begin(9600); 
    dht.begin();

 Particle.subscribe("Group 45 IOT project", handler);
}


void loop() 
{
    delay(5000);

        float humidity = dht.getHumidity();
        //This instructs the argon to take a measurement of the relative humidity as reported by the DHT11 Sensor
 
        float temperature = dht.getTempFarenheit();
        //This instructs the argon to take a measurement of the temperature in Farenheit as reported by the DHT11 Sensor

    //Sends the data recorded by the argon for relative humidity and temperature to the cloud for retrieval by partner's argon
   Particle.publish("G45 Iot project Humid", String (humidity), PRIVATE);
   Particle.publish("G45 Iot project Temp", String (temperature), PRIVATE);

    //This tells what graph plot to send what data to for ThingSpeak
    ThingSpeak.setField(1,humidity);
    ThingSpeak.setField(3,temperature);
    
  
  
  Serial.print(dht.getHumidity());
    Serial.println("humidity");
  Serial.print(dht.getTempFarenheit());
    Serial.println("temperature");

  
  ThingSpeak.writeFields(ThingSpeakChannelNum, APIWriteKey);  
}

//This code confirms that the devices are achieving two-way communicatin by received an LED ping when the partner argon has successfully received exported data
 void handler(const char *event, const char *data)
{
        digitalWrite(D7, HIGH);
             delay(2000);
        digitalWrite(D7, LOW);
             delay(500);
}
    
   

Credits

Taylor Hull

Taylor Hull

1 project • 0 followers
Tdougl11

Tdougl11

1 project • 0 followers

Comments