How to share data of temperature from DHT22 over the Internet with Xively



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
Library Xively
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 "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 ");

For more detail, visit



Please Login to comment
Notify of