Hi,
I'm pretty new to Arduino, and I am trying to read temperature and humidity using HYT 271(data sheet & Application note)and Arduino UNO.
The problem is that it gives me wrong data(56.55 for humidity, and 19.50 for temperature), and the values are not changing even though I change the testing environment.
I found the sample code on here
I also attached the sample code below.
When I pulled out one of the wires, it stopped working, so I am assuming that wiring was done well.
Any comment will be appreciated.
Thanks,
Hojae
// ********************************************
// Attention, this is unverified Code, Rev. 0.5
// Destinated only as first Information
// and to look that it works with a ARDUINO
// This code will be improved in future!
// ********************************************
//include Wire(>>I²C)-libary:
#include <Wire.h>
//set the adress of sensor:
int adress=0x28;
void setup()
{ //set arduino as master:
Wire.begin();
//set baudrate:
Serial.begin(38400);
/this code sets
databits:8 ; parity:ODD ; stopbits:2/
UCSR0C = B00111110;
}
void loop()
{ //declaration of variables:
unsigned int valuetempH=0;
unsigned int valuetempL=0;
unsigned int valuetemp=0;
unsigned int valuecapH=0;
unsigned int valuecapL=0;
unsigned int valuecap=0;
double endvaluecap=0;
double endvaluetemp=0;
//DataFetch(4 byte):
Wire.requestFrom(adress,4);
//wait for 4 bytes available:
if(Wire.available()>3)
//receive the databytes:
{valuecapH=Wire.receive();
valuecapL=Wire.receive();
valuetempH=Wire.receive();
valuetempL=Wire.receive();
Wire.endTransmission();
//mask the statusbits
valuecapH = (valuecapH&B00111111);
valuetempL= (valuetempL&B11111100);
/put together the highbytes and lowbytes
For this, the highbyte gets moved 8 bits higher/
valuecap = (valuecapH*256 + valuecapL);
/the temperature highbyte gets moved 6 bits
and the lowbyte 2 bits lower/
valuetemp = ((valuetempH)*64 + valuetempL/4);
//formate the values
endvaluecap=(double(valuecap))/163.83;
endvaluetemp=((double(valuetemp))/163.83)/2;
//output the values compatible with PCLog:
Serial.print(endvaluecap);
Serial.print("\t");
Serial.println(endvaluetemp);}
//in case of no receiving possible:
else
{Serial.println("no data");}
delay(100);
}