Friday, February 22, 2013

Arduino humidity and temperature sensor with display

This post describes a little sensor - in the particular case humidity and temperature - which is read by the arduino and writes to an LCD display. Its a nice low cost solution for monitoring without computer and the arduino also allows you to hook actuators up.
So one thing you can realize is a dry box; every time the humidity rises, a valve opens the flow of dry air or nitrogen.

Here is a foto of the device. The box contains an arduino for reading the sensor and controlling the LCD panel. In addition a piezo buzzer gives an optional audible alarm:


Lets start with the humidity and temperature sensor:
This is a chipcap from GE  in analog mode - it delivers two output voltages that can be converted to relative humidity and temperature readings. The chip comes as a surface mount device, so soldering it on a breadboard is a bit tricky. The description contains a electric diagram for hooking it up.
Next, you need to feed the two analog voltages into your arduino, more precise into two AD converter inputs.

I chose to hook them up to A0 and A1 (lower right input row in the above photgraph). The chipcap also needs to be connected to the 5V and ground of the arduino to power it - see description. Pin 11 of the chipcap needs to be connected to 5V, pin 4 of the chipcap needs to be connected to the 5V via a 0.1 microF capacitance and to the arduino ground without a capacitance. That's it!

Now you need to connect the arduino to the LCD display, which I got from Sparkfun and which is compatible with Hitachi HD44780 driver in order to use the arduino LCD libraries.
Hook up the LCD to arduino according to the wiring diagram below.



The above is copied from the arduino LCD site .
Now that is done, you can upload the following code to your arduino and try the system out:
Arduino code:

/*
 Code that reads chipcap sensor and displays the rel. humidity and temperature on a 2x16 LCD display

 created 2012
 by Markus Guehr
 */
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into
int sensorValue[2]; //this array will hold the readouts
const int maxCounter=10;// how many averages during aquisition

// include the library code:
#include <LiquidCrystal.h>
#include <stdlib.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  analogReference(INTERNAL);
    // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // see if there's incoming serial data:
  //if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    //incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED and measure the sensor value:
    //if (incomingByte == 'H') {
      digitalWrite(ledPin, HIGH);
     
      //initialize the analog variables
      int sensorValue[]={0,0};
      for (int counter=1; counter<maxCounter+1; counter++){ 
        for (int sensorCounter=0; sensorCounter<2; sensorCounter++){
          sensorValue[sensorCounter] = sensorValue[sensorCounter] + analogRead(sensorCounter);
        delay(50); 
        }
    }
       for (int sensorCounter=0; sensorCounter<2; sensorCounter++){
         sensorValue[sensorCounter] = sensorValue[sensorCounter]/maxCounter;  
       }
      
      for (int sensorCounter=0; sensorCounter<1; sensorCounter++){
      Serial.print(sensorValue[sensorCounter]); //format in DEC -
      Serial.print("\t");
      }
      Serial.println(sensorValue[1]); //format in DEC -
      float humidity;
      float temperature;
      humidity=((float)sensorValue[1])/1023*1.1;//that is the voltage - reference is internal which means 1.1 V
      humidity=humidity*100;//according to chipcap manual
     
      temperature=((float)sensorValue[0])/1023*1.1;//that is the voltage - reference is internal which means 1.1 V
      temperature=temperature*200-50;//according to chipcap manual
     
      Serial.print(humidity); //format in DEC -
      Serial.print("\t");
      Serial.println(temperature); //format in DEC -
     
      if (humidity > 50){
        tone(8,100,100);//that is a buzzer connected to pin 8 of the arduino
      }
     
      lcd.clear();
      lcd.print("Rel.Hum.:");
      lcd.print(humidity);
      lcd.setCursor(0,1);
      lcd.print("Temp.:");
      lcd.print(temperature);
      lcd.print("deg C");
      digitalWrite(ledPin, LOW);//turn LED off! 
}

So now you should have the sensor values readable!
Please note - if you hook up a piezo buzzer on digital output 8 of the arduino, an alarm will be audible if you go above a certain threshold.
At this position you could also activate any other thing - like a purge valve.

No comments:

Post a Comment