Pages: [1]   Go Down
Author Topic: Sensirion seems way off  (Read 356 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I am using 2.0 of the Sensirion library with a SHT75 - the high accuracy sensors. I have two of them. I am in a basement that is around 75 degrees F, and with the readings I am getting the sensors show 84 degrees. Im going to leave the project running overnight, but I am wondering why I would get such a wild reading.

I am connected to the 3.3v power pin, and am not using any resistors for pull-up/down. I get no CRC etc errors and seem to get clean results.

The code in question:
 if(sensirionFound){
 
    sht.measTemp(&rawData);                // sht.meas(TEMP, &rawData, BLOCK)
    temperature = sht.calcTemp(rawData);
    sht.measHumi(&rawData);                // sht.meas(HUMI, &rawData, BLOCK)
    humidity = sht.calcHumi(rawData, temperature);
    dewpoint = sht.calcDewpoint(humidity, temperature);
    
    temperature=(temperature*9/5)+32;
    dewpoint=(dewpoint*9/5)+32;
  }


I do reading every 30 seconds or so...
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 169
Posts: 12448
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Can you post the whole code?

Have you checked the temperature with another sensor/ reference as some places in the basement can be hotter than others.

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ill check as much as I can - I do have other sensors in the basement getting lower readings on ELK M1 keypads. I suppose the sensation should be much more accurate.

Feed results: https://cosm.com/feeds/61454


Code:

#include <SPI.h>
#include <Sensirion.h>
#include <Ethernet.h>
#include<stdlib.h>

#define SMTPserver "smtp.1and1.com"

#define APIKEY         "removed" // your cosm api key
#define FEEDID         61454 // your feed ID
#define USERAGENT      "Cosm Arduino Example (61454)" // user agent is the project name


//IPAddress server(216,52,233,121);      // numeric IP for api.cosm.com
char server[] = "api.cosm.com";   // name address for cosm API
boolean lastConnected = false;                 // state of the connection last time through the main loop
const unsigned long postingInterval = 15000; //10*1000; //delay between updates to Cosm.com
const unsigned long loggingInterval = 6000; //10*1000; //delay between updates to Cosm.com

unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
unsigned long lastLoggingTime = 0;          // last time you printed output, in milliseconds





unsigned int rawData;
float temperature;
float humidity;
float dewpoint;
const byte dataPin =  2;                 // SHTxx serial data
const byte sclkPin =  3;                 // SHTxx serial clock
byte error=0;
byte stat=0;
boolean sensirionFound=false;
Sensirion sht = Sensirion(dataPin, sclkPin);
boolean sentAlarm=false;





const byte redLED    = 7;                 // Alarm
const byte blueLED   = 8;                 // Flashes to show operation.
const byte greenLED  = 9;                // Lights as conections to update or send emails are made




// To get your authentication string, in a terminal, type:
// perl -MMIME::Base64 -e 'print encode_base64("yourname\@yourdomain.com\000yourname\@yourdomain.com\000YourPasswordHere")'






// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x00, 0xDF, 0x5B };


EthernetClient client;



int oldLevel = 1;
int isconnected=0;



void setup() {





  pinMode(redLED, OUTPUT);
  pinMode(blueLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(A0, INPUT);       // declare the LDR as an INPUT

    digitalWrite(greenLED, HIGH);
  delay(500);
  digitalWrite(greenLED, LOW);
  digitalWrite(blueLED, HIGH);
  delay(500);
  digitalWrite(blueLED, LOW);
  digitalWrite(redLED, HIGH);
  delay(500);
  digitalWrite(redLED, LOW);


  Serial.begin(9600);
  for(oldLevel=0;oldLevel<20;oldLevel++)Serial.println();
  oldLevel=1;
  

  Serial.print(F("Initializing the Sensirion sensor..."));

  if (error = sht.readSR(&stat)){

    Serial.print(F("Not found - disabling - "));

    logError(error);
  }
  else
  {

    Serial.println(F("OK!"));

    sensirionFound=true;
  }



  Serial.print(F("Initializing Ethernet..."));

  digitalWrite(greenLED, HIGH);
  if (!Ethernet.begin(mac)) {

    Serial.println(F("Can't get IP Address!"));

    for(;;){
      digitalWrite(greenLED, LOW);
      digitalWrite(redLED, HIGH);
      delay(100);
      digitalWrite(greenLED, HIGH);
      digitalWrite(redLED, LOW);
      delay(100);
    }

  }
  else Serial.println(F("OK!"));
  digitalWrite(redLED, LOW);
  digitalWrite(greenLED, LOW);

  Serial.println(Ethernet.localIP());
  // give the Ethernet shield a second to initialize:
  delay(1000);

}



// the loop routine runs over and over again forever:
void loop() {
  drainInternet(true);


int i,j;
for(i=0;i<15;i++){
  drainInternet(true);
  for(j=(16-i);j>0;j--){
    digitalWrite(blueLED, HIGH);
    delay(50);
    digitalWrite(blueLED, LOW);
    delay(50);
  }
  delay(1000);
}
 

  if(sensirionFound){
 
    sht.measTemp(&rawData);                // sht.meas(TEMP, &rawData, BLOCK)
    temperature = sht.calcTemp(rawData);
    sht.measHumi(&rawData);                // sht.meas(HUMI, &rawData, BLOCK)
    humidity = sht.calcHumi(rawData, temperature);
    dewpoint = sht.calcDewpoint(humidity, temperature);
    
    temperature=(temperature*9/5)+32;
    dewpoint=(dewpoint*9/5)+32;
  }
  else
  {

    humidity = analogRead(A0);
    dewpoint=humidity/2;
    temperature=100-(humidity/3);
  }

  String myData="";

 char buffer[10];
  myData="Humidity01,";
  dtostrf(humidity,6,2,buffer);
  myData+=buffer;
  
  myData+="\n";

  myData+="Temperature01,";
  dtostrf(temperature,6,2,buffer);
  myData+=buffer;
  myData+="\n";

  myData+="DewPoint01,";
  dtostrf(dewpoint,6,2,buffer);
  myData+=buffer;



  if(!client.connected() && (millis() - lastLoggingTime > loggingInterval)) {
    Serial.println(myData);
    lastLoggingTime= millis();
  }
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    sendData(myData);
  }




}


void drainInternet(boolean shouldDisplay)
{
  if (client.connected()){
    while(client.available()) {
      char c = client.read();
      if(shouldDisplay)Serial.print(c);
    }
    if (!client.connected()){
      client.stop();
      digitalWrite(greenLED, LOW);
    }

  }
}





// The following code is only used with error checking enabled
void logError(byte error) {
  switch (error) {
  case S_Err_NoACK:
    Serial.println(F("Error: No response"));
    break;
  case S_Err_CRC:
    Serial.println(F("Error: CRC mismatch!"));
    break;
  case S_Err_TO:
    Serial.println(F("Error: Measurement timeout!"));
    break;
  default:
    Serial.println(F("Unknown error!"));
    break;
  }
  
}




boolean waitForResposeContaining( String search, int timeOut)
{
  unsigned long t = millis();
  boolean found=false;
  String tempString;



  while(!found){
    tempString =readInternetLine(timeOut);
    Serial.println(tempString);
    if(tempString.indexOf(search)>-1)
    {
      return true;

    }

    if(millis()-t>timeOut*1000){
      return false;
    }
  }

}

String readInternetLine(int timeOut)
{
  // This function reads a line of text from the network client connection.
  // and returns after a \r\n (It does not return the \r or \n)
  // It also only waits for timeOut number of seconds before returning, assuming
  // that the return string never came.

  if(!client.connected())return "";
  unsigned long t = millis();
  int ok=0;
  String tempString="";
  while(ok==0){
    if(client.available()) {
      char c = client.read();
      if(c=='\n')ok=1;
      if(!(c=='\r'))if(!(c=='\n'))
        tempString.concat(c);
    }
    else
    {
      if(millis()-t>timeOut*1000)ok=1;
    }
  }
  return(tempString);
}



void sendData(String myData) {
  // if there's a successful connection:
  digitalWrite(greenLED, HIGH);



  if (client.connect(server, 80)) {
    Serial.print(F("Logging data to COSM..."));
    // send the HTTP PUT request:
    client.print(F("PUT /v2/feeds/"));
    client.print(FEEDID);
    client.println(F(".csv HTTP/1.1"));
    client.println(F("Host: api.cosm.com"));
    client.print(F("X-ApiKey: "));
    client.println(APIKEY);
    client.print(F("User-Agent: "));
    client.println(USERAGENT);
    client.print(F("Content-Length: "));

    // calculate the length of the sensor reading in bytes:
    // 8 bytes for "sensor1," + number of digits of the data:
    int thisLength = myData.length();

    client.println(thisLength);

    // last pieces of the HTTP PUT request:
    client.println("Content-Type: text/csv");
    client.println("Connection: close");
    client.println();

    // here's the actual content of the PUT request:
    client.println(myData);

    if(waitForResposeContaining("200 OK",30)){
      Serial.println(F("200 OK - Successfully Logged."));
      delay(5000);
      drainInternet(true);
    }
    else
    {
      Serial.println(F("Did not receive 200 OK - NOT Logged."));
      drainInternet(true);
    }
    lastConnectionTime = millis();
  }
  else {
    // if you couldn't make a connection:
    Serial.println(F("connection failed. Disconnecting."));

    client.stop();
  }
  // note the time that the connection was made or attempted:


}


// This method calculates the number of digits in the
// sensor reading.  Since each digit of the ASCII decimal
// representation is a byte, the number of digits equals
// the number of bytes:

int getLength(int someValue) {
  // there's at least one byte:
  int digits = 1;
  // continually divide the value by ten,
  // adding one to the digit count for each
  // time you divide, until you're at 0:
  int dividend = someValue /10;
  while (dividend > 0) {
    dividend = dividend /10;
    digits++;
  }
  // return the number of digits:
  return digits;
}




Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im going to check now, but I think it might be the heat off the Arduino. Ill try getting some leads and extend the sensor away front he board. Putting it on its side has seemed to make a difference (around 7:40AM)

Update: Turns out that the Ardueno was creating heat, which rose up and affected the sensor. I have extended the sensor off tot he side by 3 to 4 inches, and I believe the readings are now pretty accurate.

« Last Edit: June 02, 2012, 08:10:03 am by JeremyLaurenson » Logged

Pages: [1]   Go Up
Jump to: