SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
User avatar
By Stuart.W
#194380
Hi Kids;
I'm building a Arduino Uno v3 based Refrigeration Shed Environmental Controller for, wait for it,... my refer shed.....!
I have multiple problems but, that's for a different board.

What I would like to do is to connect two SEN-10167 [HRT03] sensors to the Arduino Uno v3, one indoors and one outdoors.

How do I code this? I know I need to commit an I/O pin to each HRT03, done. Now how is the HRT03 Library called for the two devices? I assume I only need one HRT03 Object ([RHT03 rth;] - Yes?). So then I'll use a subroutine (function) to call the RHT03 with me passing the function the RHT03 pin number for the device of interest. Sound right? (I'll provide the subroutine if we need to see the proposed code.)

A 2nd problem is when I down load the SparkFun_RHT03.h library it doesn't seem to be in the right format for an Arduino IDE library. What the heck am I missing?

Thanks for your time with this. :) KD0NSU
By jbike
#194489
The I/O pin is right, 2 are required. But call two instances of RHT03, like below:
(note create a RHT03-master folder within the Arduino library folder and unzip the Arduino src files into that folder see https://learn.adafruit.com/adafruit-all ... -a-library )

// Include the library:
#include <SparkFun_RHT03.h>

/////////////////////
// Pin Definitions //
/////////////////////
const int RHT03_DATA_PIN = 4; // RHT03 data pin
const int RHT03_DATA_PIN2 = 5; // RHT03 data pin2
///////////////////////////
// RHT03 Object Creation //
///////////////////////////
RHT03 rht; // This creates a RTH03 object, which we'll use to interact with the sensor
RHT03 rht2; // Second instance of a RHT03 object.
void setup()
{
Serial.begin(9600); // Serial is used to print sensor readings.

// Call rht.begin() to initialize the sensor and our data pin
rht.begin(RHT03_DATA_PIN);
rht2.begin(RHT03_DATA_PIN2);
}

void loop()
{
// Call rht.update() to get new humidity and temperature values from the sensor.
int updateRet = rht.update();
int updateRet2 = rht2.update();

// If successful, the update() function will return 1.
// If update fails, it will return a value <0
if (updateRet == 1)
{
// The humidity(), tempC(), and tempF() functions can be called -- after
// a successful update() -- to get the last humidity and temperature
// value
float latestHumidity = rht.humidity();
float latestTempC = rht.tempC();
float latestTempF = rht.tempF();

// Now print the values:
Serial.println("Humidity: " + String(latestHumidity, 1) + " %");
Serial.println("Temp (F): " + String(latestTempF, 1) + " deg F");
Serial.println("Temp (C): " + String(latestTempC, 1) + " deg C");
}
if (updateRet2 == 1)
{
// The humidity(), tempC(), and tempF() functions can be called -- after
// a successful update() -- to get the last humidity and temperature
// value
float latestHumidity = rht2.humidity();
float latestTempC = rht2.tempC();
float latestTempF = rht2.tempF();

// Now print the values:
Serial.println("Humidity2: " + String(latestHumidity, 1) + " %");
Serial.println("Temp2 (F): " + String(latestTempF, 1) + " deg F");
Serial.println("Temp2 (C): " + String(latestTempC, 1) + " deg C");
}
else
{
// If the update failed, try delaying for RHT_READ_INTERVAL_MS ms before
// trying again.
delay(RHT_READ_INTERVAL_MS);
}

delay(1000);
}