Rabu, 10 April 2013

arduino with dht22 and iic lcd

hehehe.sperti biasa setelah mencoba alat dengan tampilan di serial monitor saya akan menampilkan-nya di iic lcd.......

untuk bahan yang diperlukan:
- arduino
- dht22
- iic lcd
- white board
- kabel jumper

dan programnya :


/*
  AM2302 Temperature / Humidity Sensor (DHT22)
 
  Current Code
  Created by Derek Erb 30/01/2013
  Modified 30/01/2013
 
  Requirement : Arduino + AM2302 sensor connected to pin 2
 
  DHT Library from:
  https://github.com/adafruit/DHT-sensor-library

  v0.03 Delays and formatting
  v0.02 Delay 3 seconds between readings
*/

#include "DHT.h"          // DHT & AM2302 library
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

// Version number
const float fVerNum = 0.03;

// Data pin connected to AM2302
#define DHTPIN 2

#define DHTTYPE DHT22       // DHT 22  (AM2302)

DHT dht(DHTPIN, DHTTYPE);   // LED pins

//////////////////////////////////////////////////////
//
// SETUP
//
void setup() {
  // Setup serial monitor
  Serial.begin(9600);
  lcd.init();                      // initialize the lcd

  // Print a message to the LCD.
  lcd.backlight();
 
  // Wait 3 seconds
  delay(3000);
  dht.begin();
}
 

void loop() {

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    lcd.println(F("Failed to read from DHT"));
  }
  else {
    lcd.print(F("Humidity: "));
    lcd.print(h);
    lcd.print(F(" %\t"));
    lcd.setCursor(0, 1);
    lcd.print(F("Tmprature: "));
    lcd.print(t);
    lcd.println(F(" C"));
  }
 
  // Wait 3 seconds
  delay(3000);
}

cara perangkaiannya....


maaf gambar agak jelek tapi pasti anda jelas-kan.........

setleh selesai perangkaian silahkan meng-upload programnya ke-arduino.....
dan ini untuk hasilnya:


oke selamat mencoba DAN MENGEMBANGKAN-NYA........
 GOOD LUCK....!!!!!!!!!!!

Tidak ada komentar:

Posting Komentar