
The web has definitely changed many things, such as the availability of data on request, quickly and easily. For example, to know the temperature that’s out there, is readily available through various websites devoted, which also provide forecasts in the short and long term. For those who want to make a solution if, in style “Internet of things”, as you can do it in the easiest way possible? The answer is Arduino + DHT22 + Xively!
Through this tutorial, you can make a IoT device to to share temperature data through the web.
Hardware Components
1 x Arduino Uno
1 x DHT22
1 x 4.7 Kohm resistor
1 x Ethernet Shield
4 x Flexible cables
Software Components
DHT22 Library https://github.com/adafruit/DHT-sensor-library
Library Xively https://github.com/xively/xively_arduino
Code for Arduino
/** This code let Arduino to send the values of temperature and humidity to Xively, via Ethernet Shield. The temperature is getting from DHT22 sensor Author Giacomo Bellazzi */ #include #include #include #include #include #include "DHT.h" #define DHTPIN 3 // PIN data of DHT22 //#define DHTTYPE DHT11 // DHT 11 #define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) DHT dht(DHTPIN, DHTTYPE); // MAC address for your Ethernet shield byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Your Xively key to let you upload data char xivelyKey[] = ""; // Define the strings for our datastream IDs char sensorId1[] = "Temperature"; char sensorId2[] = "Humidity"; XivelyDatastream datastreams[] = { XivelyDatastream(sensorId1, strlen(sensorId1), DATASTREAM_FLOAT), XivelyDatastream(sensorId2, strlen(sensorId2), DATASTREAM_FLOAT), }; // Finally, wrap the datastreams into a feed. Set the Feed value insted of 12345678 XivelyFeed feed(12345678, datastreams, 2 /* number of datastreams */); EthernetClient client; XivelyClient xivelyclient(client); void setup() { Serial.begin(9600); Serial.println("Starting single datastream upload to Xively..."); Serial.println(); dht.begin(); while (Ethernet.begin(mac) != 1) { Serial.println("Error getting IP address via DHCP, trying again..."); delay(15000); } Serial.print("server is at "); Serial.println(Ethernet.localIP()); } void loop() { float h = dht.readHumidity(); // Value of Temp float t = dht.readTemperature(); // Value of Humidity datastreams[0].setFloat(t); // Value of Temp datastreams[1].setFloat(h); // Value of Humidity Serial.print("Read sensor value "); Serial.println(datastreams[0].getFloat()); Serial.println("Uploading it to Xively"); // Send data to Xively int ret = xivelyclient.put(feed, xivelyKey); Serial.print("xivelyclient.put returned "); Serial.println(ret); delay(15000); }
For more detail, visit instructables.com
COMMENTS