Created
February 3, 2013 03:16
-
-
Save amites/4700415 to your computer and use it in GitHub Desktop.
For an Arduino -- pulls sensor data from 2 DHT11's and uploads to a remote server using a GET call over an ethernet shield
requires libraries from Adafruit for the DHT & EtherCard
This file contains hidden or 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
// Example testing sketch for various DHT humidity/temperature sensors | |
// Written by ladyada, public domain | |
#include "DHT.h" | |
#define DHTPIN 2 // what pin we're connected to | |
#define DHTPIN2 3 // what pin we're connected to | |
// Uncomment whatever type you're using! | |
#define DHTTYPE DHT11 // DHT 11 | |
#define DHTTYPE2 DHT11 // DHT 11 | |
//#define DHTTYPE DHT22 // DHT 22 (AM2302) | |
//#define DHTTYPE DHT21 // DHT 21 (AM2301) | |
// Connect pin 1 (on the left) of the sensor to +5V | |
// Connect pin 2 of the sensor to whatever your DHTPIN is | |
// Connect pin 4 (on the right) of the sensor to GROUND | |
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor | |
DHT dht(DHTPIN, DHTTYPE); | |
DHT dht2(DHTPIN2, DHTTYPE2); | |
char buff_h1[6]; | |
char buff_t1[6]; | |
char buff_h2[6]; | |
char buff_t2[6]; | |
String h1_string; | |
String t1_string; | |
String h2_string; | |
String t2_string; | |
String dht_string; | |
int timer = millis(); | |
// Demo using DHCP and DNS to perform a web client request. | |
// 2011-06-08 <[email protected]> http://opensource.org/licenses/mit-license.php | |
/* | |
#include <EtherCard.h> | |
// ethernet interface mac address, must be unique on the LAN | |
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; | |
byte Ethernet::buffer[700]; | |
static uint32_t timer; | |
//char website[] PROGMEM = "www.google.com"; | |
char website[] PROGMEM = "192.168.0.2"; | |
// called when the client request is complete | |
static void my_callback (byte status, word off, word len) { | |
Serial.println(">>>"); | |
Ethernet::buffer[off+300] = 0; | |
Serial.print((const char*) Ethernet::buffer + off); | |
Serial.println("..."); | |
} | |
*/ | |
void setup () { | |
Serial.begin(9600); | |
Serial.println("\n[webClient w/ DHT sensors]"); | |
dht.begin(); | |
dht2.begin(); | |
Serial.println("DHT's initialized"); | |
/* | |
if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0) // 3rd argument 10 added to match shield pi | |
Serial.println( "Failed to access Ethernet controller"); | |
if (!ether.dhcpSetup()) | |
Serial.println("DHCP failed"); | |
ether.printIp("IP: ", ether.myip); | |
ether.printIp("GW: ", ether.gwip); | |
ether.printIp("DNS: ", ether.dnsip); | |
if (!ether.dnsLookup(website)) | |
Serial.println("DNS failed"); | |
ether.printIp("SRV: ", ether.hisip); | |
*/ | |
} | |
void loop () { | |
// ether.packetLoop(ether.packetReceive()); | |
if (millis() > timer) { | |
timer = millis() + 5000; | |
// Reading temperature or humidity takes about 250 milliseconds! | |
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) | |
float h1 = dht.readHumidity(); | |
float t1 = dht.readTemperature(); | |
// float h1 = 36.00; | |
// float t1 = 18.00; | |
Serial.print("Sensor 1 temperature: "); | |
Serial.println(t1); | |
Serial.print("Sensor 1 Humidity: "); | |
Serial.println(h1); | |
float h2 = dht2.readHumidity(); | |
float t2 = dht2.readTemperature(); | |
Serial.print("Sensor 2 temperature: "); | |
Serial.println(t2); | |
Serial.print("Sensor 2 Humidity: "); | |
Serial.println(h2); | |
dtostrf(h1,5, 2, buff_h1); | |
h1_string = String(buff_h1); | |
dtostrf(t1,5, 2, buff_t1); | |
t1_string = String(buff_t1); | |
// dtostrf(h2,5, 2, buff_h2); | |
// h2_string = String(buff_h2); | |
// dtostrf(t2,5, 2, buff_t2); | |
// t2_string = String(buff_t2); | |
dht_string = "&h1=" + h1_string + "&t1=" + t1_string; | |
// + "&h2=" + h2_string + "&t2=" + t2_string; | |
// Serial.println(); | |
// Serial.print("<<< REQ "); | |
// ether.browseUrl(PSTR("/arduino/logger1.php?pwd=secret"), dht_string, website, my_callback); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, it is only printing the temperature and humidity seven times in the serial monitor. Do you now how could I fix it. (I am new at arduino, I do not have very much experience) .