Angela LiuDaphne ManningAngie ChenShaquille Que
Created April 17, 2019 © GPL3+

Temperature Sensor

Can't decide what to wear? This sensor lights blue if it's cold enough for a jacket and red if it's too hot before you even step outside!

BeginnerFull instructions provided1 hour40
Temperature Sensor

Things used in this project

Hardware components

Grove Starter Kit for LaunchPad
Seeed Studio Grove Starter Kit for LaunchPad
×1
EK-TM4C123GXL TM4C Tiva LaunchPad
Texas Instruments EK-TM4C123GXL TM4C Tiva LaunchPad
×1
seeed grove - 4-digit display
×1
seeed grove - rotary angle sensor
×1
Grove - Temperature Sensor
Seeed Studio Grove - Temperature Sensor
×1
grove base booster pack
×1
LED (generic)
LED (generic)
×1

Software apps and online services

Energia
Texas Instruments Energia

Story

Read more

Schematics

Schematics

Code

Temperature Sensor Code

C/C++
/*
  Temperature Sensor
 Read value from grove-temperature-humidity sensor then display on grove-4-digital-display
 
 The circuit:
 * 4-digital-display attached to pin35 & pin36 (J14 plug on Grove Base BoosterPack)
 * sig pin of the Grove-Temperature-Humidity Sensor to the analog pin 24 (Grove connector J6)
 * one side pin (either one) to ground
 * the other side pin to +VCC
 * LED anode (long leg) attached to RED_LED
 * LED cathode (short leg) attached to ground
 
 * Note: Put your hands on Grove-Temperature-Humidity Sensor, both of the value 
         will rise. 
         
         4-digital-display:
         |--------------------------|
         | temperature :  humidity  |    
         |--------------------------| 
 
 This example code is in the public domain.
 
 http://www.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro 
 
 */
 
#include "TM1637.h" 
#include "DHT.h"

/* Macro Define */
#define CLK               36                 /* 4-digital display clock pin */
#define DIO               35                 /* 4-digital display data pin */
#define BLINK_LED         RED_LED            /* blink led */
#define TEMP_HUMI_PIN     24                 /* pin of temperature&humidity sensor */
#define ROTARY_ANGLE_P    26                 /* pin of rotary angle sensor */

/* Global Varibles */
TM1637 tm1637(CLK, DIO);                  /* 4-digital 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 */

int c_threshold = 0;                 /* variable to store the value coming from rotary angle sensor */
int blink_interval = 0;               /* LED delay time */
int8_t bits[4] = {0};                 /* array to store the single bits of the value */

const int buttonPin = PUSH2;     // the number of the pushbutton pin
int buttonState = 0;         // variable for reading the pushbutton status
bool isCelsius = true;
bool wasPressed = false;

/* the setup() method runs once, when the sketch starts */
void setup() {
        
    tm1637.init();                       /* initialize 4-digital display */
    tm1637.set(BRIGHT_TYPICAL);          /* set the brightness */    
    tm1637.point(POINT_ON);              /* light the clock point ":" */
        
    dht.begin();                         /* initialize temperature humidity sensor */
        
    pinMode(RED_LED, OUTPUT);            /* declare the red_led pin as an OUTPUT */
    pinMode(GREEN_LED, OUTPUT);
    pinMode(BLUE_LED, OUTPUT);

    // initialize the pushbutton pin as an input:
    pinMode(buttonPin, INPUT_PULLUP); 
}

int celsiusToFarenheit(int temp){
  return 1.8 * (temp) + 32;
}

/* the loop() method runs over and over again */
void loop() {   
  
    int c_temp = dht.readTemperature();             /* read the temperature value from the sensor */
    c_threshold = analogRead(ROTARY_ANGLE_P) / 128;      /* read the value from the sensor */
    blink_interval = c_threshold;                        /* store the rotary analog value */

    // read the state of the pushbutton value:
    buttonState = digitalRead(buttonPin);

    int f_temp = celsiusToFarenheit(c_temp);
    int f_threshold = celsiusToFarenheit(c_threshold);    
  
    // check if the pushbutton is pressed.
    // if it is, the buttonState is HIGH:
    if (buttonState == HIGH) {     
      wasPressed = true;
    } 
    else {
      if(wasPressed){
        isCelsius = !isCelsius;
      }
      wasPressed = false;
    }
             
    memset(t_bits, 0, 2);                                 /* reset array when we use it */
    memset(bits, 2, 4);

    
    if(isCelsius){
      /* 4-digital-display [0,3] is used to display temperatures */
      t_bits[0] = c_temp % 10;
      c_temp /= 10;
      t_bits[1] = c_temp % 10;
  
      bits[2] = c_threshold % 10;
      c_threshold = c_threshold / 10;
      bits[3] = c_threshold % 10;
    }
    else {
      /* 4-digital-display [0,3] is used to display temperatures */
      t_bits[0] = f_temp % 10;
      f_temp /= 10;
      t_bits[1] = f_temp % 10;
  
      bits[2] = f_threshold % 10;
      f_threshold = f_threshold / 10;
      bits[3] = f_threshold % 10;
    }
    
    
    /* show it */
    tm1637.display(1, t_bits[0]);
    tm1637.display(0, t_bits[1]);
    tm1637.display(3, bits[2]);
    tm1637.display(2, bits[3]);

    if(dht.readTemperature() > analogRead(ROTARY_ANGLE_P) / 128)                       /* too hot for jacket */
    {
      digitalWrite(39, LOW);
      digitalWrite(BLUE_LED, LOW);
      digitalWrite(RED_LED, HIGH);
    }
    else                                                  /* wear a jacket */
    {
      digitalWrite(39, LOW);
      digitalWrite(RED_LED, LOW);
      digitalWrite(BLUE_LED, HIGH);
    }
     
}

Credits

Angela Liu
3 projects • 1 follower
Contact
Daphne Manning
0 projects • 0 followers
Contact
Angie Chen
0 projects • 0 followers
Contact
Shaquille Que
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.