Wednesday, April 10, 2013

Humidity Sensor Testing HIH-4030

Documentation by Andrew Samuels

Description

Honeywell HIH-4030 - Humidity Sensor
  • Factory Calibrated
Operation
  • Insulating Film in a Capacitor System
  • Voltage Difference
Connections
  • 5 V
  • OUT
  • Analog Voltage input to digital voltage output
  • GND

Goals

Measure the humidity of the environment using the HIH-4030.

Results

The HIH-4030 humidity sensor has been tested and is working as anticipated. Documentation on the HIH-4030 can be found on Bildr: Sensing Humidity With The HIH-4030 + Arduino. We connected the HIH-4030 to the arduino pins specified, uploaded the code, and took video of the results.

The code

/* HIH-4030 humidity sensor
UVC PHY420
*/

int HIH4030_Pin = A0; //analog pin 0

void setup(){

  Serial.begin(9600);
}

void loop(){

  //To properly calculate relative humidity, we need the temperature.
  float temperature = 25; //replace with a thermometer reading if you have it
  float relativeHumidity = getHumidity(temperature);

  Serial.println(relativeHumidity);

  delay(100); //just here to slow it down so you can read it
  
}

float getHumidity(float degreesCelsius){
  //caculate relative humidity
  float supplyVolt = 5.0;

  // read the value from the sensor:
  int HIH4030_Value = analogRead(HIH4030_Pin);
  float voltage = HIH4030_Value/1023. * supplyVolt; // convert to voltage value

  // convert the voltage to a relative humidity
  // - the equation is derived from the HIH-4030/31 datasheet
  // - it is not calibrated to your individual sensor
  //  Table 2 of the sheet shows the may deviate from this line
  float sensorRH = 161.0 * voltage / supplyVolt - 25.8;
  float trueRH = sensorRH / (1.0546 - 0.0026 * degreesCelsius); //temperature adjustment 

  return trueRH;
}

Wednesday, April 3, 2013

Data Logger Testing

Documentation by Andrew Samuels

Description

Getting the data logger working was one of the more formidable tasks. Three of the digital pin connections required pull down resistors to lower the voltages because the digital pins on the Arduino output 5V, but our data logger operates on 3.3V. The documentation for the SD-MMC breakout board can be difficult to decipher. It helps to read the comments on the SparkFun page for BOB-11403

Goals

We want our sensor data to write to the SD Card mounted on the SD-MMC breakout board

Results

It works. Watch the video below.

The code for the data logger is from GarageLab Tutorial How to use SD Card with Arduino

The code:

// Ported to SdFat from the native Arduino SD library example by Bill Greiman
// On the Ethernet Shield, CS is pin 4. SdFat handles setting SS
const int chipSelect = 10;
/*
 SD card read/write
  
 This example shows how to read and write data to and from an SD card file  
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 created   Nov 2010
 by David A. Mellis
 updated 2 Dec 2010
 by Tom Igoe
 modified by Bill Greiman 11 Apr 2011
 This example code is in the public domain.
   
 */
//#include 
#include 
//SoftwareSerial mySerial(10,11);
#include 
SdFat sd;
SdFile myFile;

void setup() {
  Serial.begin(9600);
  while (!Serial) {}  // wait for Leonardo
  Serial.println("Type any character to start");
  while (Serial.read() <= 0) {}
  delay(400);  // catch Due reset problem
  
  // Initialize SdFat or print a detailed error message and halt
  // Use half speed like the native library.
  // change to SPI_FULL_SPEED for more performance.
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();

  // open the file for write at end like the Native SD library
  if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
    sd.errorHalt("opening test.txt for write failed");
  }
  // if the file opened okay, write to it:
  Serial.print("Writing to test.txt...");
  myFile.println("testing 1, 2, 3.");

  // close the file:
  myFile.close();
  Serial.println("done.");

  // re-open the file for reading:
  if (!myFile.open("test.txt", O_READ)) {
    sd.errorHalt("opening test.txt for read failed");
  }
  Serial.println("test.txt:");

  // read from the file until there's nothing else in it:
  int data;
  while ((data = myFile.read()) >= 0) Serial.write(data);
  // close the file:
  myFile.close();
}

void loop() {
  // nothing happens after setup
}