I found a humidity sensor that I thought about using in a project. After some internet searching I did not find a lot about it other than a data sheet and some old forum posts from abou 2 years ago.
I was looking to read the sensor output but I couldn't find anything that was already written. I'm guessing that there are not a lot of these in general circulation or at least not that Arduino folks are using anyway.
First off, here is a link to the datasheet for it. HSU-07 datasheet
The very last page shows the voltage/humidity graph, and it's not linear, so I wasn't sure how to work that out properly, so I just used map() to do it. It's far from perfect, I'm not sure it even works. If anyone knows how to improve the mapping so that it's more accurate, I would appreciate knowing how to do that.
If nothing else, there is more information here for the next person to stumble upon in another couple of years that might help them out or at least give them a place to start.
Here is my sketch:
// HSU-07 Humidity sensor
// The HSU sensors are humidity only, they do not measure temperature
// HSU-06 Sensor can read between 10% and 90% RH
// HSU-07 Sensor can read between 20% and 90% RH
int sensorPin = 0; //Set the sensor to the analog input pin
void setup() {
// Init serial output
Serial.begin(9600);
}
void loop() {
// Read the input from the humidity sensor:
int sensorValue = analogRead(sensorPin);
// Convert the analog reading (which goes from 0 - 1024) to a voltage (0 - 3.3V):
float voltage = sensorValue * (3.3 / 1024);
// Convert the voltage to Humidity
// Typical ranges:
// 0.5V = 10%
// 1.0V = 22%
// 1.5V = 32%
// 2.0V = 50%
// 2.5V = 75%
// 2.7V = 90%
float humidity = map(voltage,0.5, 2.7, 10, 90);
//Print out the values for voltage and humidity:
Serial.print("Humidity: ");
Serial.println(humidity);
}
0.5v is the lowest value that the sensor will return.
2.7v is the highest value it will return.
We want that mapped to values between 10 and 90.
This was returning 50 when I ran it and my other sensors were reading ~53% so it was somewhat close to the expected value. I know that this is not super accurate, but I don't know how to map values along a curve and that would be the only way I know of to make it any more accurate.
There might be two variants of this sensor, one with a temp output (on the fourth pin) and one without. I've seen images with three wires and images with four wires connected and it's often labeled as being a temperature and humidity sensor. All images show four pins regardless of how it's labeled. The fourth pin is not mentioned in the datasheet and there is no reference to temperature in the datasheet.
On the sensor that I have the fourth pin doesn't seem to have any output with respect to ground. It does have something when referenced to the humidity pin or the vin pin. So it will take some further investigation to see how to read it, assuming the temperature output actually does anything useful on the sensor that I have.
Lets find the value corresponding to a reading of 1.0V (call this Vin)
Its more than RH20% (0.9V) and less than RH30% (1.3V)
the change in RH (30% - 20%) (call this dRH) is 10
the change in V (V30 - V20) is (1.3 - 0.9) (call this dV) is 0.4
so we take the 0.9V reading for RH20% and add on a bit that we work out like this:
RHdiff = ((Vin - V(20)) / dV ) * dRH so RHdiff = ((1.0 - 0.9) /0.4) * 10
RHdiff = (0.1 /0.4) * 10 = 2.5
So the RH for a Vin of 1.0V is 20% + 2.5% = 22.5%
It seems complicated but its dead easy to implement.