Dylan NguyenChristina CrassasStella PengAn LuuAndrew_Connoy
Published

HumidTemp 1.0

The HumidTemp 1.0 is a temperature/humidity sensor with modern motion sensor abilities. It displays the temperature and dew point.

IntermediateShowcase (no instructions)947
HumidTemp 1.0

Things used in this project

Story

Read more

Schematics

Schematic

Schematic Diagram

Code

HumidTemp 1.0 Code

C/C++
The project uses three modules: temperature/humidity, motion detection, and display. When the motion sensor detects movement, the temperature and humidity sensor measures temperature and humidity, processes the readings, then displays temperature in Fahrenheit and Celsius and dew point.
#include "TM1637.h" 
#include "DHT.h"

/* Macro Define */
#define CLK               38          /* 4-Digit Display clock pin */
#define DIO               37          /* 4-Digit Display data pin */
#define BLINK_LED         RED_LED            /* blink LED */
#define TEMP_HUMI_PIN     24                 /* pin of temperature&humidity sensor */
#define PIR_MOTION_SENSOR        39            /* sig pin of the PIR sensor */

/* Global Variables */
TM1637 tm1637(CLK, DIO);                  /* 4-Digit Display object */
DHT dht(TEMP_HUMI_PIN, DHT22);            /* temperature&humidity sensor object */

int8_t t_bits[2] = {0};                   /* array to store the single bits of the temperature */
int8_t h_bits[2] = {0};                   /* array to store the single bits of the humidity */  

void setup() {
    tm1637.init();                       /* initialize 4-Digit Display */
    tm1637.set(BRIGHT_TYPICAL);          /* set the brightness */    
    tm1637.point(POINT_OFF);              /* light the clock point ":" */
          
    dht.begin();                         /* initialize temperature humidity sensor */

    pinMode(PIR_MOTION_SENSOR, INPUT);    /* Define the input/output pins */
    pinMode(DIO, OUTPUT);
}

void loop() {
    // Display the readings when motion is detected.
    if(isMotionDetected()) {
      /**
       * Read the temperature value from the sensor in Celsius.
       */
      int _temperature = dht.readTemperature();
      /**
       * Calculate the temperature in Fahrenheit and assign it to a new variable.
       */
      int temp = _temperature*9/5+32;    
      /**                   
       * Read the humidity from teh sensor.
       */
      int _humidity = dht.readHumidity();
      /**
       * Calculate the dew point and assign it to a variable.
       */
      int dewPoint = temp - 9*(100-_humidity)/25;
      
      //Reset the temperature and humidity arrays to 0s.
      memset(t_bits, 0, 2);
      memset(h_bits, 0, 2);
      
      // Calculate the digits to show temperature in Celsius on the 4-Digit Display
      t_bits[0] = _temperature % 10;
      _temperature /= 10;
      t_bits[1] = _temperature % 10;
      
      // Calculate the digits to show humidity on the 4-Digit Display
      h_bits[0] = dewPoint % 10;
      dewPoint /= 10;
      h_bits[1] = dewPoint % 10;
      
      // Show the temperature in Celsius for 3000 ms
      tm1637.clearDisplay();
      tm1637.display(1, t_bits[0]);
      tm1637.display(0, t_bits[1]);
      tm1637.display(3, 12);

      delay(3000);
      tm1637.clearDisplay();

      // Calculate the digits to show temperature in Fahrenheit on the 4-Digit Display
      t_bits[0] = temp % 10;
      temp /= 10;
      t_bits[1] = temp % 10;

      // Show the temperature in Fahrenheit for 3000 ms
      tm1637.display(1, t_bits[0]);
      tm1637.display(0, t_bits[1]);
      tm1637.display(3, 15);

      delay(3000);
      tm1637.clearDisplay();

      // Show the dew point for 3000 ms
      tm1637.display(1, h_bits[0]);
      tm1637.display(0, h_bits[1]);
      tm1637.display(3, 13);

      delay(3000);
    }
    // Clear the display when no motion is detected
    else {
      tm1637.clearDisplay();
    }
}

boolean isMotionDetected() {
    int sensor_val = digitalRead(PIR_MOTION_SENSOR);        /* read sig pin */
    if(sensor_val == HIGH) {
        return true;                                        /* motion detected */
    } 
    else {
        return false;                                       /* no motion detected */
    }
}

Credits

Dylan Nguyen
1 project • 0 followers
Contact
Christina Crassas
1 project • 0 followers
Contact
Stella Peng
1 project • 0 followers
Contact
An Luu
1 project • 0 followers
Contact
Andrew_Connoy
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.