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
}


Wednesday, March 20, 2013

Testing the Arduino TMP102

Documentation by Andrew Samuels

Description


TMP102 - Temperature Sensor
Specs
  • 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

Goals

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

Results

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 Bildr.com, 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
//////////////////////////////////////////////////////////////////

#include 
int tmp102Address = 0x48;

void setup(){
  Serial.begin(9600);
  Wire.begin();
}

void loop(){

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

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

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

float getTemperature(){
  Wire.requestFrom(tmp102Address,2); 

  byte MSB = Wire.read();
  byte LSB = Wire.read();

  //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);
      thisPin++;
      
      //set the LED with ledState
      if (thisPin == 14){
      digitalWrite(startPin, HIGH);
      thisPin = startPin;
    }
      else{
      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.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.print(temperatureC);
Serial.println(" degrees C");

delay(1000);

}