Richard LiuHugh O'ReillyJiamu_FengJake LeiRichelle_Huang
Published © CC0

A TEMPorary Solution

Wearing shirts and shorts, but it's 40 degrees outside? Wearing a hoodie and sweats, but it's 103? Never again with a TEMPorary Solution.

BeginnerFull instructions provided2 hours812
A TEMPorary Solution

Things used in this project

Story

Read more

Schematics

A TEMPorary Solution Diagram

Visual Representation of the modules connected to the tiva launch, without the grove booster base

Code

A TEMPorary Solution

C/C++
This is the code for A TEMPorary Solution, that runs in Energia once the TIVA Launch, Grove Seeed Modules are all attached correctly
/*
 Grove Temperature & Humidity Sensor Pro
 
 Read value from Temperature & Humidity sensor then display on 
 the Grove 4-Digit Display.
 
 The circuit:
 * 4-Digit Display attached to Pin 38 and 39 (J14 plug on Grove Base BoosterPack)
 * Rotary Angle Sensor attached to Pin 24 (J6 plug on Grove Base BoosterPack)
 * sig pin of the Grove-Temperature-Humidity Sensor to the analog pin A1

 
 * Note: Put your hands on Temperature & Humidity Sensor, both of the values 
         will rise. 
         
         4-Digit Display:
         |--------------------------|
         | temperature :  humidity  |    
         |--------------------------| 
 
 This example code is in the public domain.
 
 http://www.seeedstudio.com/depot/Grove-TemperatureHumidity-Sensor-Pro-p-838.html 
 
 */
 
#include "TM1637.h" 
#include "DHT.h"

/* Macro Define */
#define TEMP_HUMI_PIN     24                 /* pin of temperature&humidity sensor */
#define PIR_MOTION_SENSOR        36            /* sig pin of the PIR sensor */
#define CLK               38          /* 4-Digit Display clock pin */
#define DIO               37          /* 4-Digit Display data pin */
#define BUZZER_PIN               40            /* sig pin of the Grove Buzzer */
#define LED                      RED_LED      /* LED */


int length = 15;         /* the number of notes */
char notes[] = "ccggaagffeeddc "; //notes in the song
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; //length of each note
int tempo = 200;

/* 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 */  

/* the setup() method runs once, when the sketch starts */
void setup() 
{    
    tm1637.init();                       /* initialize 4-Digit Display */
    tm1637.set(BRIGHT_TYPICAL);          /* set the brightness */    
    tm1637.point(POINT_ON);              /* light the clock point ":" */
        
    dht.begin();                         /* initialize temperature humidity sensor */
    pinMode(BUZZER_PIN, OUTPUT);      
    pinMode(PIR_MOTION_SENSOR, INPUT);   /* declare the sig pin as an INPUT */
    pinMode(LED, OUTPUT);            /* declare the LED pin as an OUTPUT */
    digitalWrite(LED, LOW);
}

/* the loop() method runs over and over again */
void loop() 
{   
    int _temperature = dht.readTemperature();   /* read the temperature value from the sensor */
    int temp = dht.readTemperature();
    //int _temperature = 28;
    //int temp = 28;

    //int _temperature = 10;
    //int temp = 10;
    
    int _humidity = dht.readHumidity();                   /* read the humidity value from the sensor */    
             
    memset(t_bits, 0, 2);                                 /* reset array before we use it */
    memset(h_bits, 0, 2);                                 /* reset array before we use it */
    
    /* 4-Digit Display [0,1] is used to display temperature */
    t_bits[0] = _temperature % 10;
    _temperature /= 10;
    t_bits[1] = _temperature % 10;
    
    /* 4-Digit Display [2,3] is used to display humidity */ 
    h_bits[0] = _humidity % 10;
    _humidity /= 10;
    h_bits[1] = _humidity % 10;
    
    /* show it */
    tm1637.display(1, t_bits[0]);
    tm1637.display(0, t_bits[1]);
    
    tm1637.display(3, h_bits[0]);
    tm1637.display(2, h_bits[1]);

    
    if(isMotionDetected()) 
    {
        digitalWrite(LED, HIGH); 
        if(temp >= 27){
          playNote(notes[7], beats[0] * tempo);
        }
        if(temp <= 16){
          playNote(notes[7], beats[0] * tempo*2);
          playNote(notes[7], beats[0] * tempo*2);
        }/* if we detect movement, turn on the LED */
    } 
    else 
    {
        digitalWrite(LED, LOW);          /* no movement, turn off the light */
    }
    for(int i = 0; i<10000; i++){}
}

/* play tone */
void playTone(int tone, int duration) 
{
  for (long i = 0; i < duration * 1000L; i += tone * 2) 
  {
    digitalWrite(BUZZER_PIN, HIGH);
    delayMicroseconds(tone);
    digitalWrite(BUZZER_PIN, LOW);
    delayMicroseconds(tone);
  }
}

char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

void playNote(char note, int duration) 
{
  
  
  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) 
  {
    if (names[i] == note) 
    {
      playTone(500, duration);
    }
  }
}

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

Richard Liu
1 project • 0 followers
Contact
Hugh O'Reilly
1 project • 0 followers
Contact
Jiamu_Feng
0 projects • 0 followers
Contact
Jake Lei
0 projects • 0 followers
Contact
Richelle_Huang
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.