Temperatur dan Humidity Sensor dengan AVR ( Atmega8535 )

Temperatur dan humidity sensor menggunakan modul DT-SENSE dan microcontroller Atmega8535

sensor temperatur dan humidity

code untuk Temperatur & Humidity Sensor  + Atmega 8535

/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.

Project : Temp-Humidity
Version : 1.0
Date    : 19/01/2011
Author  : Pccontrol
Company : pccontrol.wordpress.com
Comments: 

Chip type           : ATmega8535
Program type        : Application
Clock frequency     : 4,000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 128
*****************************************************/

#include <mega8535.h>
#include <delay.h>
// I2C Bus functions
#asm
   .equ __i2c_port=0x18 ;PORTB
   .equ __sda_bit=0
   .equ __scl_bit=1
#endasm  

#include <i2c.h>

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// I2C Bus initialization
i2c_init();

// LCD module initialization
lcd_init(16);
 lcd_gotoxy(0,0);
lcd_putsf(" YAMAMOTO Corp.");
lcd_gotoxy(0,1);
lcd_putsf("T:    .C");
lcd_gotoxy(9,1);
lcd_putsf("H:    .%");
 delay_ms(100);
// Global enable interrupts
#asm("sei")

while (1)
      { 

      // Place your code here
         unsigned char temp1,temp2;
       unsigned int temperatur,humidity;  

         i2c_start();           // Start Condition
         i2c_write(0xE0);       // Tulis ke modul DT-SENSE
         i2c_write(0x00);       // Perintah baca temperatur dengan resolusi 0,1
         i2c_stop();            // Stop Condition

         delay_ms(100);         // delay 100 ms

         i2c_start();           // Start Condition
         i2c_write(0xE1);       // Baca ke modul DT-SENSE
         temp1 = i2c_read(1);
         temp2 = i2c_read(0);
         i2c_stop();            // Stop Condition

         temperatur = (unsigned int)temp1*256 + temp2;
         temperatur -= 400; 

         lcd_gotoxy(2,1);
         lcd_putchar(temperatur/1000 %10 + 0x30); //5
         lcd_putchar(temperatur/100  %10 + 0x30); //1
         lcd_putchar(temperatur/10   %10 + 0x30); //3
         lcd_putchar('.');
         lcd_putchar(temperatur      %10 + 0x30); //5
         delay_ms(300);   

         i2c_start();           // Start Condition
         i2c_write(0xE0);       // Tulis ke modul DT-SENSE
         i2c_write(0x02);       // Perintah baca kelembaban dengan resolusi 0,1
         i2c_stop();            // Stop Condition

         delay_ms(100);          // delay 100 ms

         i2c_start();           // Start Condition
         i2c_write(0xE1);       // Baca ke modul DT-SENSE
         temp1 = i2c_read(1);
         temp2 = i2c_read(0);
         i2c_stop();            // Stop Condition

         humidity = (unsigned int)temp1*256 + temp2;

          lcd_gotoxy(11,1);
         lcd_putchar(humidity/1000 %10 + 0x30);
         lcd_putchar(humidity/100  %10 + 0x30);
         lcd_putchar(humidity/10   %10 + 0x30);
         lcd_putchar('.');
         lcd_putchar(humidity      %10 + 0x30);

         delay_ms(250);    

      };
}

referensi:
- http://www.sensirion.com/en/pdf/product_information/Datasheet-humidity-sensor-SHT1x.pdf
- DT-Sense SHT10 manual
Advertisements

About pccontrol

Berisi Tutorial Menggunakan PC untuk mengontrol Peralatan dengan cara mudah & praktis.

Posted on 27/04/2011, in Contoh-contoh Aplikasi. Bookmark the permalink. 2 Comments.

  1. cara settingan cvavr gmana ya???

  2. kalau menggunakan bascom avr gmana y ? tolong pencerahan..thx

Komentar ,Saran atau Pertanyaan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: