/*NYU ITP - Sensor Workshop - Tom Igoe (fall 2012)
 Datalogging: Manuela Donoso & Luca Shapiro

 Test code for the Humidity Sensor HIH-4030
 Based on the code by Adafruit:
 http://www.ladyada.net/learn/sensors/tmp36.html*/



int humidityPin = 1; // HIH-4030
int humidityReading = 0;
const int interval = 10*100; // the interval between sensor reads, in ms
long lastReadTime = 0;        // the last time you read the sensor, in ms


void setup() {
  Serial.begin(9600);
  Serial.println ("Humidity:"); 
  Serial.println ("read \t volt \t %"); // humidity readings, voltage & %
}

void loop() {
  // get the current time in ms:
  long currentTime = millis();
  if (currentTime > lastReadTime + interval) {

    // READ HUMIDITY
    humidityReading = analogRead(humidityPin);
    // Serial.println("Humidity Reading:"); 
    Serial.print(humidityReading);
    float humidityVoltage = humidityReading * 5;
    humidityVoltage /= 1024.0;
    Serial.print("\t"); 
    Serial.print(humidityVoltage);

    // convert to percentage
    float humidityPercentage = humidityVoltage * 100;
    humidityPercentage /= 5;
    Serial.print("\t"); 
    Serial.println(humidityPercentage);

    lastReadTime = millis();
  }
}