Page 1 of 1

humidity and temperature sensor combine source code

PostPosted: Tue Aug 26, 2014 12:40 am
by alung92
i had Temperature Sensor Module and Humidity Sensor Module both bought from cytron and connect to arduino main board. i tried combine this 2 sensor source code together. I expected will display temperature reading and humidity reading in RH% , but the output is quite weird. MAybe my source code, formula or somewhere got mistake. Someone please help me to correct it . i Need help !!!!. thanks a lot .
CODE: SELECT_ALL_CODE
float val = 0;
float RH = 0;

float temp;


void setup()
{
  Serial.begin(9600);
}

void loop()
{
  val = analogRead(0);
  delay(500);
  Serial.println(val);
  //RH = ((((val/1023)*5)-0.8)/3.1)*100;
  Serial.println(RH);
  RH = ((0,0004*20 + 0,149)*temp)-(0,0617*20 + 24,436);

  delay(500);             


temp = analogRead(3)/9.31;
Serial.print("TEMPRATURE = ");

Serial.print(temp);

Serial.print("*C");

Serial.println();

delay(1000);
 
}



output
CODE: SELECT_ALL_CODE
TEMPRATURE = 30.50*C
24.00
4109.22
TEMPRATURE = 30.50*C
23.00
4109.22
TEMPRATURE = 30.61*C
24.00
4109.22
TEMPRATURE = 30.61*C
24.00
4125.22
TEMPRATURE = 30.61*C
24.00
4125.22
TEMPRATURE = 30.50*C
24.00
4125.22
TEMPRATURE = 30.50*C
24.00
4109.22
TEMPRATURE = 30.50*C

Re: humidity and temperature sensor combine source code

PostPosted: Tue Aug 26, 2014 2:42 pm
by yonghui
I am quite confused with your code.

i see you use value that is not properly initialize to the reading of adc.

Re: humidity and temperature sensor combine source code

PostPosted: Tue Aug 26, 2014 3:02 pm
by alung92
I'm quite new in this field ,i'm trying and some code copy from other web page . Can u give me a example and guide line how to write code with this two sensor combine together. Thanks a lot .

Re: humidity and temperature sensor combine source code

PostPosted: Tue Aug 26, 2014 9:35 pm
by yonghui
i assume that Humidity sensor is connected AN0 and Temperature sensor is connected to AN3

word Temperature;
word Humidity;

void loop()
{
Humidity = analogRead(0);
Temperature =analogRead(3);
// do some calculation here to convert the humidity value to valid value then print it

// print Humidity
// print temperature

delay(500);

}