Max YuAlex ArtripYixuan Zhou
Published © GPL3+

Please Turn DOWN the AC

Nothing feels better than a cold room on a hot day, and with a handpicked array of sensors and instruments, thats exactly what you can get!

EasyFull instructions provided1 hour34
Please Turn DOWN the AC

Things used in this project

Hardware components

Grove Starter Kit for LaunchPad
Seeed Grove Starter Kit for LaunchPad
×1
EK-TM4C123GXL TM4C Tiva LaunchPad
Texas Instruments EK-TM4C123GXL TM4C Tiva LaunchPad
×1

Software apps and online services

Energia
Texas Instruments Energia

Story

Read more

Schematics

circuit

Elect220 fritzing bb kxemd6cq4l

schematic

Elect220 fritzing schem 9ijxkrrso0

Code

Source Code

C/C++
/*
 Grove Rotary Angle Sensor

 Demonstrates analog input by reading an analog sensor on analog 
 pin, turning on and off a light emitting diode (RED_LED on LanuchPad) 
 and display the value on Grove 4 Digit Display. 
 The amount of time the LED will be on and off depends on
 the value obtained by analogRead(). 
 
 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)
 
 * Note: Because of changes in voltage, the value of the rotary angle sensor 
         varies slightly from run to run even you don't touch it.  
 
 Created by Oliver Wang
 
 This example code is in the public domain.
 
 http://www.seeedstudio.com/depot/Grove-Rotary-Angle-Sensor-p-770.html
 */
 
#include "TM1637.h" 
#include "DHT.h"

/* Macro Define */
#define CLK               39          /* 4-Digit Display clock pin */
#define DIO               38          /* 4-Digit Display data pin */
#define LED               RED_LED     /* blink LED */
#define ROTARY_ANGLE_P    24          /* pin of rotary angle sensor */
#define TEMP_HUMI_PIN     27                 /* pin of temperature&humidity sensor */
#define BUZZER_PIN               36


/* Global Variables */
TM1637 tm1637(CLK, DIO);              /* 4-Digit Display object */
DHT dht(TEMP_HUMI_PIN, DHT22);            /* temperature&humidity sensor object */
int analog_value = 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 */
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 */  

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;

/* the setup() method runs once, when the sketch starts */
void setup() 
{
    /* Initialize 4-Digit Display */
    tm1637.init();
    tm1637.set(BRIGHT_TYPICAL);
  
    /* declare the LED pin as an OUTPUT */
    dht.begin();        

    pinMode(BUZZER_PIN, OUTPUT);
    
    pinMode(LED, OUTPUT);

    Serial.begin(9600);
}

/* the loop() method runs over and over again */
void buzz()
{
  /* Create a melody that is played upon the method call */
  int c = 0x5;
  int x = 0X5;
  int z = 0x1f;
  for(int i = 0; i < length; i++)
  {
    //space indicates a pause
    if(notes[i] == ' ')
    {
      delay(beats[i] * tempo);
    }
    else
    {
      playNote(notes[i], beats[i] * tempo);
    }
    delay(tempo / 2);    /* delay between notes */
  }
}

/* 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);
  }
}

/* initialize notes to be played when buzzer is triggered */
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(tones[i], duration);
    }
  }
}


void loop() 
{   
    analog_value = analogRead(ROTARY_ANGLE_P);      /* read the value from the sensor */
    blink_interval = analog_value;                  /* store the rotary analog value */
    digitalWrite(LED, HIGH);                        /* turn on LED */

    int actual_temp = (dht.readTemperature()*9)/5 + 32;  /* convert recorded temperatur to fahrenheit */
    Serial.print(actual_temp);
    int ideal_temp = 50;      /* set lower bound on temperature display */
    int off_set = 4096 / 49; /* define the increment of the rotary sensor to be able to go from initial temp to (initial + 49( */

    int dis_temp = ideal_temp + analog_value/off_set ; /* temperature threshhold that is not to be exceeded */ 
    int dis_t = dis_temp;

    /* Display the bits to their appropriate place on the 4-digit display */
    memset(bits, 0, 4);     
    bits[0] = 0; 
    bits[1] = 0;/* reset array before we use it */
    for(int i = 3; i >= 2; i--) 
	  {
        bits[i] = dis_temp % 10;  /*looks at last digit */
        dis_temp = dis_temp / 10; /* clearly last digit */
        tm1637.display(i, bits[i]);                 /* display on 4-Digit Display */
    }

    
    if(actual_temp > dis_t)         /* If measured temperature exceeds the displayed ideal temperature the buzzer is activated */
    {
        buzz();
    }
    
}

 

Credits

Max Yu

Max Yu

1 project • 0 followers
Alex Artrip

Alex Artrip

0 projects • 0 followers
Yixuan Zhou

Yixuan Zhou

0 projects • 0 followers

Comments

Add projectSign up / Login