Sunday, June 8, 2014

Construct - Humidity & Temperature Web Logger

This time I'm going to create Humidity & Temperature Logger to outline how easy it is to create Web Logger.

Humidity & Temperature Sensor

I have used DHT11, the most common Arduino Humidity & Temperature sensor.
The above site has many more interesting gadgets to look at.

DHT11 datasheet can be downloaded from following site, or it can also be found in the link at the bottom.

Item Measurement Range Humidity Accuracy Temperature Accuracy Resolution Package
DHT11 20-90% RH
±5% RH ±2°C 1 4 Pin Single Row

Accuracy for both Temperature & Humidity sucks; however, DHT11 is easy to purchase and connect.  I will try working with higher accuracy model next time.

It says Resolution for both are 8 bit; however, if you look at the data format it is a different story.

Data Format: 

  • 8 bit integral RH data 
  • + 8 bit decimal RH data 
  • + 8 bit integral T data 
  • + 8 bit decimal T data 
  • + 8 bit check sum

If we start thinking about decimal points it gets confusing when coding.  Thus we are going to use floating just like we did for ADAM-4017.

Data Block Components

It is highly unlikely Temperature & Humidity changes drastically.
For this sensor, the response time for humidity is 15 seconds and temperature is 30 seconds ( in data sheet ).
I am going to measure every 10 minutes.

If we measure every 10 minutes, it is going to take multiple hours to fill up 1 sector.  And if for some reason if you decide to reboot, you are going to lose hours worth of Data.
This is very unwanted situation, thus we are going to write to SD every time we measure.
Add time stamp to each measured data.

  • Used Flag: 4 bytes
    Set it to 0xaa55a55b
  • Data Count: 1 byte
    Number of Data in sector. 0, 1 - 42
  • Extra: 3 bytes
    Fill it with Null.
  • Data: 12 bytes
    42 will fit in 1 Data Block (8 + 42 * 12 = 512)
    • Time Stamp: 4 bytes
      Use only sec part of POSIX time_t.
      Must *1000 because we are not using millisecond part.
      It is 32 bit unsigned integer.
    • Temperature: 4 bytes floating
    • Humidity: 4 bytes floating

Each sector will contain 42 * 10 min = 420 min = 7 hrs worth of data.
Each Data has its own time stamp, thus sector is not ordered in time or date.

Full codes can be found in following links

No comments:

Post a Comment