Created
May 16, 2014 15:17
-
-
Save dwblair/5d190216343fd56dccf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using Plot.ly's Arduino API to visualize Temperature and Humidity Readings from A DHT22 Sensor | |
#define DELAY_OFFSET 11 | |
#define BEEP_PIN 5 | |
#define audioLOW 250 | |
#define audioHIGH 2000 | |
#define tempLOW 0 | |
#define tempCHILLY 18 | |
#define tempMED 30 | |
#define tempHIGH 36 | |
#include <thermistor.h> | |
// Calibration coeffs for RSBR-302J-Z50 Teflon-Coated 3k Thermistor | |
#define A 3.3501 | |
#define B 0.5899 | |
#define C 0.0104 | |
#define R_25C 3000.0 /*ohms*/ | |
#define R_STANDARD 3003.0 /*ohms*/ | |
Thermistor firstThermistor(A,B,C,R_25C,R_STANDARD); | |
#define greenPIN 9 | |
#define bluePIN 8 | |
#define redPIN 7 | |
int tempRange=tempHIGH-tempLOW; | |
int tempStep=tempRange/3.; | |
void beep(unsigned long hz, unsigned long ms); | |
void setup() { | |
Serial.begin(9600); | |
firstThermistor.begin(0); | |
pinMode(BEEP_PIN, OUTPUT); | |
pinMode(bluePIN, OUTPUT); | |
pinMode(greenPIN, OUTPUT); | |
pinMode(redPIN, OUTPUT); | |
//digitalWrite(13, HIGH); | |
} | |
void loop() { | |
Serial.println(tempStep); | |
// Thermistor stuff | |
double V = firstThermistor.readVoltage(); | |
double R = firstThermistor.readResistance(); | |
float T = firstThermistor.readTemperature(); | |
delay(200); | |
Serial.println("---"); | |
Serial.print("voltage: "); | |
Serial.println(V); | |
Serial.print("resistance: "); | |
Serial.println(R); | |
Serial.print("temperature: "); | |
Serial.println(T); | |
//T=15; | |
//decide which LED to blink, and blink it | |
//turn all pins off | |
digitalWrite(redPIN, LOW); | |
digitalWrite(bluePIN, LOW); | |
digitalWrite(greenPIN, LOW); | |
int blinkPIN; | |
blinkPIN=redPIN; | |
if (T<tempMED) blinkPIN=greenPIN; | |
if (T<tempCHILLY) blinkPIN=bluePIN; | |
/* | |
if (T<=(tempLOW+2*tempStep)) blinkPIN=greenPIN; | |
if (T<=(tempLOW+tempStep)) blinkPIN=bluePIN; | |
*/ | |
int j=map(T,tempLOW,tempHIGH,audioLOW, audioHIGH); | |
beep(j, 250); | |
Serial.println(j); | |
int thisDelay = map(T, tempLOW,tempHIGH, 1500,20); | |
digitalWrite(blinkPIN, HIGH); | |
delay(thisDelay); | |
digitalWrite(blinkPIN, LOW); | |
} | |
void beep(unsigned long hz, unsigned long ms) { | |
// reference: 440hz = 2273 usec/cycle, 1136 usec/half-cycle | |
unsigned long us = (500000 / hz) - DELAY_OFFSET; | |
unsigned long rep = (ms * 500L) / (us + DELAY_OFFSET); | |
for (int i = 0; i < rep; i++) { | |
digitalWrite(BEEP_PIN, HIGH); | |
delayMicroseconds(us); | |
digitalWrite(BEEP_PIN, LOW); | |
delayMicroseconds(us); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment