Pembuatan Alat Bantu Stress Detector Menggunakan Sensor Hir333, GSR, dan DS18B20 Berbasis Mikrokontroler ATMega 8

Lampiran I
Rangkaian Lengkap Alat

Universitas Sumatera Utara

Lampiran II
Program Pada Alat
/*****************************************************
This program was produced by the
CodeWizardAVR V2.04.9 Evaluation
Automatic Program Generator
© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Date : 29/04/2016
Author : Freeware, for evaluation and non-commercial use only
Chip type
: ATmega8
Program type
: Application
AVR Core Clock frequency: 4,000000 MHz
Memory model

: Small
External RAM size
:0
Data Stack size
: 256
*****************************************************/
#include
#include
#include
#include
#include
#include
// DS1820 Temperature Sensor functions
#include
#include
#define ADC_VREF_TYPE 0x00
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Place your code here
}

unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
#define MAX_DEVICES 8
;
unsigned int GSR,HR,Temp1,Temp,G,t;
unsigned char buf[30];

Universitas Sumatera Utara

/* DS18B20 devices ROM code storage area,

9 bytes are used for each device
(see the w1_search function description),
but only the first 8 bytes contain the ROM code
and CRC */
unsigned char rom_codes[MAX_DEVICES][9];

/* allocate space for ROM codes of the devices
which generate an alarm */
unsigned char alarm_rom_codes[MAX_DEVICES][9];
void main(void)
{ //unsigned char i, j,devices,data;
unsigned char i, j, devices;
// Input/Output Ports initialization
// Port B initialization
PORTB=0x00;
DDRB=0x00;
// Port C initialization
PORTC=0x00;
DDRC=0x00;
// Port D initialization

PORTD=0x00;
DDRD=0x70;
// ADC initialization
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x82;
// 1 Wire Bus initialization
// 1 Wire Data port: PORTD
// 1 Wire Data bit: 2
w1_init();
devices=w1_search(0xf0,rom_codes);
j = 0;
// Alphanumeric LCD initialization
// RS - PORTB Bit 0
// RD - PORTD Bit 7
// EN - PORTB Bit 1
// D4 - PORTB Bit 2
// D5 - PORTB Bit 3
// D6 - PORTB Bit 4
// D7 - PORTB Bit 5
lcd_init(16);

// hitung mundur

Universitas Sumatera Utara

Temp=ds1820_temperature_10(&rom_codes[0][0])*10/8+250;
delay_ms(2000);
while (1)
{ lcd_clear();
Temp=(ds1820_temperature_10(&rom_codes[0][0])*10/8)+250;
xt:
t = 0;
G = 0;
lcd_clear(); lcd_gotoxy(0,0); lcd_putsf(" Mendeteksi...");
lcd_gotoxy(0,1); lcd_putsf(" Harap Tunggu ");
while(t < 3000)
{
while (HR < 100){HR = read_adc(5); delay_ms(10); t++;}
while (HR >= 100){HR = read_adc(5); delay_ms(10); t++; PORTD.6 = 1;
PORTD.5 = 1;}
PORTD.5 = 0;

PORTD.6 = 0;
G = G + 1;
/*
lcd_gotoxy(0, 0); lcd_printf("1"); delay_ms(1000);
lcd_gotoxy(0, 0); lcd_printf("30"); delay_ms(1000);
*/
}
HR = (G*2);
if((HR 180))
//bagian heart rate
{
lcd_clear();
lcd_putsf(" ERROR..."); delay_ms(2000);
goto xt;
}
while (1)
{
lcd_clear();
sprintf(buf,"HR:%i",HR);
lcd_gotoxy(10,0);

lcd_puts(buf);
//delay_ms(2000);
//lcd_clear();

GSR = read_adc(4);
if (GSR