Introduction: How to Share Data of Temperatura From DHT22 Over the Internet With Xively

About: I'm an Arduino Maker, I like technology, playing tennis

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!

Arduino, a microcontroller is really great because it is simple to use and, through the various transducers exist, you can create projects that truly complete.
The DHT22 is a temperature transducer, able to read the temperature and the humidity present and "communicate" to Arduino, so electric.
Xively is web service, with which you can share physical and electrical network, taking advantage of the Internet connection at home.

Requirements of the project

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
Library Xively
Code for Arduino

Step 1: Registration Xively

In order to share the temperature on the web, you need to register a free website Xively, from this web page On this page, we should insert some standard configurations, such as name, etc ...

Now that we have completed the registration, we can finally access the page control with which we manage our information coming from the Arduino. The web page is located at the following link

Now we can add our device, which in this is Arduino, through which the temperature sensor DHT22, is able to read the physical magnitudes, Temp and Hum. To do this we click on "Add device" in the control page

After we have completed the form above, it will open the web page from which we could see the information about the weather conditions anywhere, using an Internet connection. From this page, we should copy some data that will be included in the Arduino code:


Step 2: How to Connect the Wires

The connection of the device to the Arduino DHT22 is quite simple:

(1) VCC -> 5V
(2) DATa -> PIN 3
(3) NULL
(4) GND -> GND

Be careful

Date between VCC and there is a resistance from 4.7 Kohm pull-up, in order to read a voltage values​​, variable according to the temperature, which is read by Arduino! Without this, you can not read the value!

Step 3: The Arduino's Code

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 "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)
// 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.println("Starting single datastream upload to Xively...");
  while (Ethernet.begin(mac) != 1)
    Serial.println("Error getting IP address via DHCP, trying again...");
  Serial.print("server is at ");

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("Uploading it to Xively");
  // Send data to Xively
  int ret = xivelyclient.put(feed, xivelyKey);
  Serial.print("xivelyclient.put returned ");

To be able to make it work, you must enter the data FEED ID and API at their place, within the code.

Now that we have everything set up, we can finally compile and see the final result!