Announcement

Collapse
No announcement yet.

Arduino Temperature & Humidity Sensor

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Arduino Temperature & Humidity Sensor

    Hello Fellow Homeseer's.

    I thought i would share with you the Arduino sketch I have been using, it may or may not be of any specific use to anyone, but basically it allows you to connect an ethernet shield to an Arduino device, and when you add a DHT22 temperature and humidity sensor, and a light meter (which has a resistive output) the sketch allows you to serve a web page with the results.

    The initial sketch was modified from the internet, but it seems to work fine for me. Example applications are Greenhouse Monitoring, or anywhere Temperature needs to be monitored. In reality is wouldn't be cheaper than a wireless temperature and humidity sensor but may be of use to someone.

    Arduino 1.0 Sketch:

    For this to work for you, the IP address, Subnet and Gateway would need to be changed to suit your network, also the DHT sensor is connected in this sketch to Pin 4.

    PHP Code:
    /*
     
     http://www.bajdi.com
     
     Web  Server showing the values from a DHT22 sensor
     */

    #include <SPI.h>
    #include <Ethernet.h>
    #include <dht.h>

    dht DHT;

    #define DHTTYPE DHT22  // Sensor type
    #define DHT22_PIN 4       // Data pin of DHT22 sensor

    int lightLevel
    int temp;
    int humi;

    byte mac[]     = { 0x000xAD0xBE0xEF0xFE0xED };
    byte ip[]    = { 1921681};
    byte gateway[] = { 1921681};
    byte subnet[]  = { 255255255};

    EthernetServer server(80);

    unsigned long lastTime 0;

    void setup()
    {
      
    Ethernet.begin(macipgatewaysubnet);
      
    server.begin();
      
    delay(2000);
      
    }

    void loop()
    {
      
    // DHT measurements, max once per 2 seconds
      
    if (millis() - 2000 lastTime)
      {
        
    lastTime += 2000;
        
    int chk DHT.read22(DHT22_PIN);
        
    temp DHT.temperature;
        
    humi DHT.humidity;
      }
      
    // multiple analog reads smooths the signal
      
    lightLevel 0;
      for (
    int i=0i<16i++) lightLevel += analogRead(A0);
      
    lightLevel /= 16;


      
    // listen for incoming clients
      
    EthernetClient client server.available();
      if (
    client
      {
        
    boolean currentLineIsBlank true;
        while (
    client.connected()) 
        {
          if (
    client.available()) 
          {
            
    char c client.read();
            
    // 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 (== '\n' && currentLineIsBlank
            {
              {
      
    // send a standard http response header
      
    client.println("HTTP/1.1 200 OK");
      
    client.println("Content-Type: text/html");
      
    client.println();

      
    // output the value of the DHT22 sensor  
      
    client.print("Arduino powered webserver");
      
    client.println("#<br />");
      
    client.print("Serving temperature and humidity values from a DHT22 sensor");
      
    client.println("#<br />");
      
    client.print("Light : ");
      
    client.print(lightLevel);
      
    client.println(" #<br />");
      
    client.print("Temperature (oC): ");
      
    client.print(temp);
      
    client.println(" #<br />");
      
    client.print("Humidity (%): ");
      
    client.print(humi);
      
    client.println(" #<br />");
    }
              break;
            }
            if (
    == '\n') {
              
    // you're starting a new line
              
    currentLineIsBlank true;
            }
            else if (
    != '\r') {
              
    // you've gotten a character on the current line
              
    currentLineIsBlank false;
            }
          }
        }
        
    // give the web browser time to receive the data
        
    delay(90);
        
    // close the connection:
        
    client.stop();
      }

    Then the code below, thanks to MrHappy's great work will visit the IP address, download the page and extract the appropiate strings and write them to a log, you could then use Hs.SetDeviceString or Hs.SetDeviceValue to store these if needed. The IP address will need to be changed to suit the IP address you assign the Arduino + Ethernet Shield.

    PHP Code:
    Imports System.Text.RegularExpressions

    Sub Main
    (ByVal Parms As Object)

        
    Dim WebStr As String "Arduino powered webserver#Serving temperature and humidity values from a DHT22 sensor#Light (Lux): 

    0#Temperature (oC): -24.40#Humidity (%): +54.00#"

        'Dim Path As String = "http://192.168.1.2/"
        '
    Dim WebStr As String hs.geturl(Path"/"FALSE80)

        
    hs.writelog("RAW"WebStr)
        
    Dim SplitStr() As String Split(WebStr"#")

        
    'For i As Integer = 0 To UBound(SplitStr) - 1
        '
    hs.writelog(iSplitStr(i))
        
    'Next

        If UBound(SplitStr) > 0 Then

            hs.writelog("Light", convert.todouble(Regex.Replace(SplitStr(2), "[^\d|\.\-]", "")) & " lux")
            hs.writelog("Temp", convert.todouble(Regex.Replace(SplitStr(3), "[^\d|\.\-]", "")) & " °C")
            hs.writelog("Humidity", convert.todouble(Regex.Replace(SplitStr(4), "[^\d|\.\-]", "")) & " %")


        End If

    End Sub 
    Hope it helps someone, thanks everyone for the help in getting this going.
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

    #2
    Hi travisdh,

    Nice script

    I am still looking for a new beta tester for my arduino script if you are interested drop me an e-mail.

    This script was written to interact with the Arduino range of I/O boards and Homeseer. The script has the following functions:

    1. Board pins can be assigned as Input, Analogue input, Output or PWM.
    2. The script will auto generate the used devices in homeseer.
    3. All Inputs are switched Inputs that are on when pulled to ground.(no resistors are required)
    4. All outputs are High when On in Homeseer.
    5. All inputs and Outputs are auto update on connection to homeseer.
    6. Multiple Arduino boards are supported.
    7. One Wire DS18S20, DS18B20 and DS1822 temperature sensors are supported.

    I did support the DHT22 but changed it to use the One Wire instead.

    I am looking in to getting an ethernet interface to. I have this working but have had no time to test multi board support and update the manual.

    Greig.
    Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
    X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
    Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
    Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
    Scripts =
    Various

    Comment


      #3
      Nice stuff thanks for posting, my ethernet shield arrived this week and it is on the list to start messing with it, the arduino web code looks nice and easy from your example.

      Comment


        #4
        Depending on the Age of the Ethernet shield you might have a few minor issues, i doubt you will though but in the first version of the Ethernet shields there was a minor bug, which basically caused the unit to freeze and not allow Ethernet communications, this required a capacitor and resistor to be connected to the board, so when the board started up it waited a few seconds whilst the cap charged, then triggered a reset of the Ethernet shield, once this was done it works fine.

        That was earlier versions of the board though, also in the sketch above there is a 2 second delay deliberately put in, since the DHT22 can only read every 1 - 2 seconds, this delay could be removed for analogue devices, and potentially the other 1-wire gear.
        HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

        Facebook | Twitter | Flickr | Google+ | Website | YouTube

        Comment


          #5
          Originally posted by travisdh View Post
          Depending on the Age of the Ethernet shield you might have a few minor issues, i doubt you will though but in the first version of the Ethernet shields there was a minor bug, which basically caused the unit to freeze and not allow Ethernet communications, this required a capacitor and resistor to be connected to the board, so when the board started up it waited a few seconds whilst the cap charged, then triggered a reset of the Ethernet shield, once this was done it works fine.

          That was earlier versions of the board though, also in the sketch above there is a 2 second delay deliberately put in, since the DHT22 can only read every 1 - 2 seconds, this delay could be removed for analogue devices, and potentially the other 1-wire gear.
          I am not expecting much from it, it is a bit of a knock off device from eBay from China (http://www.ebay.co.uk/itm/2211509691...84.m1497.l2649). Not sure what I am going to do with it really, my last project unbelievably worked (Arduino DMX interface with wireless bluetooth) and I don't have many more ideas. We will see, I am sure I can find something for it.

          Comment


            #6
            That looks quite similar to the one I have, I did the same thing and just got a few knockoff shields from eBay and they do work well.

            As for what you can do with them, it really depends. In their simplest form you could use them for some kind of monitoring system reading 1-wire or Analogue values and integrating into Homeseer, you could set up a pan tilt system very easily again integrating into homeseer or go the ultimate Security system and Rig up a Paintball Gun to one of these (i saw a computer kit some time ago that allows you to track people and give them a fright lol)

            Mine is used for simple Temperature, Light and Humidity Monitoring but I am looking at using another one as a kind of pseudo climate control system.

            My thought is that my Computer cupboard gets vented into the roof cavity, at the current time the temperature of that cupboard is 28 Deg C, with about 37% Humidity, my thought is instead of venting into the roof I could reclaim the heat from the roof, and either just directly run a short ducted line to my outdoor Greenhouse (right beside the house) and heat it using the heat, or alternatively run the air through a heat exchanger, to a liquid then back again to another heat exchanger on the other end.

            Using an Ardiuno would allow me to monitor indoor and outdoor temperature, and humidity, and / or pipe liquid temperatures to determine if the air should vent in the greenhouse to heat it, or if it would end up cooling the greenhouse down.

            It would be a big project, but I did also think that the Arduino and an Ethernet shield could potentially be a good audio matrix switcher.
            HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

            Facebook | Twitter | Flickr | Google+ | Website | YouTube

            Comment


              #7
              It would be a big project, but I did also think that the Arduino and an Ethernet shield could potentially be a good audio matrix switcher.
              Oddly enough that was something I had thought of before, I still have some dual digital potentiometers that can be controlled by I2C (or SPI, can't remember) that I thought could turn into some sort of digital mixer. I have absolutely no real application for it but I guess that has not stopped me before!

              Comment


                #8
                Hi Greig, just spotted your post - I wonder if I could test your script to interface HS with the Arduino? I have a couple of UNOs, one of which is pushing excess Solar PV into an immersion heater. The other one I would like to use to PWM some FETS to soft start and dim the LED lighting in the living room. I would like to have these devices controllable from HS.

                cheers,

                Al

                Comment


                  #9
                  Originally posted by apluck View Post
                  Hi Greig, just spotted your post - I wonder if I could test your script to interface HS with the Arduino? I have a couple of UNOs, one of which is pushing excess Solar PV into an immersion heater. The other one I would like to use to PWM some FETS to soft start and dim the LED lighting in the living room. I would like to have these devices controllable from HS.

                  cheers,

                  Al
                  Hi Al,

                  I sent you an e-mail.
                  Can you tell me how your Solar pv and immersion heater is set up as I to would like to do this.

                  Greig.
                  Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
                  X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
                  Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
                  Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
                  Scripts =
                  Various

                  Comment


                    #10
                    Do you want to create a new topic and we can post the various things we are finding about the script , I have just installed on a board with two 1-wire temperature sensors and all seems to be going well at the moment,

                    If you create a new thread, let me know the address and I can let you know what I have done, how it is going etc...

                    Thanks

                    Originally posted by enigmatheatre View Post
                    Hi travisdh,

                    Nice script

                    I am still looking for a new beta tester for my arduino script if you are interested drop me an e-mail.

                    This script was written to interact with the Arduino range of I/O boards and Homeseer. The script has the following functions:

                    1. Board pins can be assigned as Input, Analogue input, Output or PWM.
                    2. The script will auto generate the used devices in homeseer.
                    3. All Inputs are switched Inputs that are on when pulled to ground.(no resistors are required)
                    4. All outputs are High when On in Homeseer.
                    5. All inputs and Outputs are auto update on connection to homeseer.
                    6. Multiple Arduino boards are supported.
                    7. One Wire DS18S20, DS18B20 and DS1822 temperature sensors are supported.

                    I did support the DHT22 but changed it to use the One Wire instead.

                    I am looking in to getting an ethernet interface to. I have this working but have had no time to test multi board support and update the manual.

                    Greig.
                    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

                    Facebook | Twitter | Flickr | Google+ | Website | YouTube

                    Comment


                      #11
                      Originally posted by travisdh View Post
                      Do you want to create a new topic and we can post the various things we are finding about the script , I have just installed on a board with two 1-wire temperature sensors and all seems to be going well at the moment,

                      If you create a new thread, let me know the address and I can let you know what I have done, how it is going etc...

                      Thanks
                      Ok here you go : http://board.homeseer.com/showthread...09#post1044909

                      I'm glad to here all is well so far.

                      Greig.
                      Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
                      X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
                      Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
                      Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
                      Scripts =
                      Various

                      Comment

                      Working...
                      X