Wednesday, April 10, 2013

Humidity Sensor Testing HIH-4030

Documentation by Andrew Samuels


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


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


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

int HIH4030_Pin = A0; //analog pin 0

void setup(){


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);


  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


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


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


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.
//SoftwareSerial mySerial(10,11);
SdFat sd;
SdFile myFile;

void setup() {
  while (!Serial) {}  // wait for Leonardo
  Serial.println("Type any character to start");
  while ( <= 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 (!"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:

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

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

void loop() {
  // nothing happens after setup

Wednesday, March 20, 2013

Testing the Arduino TMP102

Documentation by Andrew Samuels


TMP102 - Temperature Sensor
  • Accurate: -40 – 125 oC
  • Operating: -55 – 150 oC
  • 0.0625 oC Resolution
  • 1.4 – 3.6 V Input
  • 10 µA
Thermal Resistivity
  • 260 oC/W

I2C bus Interface


The goal of the test is to read the temperature of the h1surrounding environment with the TMP102 component.


This was our second temperature component tested on our breadboard. Watch the video to see the circuit and results of the test.

Source for the code is from, How's the weather? TMP102 + Arduino
The code:
//Arduino 1.0+ Only
//Arduino 1.0+ Only

//©2011 bildr
//Released under the MIT License - Please reuse change and share
//Simple code for the TMP102, simply prints temperature via serial

int tmp102Address = 0x48;

void setup(){

void loop(){

  float celsius = getTemperature();
  Serial.print("Celsius: ");

  float fahrenheit = (1.8 * celsius) + 32;
  Serial.print("Fahrenheit: ");

  delay(200); //just here to slow down the output. You can remove this

float getTemperature(){

  byte MSB =;
  byte LSB =;

  //it's a 12bit int, using two's compliment for negative
  int TemperatureSum = ((MSB << 8) | LSB) >> 4; 

  float celsius = TemperatureSum*0.0625;
  return celsius;

Monday, January 28, 2013

Intro to Arduino - Two Tasks : #1) 8 Sequentially Blinking LEDs #2) Ambient Temperature Sensor

Documentation by Andrew Samuels

We completed two tasks assigned to us in our introduction to the Arduino microcontroller. The first task was to instruct the Arduino to blink 8 LEDs in sequence without the Arduino programming language's delay() function. The second task was to measure the ambient temperature sensor using the TMP36 sensor. Arduino code is included for both tasks.

#1) 8 Blinking LEDs in Sequence

/* 8 blinking LEDS w/ no delay func
hopefully this fixes the random LED problem

//int timer = 100; //higher number, slower timing

//changing variables
int ledState = LOW; //used to set the LED
long previousMillis = millis(); //will store last time LED was updated

long interval = 500; //interval at which to blink
int thisPin = 5;
int startPin = 6;
void setup(){
//initialize each pin as output
for(int thisPin = 6; thisPin < 13; thisPin++){
    pinMode(thisPin, OUTPUT);

void loop(){
//loop from the lowest pin to the highest pin
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval){
      //save the last time you blinked the LED
      previousMillis = currentMillis;
      digitalWrite(thisPin, LOW);
      //set the LED with ledState
      if (thisPin == 14){
      digitalWrite(startPin, HIGH);
      thisPin = startPin;
      digitalWrite(thisPin, HIGH);
      //If LED is off turn it on, if on..turn off

#2) Ambient Temperature Sensor (TMP36)

/* Temperature Sensor with TMP36
Measures the ambient temperature of the room.

int sensPin = 0; //analog pin for TMP36

void setup(){
  Serial.begin(9600); //initialize serial connection with computer
     //to view results

void loop(){
//get the voltage reading from the temp sensor
int reading = analogRead(sensPin);

//convert reading to voltage
float voltage = reading * 5.0;
voltage /= 1024.0; //divide and assign voltage

//print voltage
Serial.println(" volts");

//convert voltage to tempurature in Celsius, then print
float temperatureC = (voltage - 0.5) * 100; //convert 10mV per degree
//with 500 mV offset to degrees 
Serial.println(" degrees C");