Skip navigation

To all the Element14 members interested in participating to the Internet of Holiday Lights roadtest, and more generally to anyone who'd like to play with the Arduino Yún for building Internet of Things applications, this video is for you!
It gives you a very brief introduction on how you can turn an RGB LED strip that you can get on Amazon or eBay for ~25USD, into a remotely controlled IoT device using MQTT, the Eclipse IoT free broker, and an Arduino Yún!



The MQTT library for the Arduino is from Eclipse Paho but includes a fix that is not yet merged, so in the meantime you should probably use the library available here.

The code for the Arduino and Web applications is on Github.


Please do not hesitate to comment if you have any questions or if you want to share the ideas you may have to improve this little experiment!

This is a quick post to show how easy it is to connect a DHT22 temp and Humidity sensor to an Arduino and have it output its reading on a web page that can easily be accessible from anywhere on the internet

With a little more work you can pretty up the display and add other features. This is just to demonstrate a proof of concept to you


The library is directly from the Arduino Playground, what I am demonstrating here is how to combine a few libraries to create something useful, a little more than a blinky sketch. I have found through experience that there is a lot of good educational material on the internet to do just a single function but not too much that actually is useful beyond the educational aspect. What I am going to do in the coming weeks is to build upon this sample prototype in this post and create a full blown useful home thermostat or something similar.


this is the sensor :-

you can also get the cheaper and less accurate DHT11 but will need to change the code ever so slightly, IE, change this "int chk = DHT.read22(DHT22_PIN)" to "int chk = DHT.read11(DHT11_PIN)" and other places with similar references to DHT22


and the ENC Card looks like this

or you can use a Wiznet based Shield

Parts are available from eBay, AdaFruit, Sparkfun and other suppliers

Please provide feedback as to any features you would like to see in this as we progress and I will try to include some.



Oh and for those not following along closely, the Arduino is acting as the web server in this case, you don't need a separate server






Code for the proof of concept

#include <SPI.h>
#include <Wire.h>
#include <Ethernet.h>
//#include <UIPEthernet.h>
#include <dht.h>
#include <stdio.h>
dht DHT;
#define DHT22_PIN 2
float combined_temp_C;
float combined_temp_F;  //create a new variable
byte TempHi;              // Variable hold data high byte
byte TempLo;              // Variable hold data low byte
boolean P_N;              // Bit flag for Positive and Negative
boolean P_N112;
boolean P_N212;
unsigned int Decimal;     // Variable hold decimal value
char * strTempC = NULL;
 char * strTempF = NULL;
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x4E, 0x10 };  // MAC address
byte ip[]  = { 192, 168, 1, 203 };                     // ip-address, please change to fit your network
byte mydns[] = { 192, 168, 1, 1 };            
byte gateway[] = { 192, 168, 1, 1 };             
byte subnet[] = { 255,255,255,0 }; 
EthernetServer server(80);
static char output[300] = "";
void setup() {
   Ethernet.begin(mac, ip);
   Serial.print("server is at ");
char headerHTML[] = "HTTP/1.1 200 OK\r\n"
          "Content-Type: text/html\r\n"
          "Connection: close\r\n"
          "Refresh: 5\r\n"
          "<!DOCTYPE HTML>"
          "<Title>RBBS Server</Title>"
 char footerHTML[] = "</html>" ;
 char * TimeElapsed() { // Was Home Page
  long t = millis() / 1000;
  word h = t / 3600;
  byte m = (t / 60) % 60;
  byte s = t % 60;
  sprintf(output, "<h1>%d%d:%d%d:%d%d</h1>" , h/10, h%10, m/10, m%10, s/10, s%10);
  return output;
 void sendTempToNetwork(EthernetClient myClient)
      // now humidity / temp sensor
    int chk = DHT.read22(DHT22_PIN);
    myClient.print(DHT.temperature, 0);
    myClient.write(" ");
    myClient.print(dewPoint(DHT.temperature,DHT.humidity), 0);
    myClient.write(" ");
 void sendAnalogToNetwork(EthernetClient myClient)
    // output the value of each analog input pin for good measure
    for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
      int sensorReading = analogRead(analogChannel);
      myClient.print("analog input ");
      myClient.print(" is ");
      myClient.println("<br />");       
 * Main Loop
void loop() 
// listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c =;
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          // now send the stuff we want
          client.print(TimeElapsed()); // your old code here
          // do some more stuff
           // were done sending so now send the footer to close the page
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data
    // close the connection:
    Serial.println("client disconnected");
void Cal_Temp()
  if (TempHi&0x80)     // If bit7 of the TempHi is HIGH then the temperature is negative
    P_N = 0;
  else       // Else the temperature is positive
  P_N = 1;
  TempHi = TempHi & 0x7F;   // Remove sign
  TempLo = TempLo & 0xF0;   // Filter out last nibble
  TempLo = TempLo >>4; // Shift right 4 times
  Decimal = TempLo;
  Decimal = Decimal * 625;  // Each bit = 0.0625 degree C
  combined_temp_C= TempHi + TempLo*.0625;
  combined_temp_F = combined_temp_C*1.8+32;
   sprintf(strTempC, "%f", combined_temp_C);
   sprintf(strTempF, "%f", combined_temp_F);
////Celsius to Kelvin conversion
//double Kelvin(double celsius)
//        return celsius + 273.15;
// dewPoint function NOAA
// reference: 
double dewPoint(double celsius, double humidity)
        double A0= 373.15/(273.15 + celsius);
        double SUM = -7.90298 * (A0-1);
        SUM += 5.02808 * log10(A0);
        SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
        SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM-3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558-T);
// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference:
double dewPointFast(double celsius, double humidity)
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;


The DHT22 Library can be found here




This is a sample of the code and also the resulting output on a web browser to show it works

Hi all,


I'm trying to raise some funds for the Portlet project on Kickstarter:


The brain is an Arduino Pro and it's sporting 2 relay controlled outlets, 2 thermocouple inputs, 4 buttons, the reset button, and an LCD screen.


Here's a list of some project ideas using the Portlet:


Thanks for taking a look!  Hope it generates some interest.

Filter Blog

By date: By tag: