Created
February 26, 2014 22:15
-
-
Save dwblair/9239781 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 | |
#include <SPI.h> | |
#include <Ethernet.h> | |
#include "plotly_ethernet.h" | |
#include "DHT.h" | |
#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); | |
// DHT Sensor Setup | |
#define DHTPIN 2 // We have connected the DHT to Digital Pin 2 | |
#define DHTTYPE DHT22 // This is the type of DHT Sensor (Change it to DHT11 if you're using that model) | |
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT object | |
plotly plotly; // initialize a plotly object, named plotly | |
//initialize plotly global variables | |
char layout[]="{}"; | |
//char layout[] = "{\"xaxis\": {\"title\": \"Time\"}, \"yaxis\": {\"title\": \"Temp C\"}, \"yaxis2\": {\"title\": \"RH\"}}"; | |
char filename[] = "feed7-olm1"; // name of the plot that will be saved in your plotly account -- resaving to the same filename will simply extend the existing traces with new data | |
// Ethernet Setup | |
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x52, 0xC5 }; | |
byte my_ip[] = { 172, 30, 50, 252 }; // google will tell you: "public ip address" | |
void startEthernet(){ | |
if (plotly.VERBOSE) { | |
Serial.println("Initializing ethernet"); | |
} | |
if(Ethernet.begin(mac) == 0){ | |
if (plotly.VERBOSE) { | |
Serial.println("Failed to configure Ethernet using DHCP"); | |
} | |
// no point in carrying on, so do nothing forevermore: | |
// try to congifure using IP address instead of DHCP: | |
Ethernet.begin(mac, my_ip); | |
} | |
if (plotly.VERBOSE) { | |
Serial.println("Done initializing ethernet"); | |
} | |
delay(1000); | |
} | |
void setup() { | |
// Open serial communications and wait for port to open: | |
dht.begin(); // initialize dht sensor reading | |
startEthernet(); // initialize ethernet | |
// Initialize plotly settings | |
plotly.VERBOSE = false; // turn to false to suppress printing over serial | |
plotly.DRY_RUN = false; // turn to false when you want to connect to plotly's servers | |
plotly.username = "donblair"; // your plotly username -- sign up at https://plot.ly/ssu or feel free to use this public account. password of the account is "password" | |
plotly.api_key = "6f3ad11nnb"; // "public_arduino"'s api_key -- char api_key[10] | |
plotly.timestamp = true; // tell plotly that you're stamping your data with a millisecond counter and that you want plotly to convert it into a date-formatted graph | |
plotly.timezone = "America/Montreal"; // full list of timezones is here: | |
firstThermistor.begin(0); | |
if (plotly.VERBOSE) { | |
Serial.begin(9600); | |
while (!Serial) { | |
; // wait for serial port to connect. Needed for Leonardo only | |
} | |
} | |
} | |
void loop() { | |
float h = dht.readHumidity(); // read humitidy from DHT pin | |
float t = dht.readTemperature(); // read temperature from DHT pin (ours calibrated accuractly to our home thermostat with -5 to the temperature) | |
// Thermistor stuff | |
double V = firstThermistor.readVoltage(); | |
double R = firstThermistor.readResistance(); | |
float T = firstThermistor.readTemperature(); | |
if (plotly.VERBOSE) { | |
Serial.println("---"); | |
Serial.print("voltage: "); | |
Serial.println(V); | |
Serial.print("resistance: "); | |
Serial.println(R); | |
Serial.print("temperature: "); | |
Serial.println(T); | |
Serial.print("dht22: humidity: "); | |
Serial.println(h); | |
Serial.print("dht22: temperature: "); | |
Serial.println(t); | |
} | |
// Open the Stream | |
plotly.open_stream(1, 3, filename, layout); // plotlystream(number_of_points, number_of_traces, filename, layout) | |
plotly.post(millis(),h); // post temperature to plotly (trace 0) | |
delay(150); | |
plotly.post(millis(),t); // post humidity to plotly (trace 1) | |
delay(150); | |
plotly.post(millis(),T); // post humidity to plotly (trace 2) | |
delay(150); | |
for(int i=0; i<300; i++){ //number of seconds to wait before posting again (300 = 5 minutes) | |
delay(1000); | |
if (plotly.VERBOSE) { | |
Serial.println(i); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is for "olm-1" in the Markstein lab