Anda di halaman 1dari 10

LAPORAN UAS

MIKROKONTROLER

Kontrol Kipas Angin Otomatis Menggunakan


Microcontroller ATmega16 Berbasis Sensor Suhu LM35

Nama : Feri Dwianto


Nim : 20151330034

Jurusan Pendidikan Teknik Elektro

Fakultas Teknik

Universitas Muhammadiyah Surabaya


1.

1 U2 U1
9 22
RESET PC0/SCL
23
PC1/SDA
1 13 24
23.0 XTAL1 PC2/TCK
2 12 25
XTAL2 PC3/TMS
26
PC4/TDO
2 40 27
VOUT PA0/ADC0 PC5/TDI
39 28
PA1/ADC1 PC6/TOSC1
38 29
PA2/ADC2 PC7/TOSC2
37
PA3/ADC3
3 LM35 36 14
PA4/ADC4 PD0/RXD
35 15
PA5/ADC5 PD1/TXD
34 16
PA6/ADC6 PD2/INT0
33 17
U3 PA7/ADC7 PD3/INT1
8 16 18
PD4/OC1B
1 19
PB0/T0/XCK PD5/OC1A
0.00 3 2 2 20
OUT1 VS VSS IN1 PB1/T1 PD6/ICP1
6 7 3 21
OUT2 IN2 PB2/AIN0/INT2 PD7/OC2
1 4
EN1 PB3/AIN1/OC0
5
PB4/SS
6
PB5/MOSI
9 7 32
EN2 PB6/MISO AREF
11 10 8 30
OUT3 IN3 PB7/SCK AVCC
14 15
OUT4 GND GND IN4
D2 ATMEGA16
LED-BIGY
L293D

C1
1

22pf

X1
CRYSTAL
C2
2

22pf

Gambar keadaan suhu dibawah 30 celcius


1 U2 U1
9 22
RESET PC0/SCL
23
PC1/SDA
1 13 24
34.0 XTAL1 PC2/TCK
2 12 25
XTAL2 PC3/TMS
26
PC4/TDO
2 40 27
VOUT PA0/ADC0 PC5/TDI
39 28
PA1/ADC1 PC6/TOSC1
38 29
PA2/ADC2 PC7/TOSC2
37
PA3/ADC3
3 LM35 36 14
PA4/ADC4 PD0/RXD
35 15
PA5/ADC5 PD1/TXD
34 16
PA6/ADC6 PD2/INT0
33 17
U3 PA7/ADC7 PD3/INT1
8 16 18
PD4/OC1B
1 19
PB0/T0/XCK PD5/OC1A
-192 3 2 2 20
OUT1 VS VSS IN1 PB1/T1 PD6/ICP1
6 7 3 21
OUT2 IN2 PB2/AIN0/INT2 PD7/OC2
1 4
EN1 PB3/AIN1/OC0
5
PB4/SS
6
PB5/MOSI
9 7 32
EN2 PB6/MISO AREF
11 10 8 30
OUT3 IN3 PB7/SCK AVCC
14 15
OUT4 GND GND IN4
D2 ATMEGA16
LED-BIGY
L293D

C1
1

22pf

X1
CRYSTAL
C2
2

22pf

Gambar ketika suhu diatas 30celcius


Prinsip Kerja Kipas angin Otomatis
Kipas angin otomatis ini digerakkan melalui sensor suhu, pada rangkaian digunakan LM35 sebagai
alat sensor suhu.
LM35 dihubungkan pada ATmega16 yang mana nantinya pada ATmega16 di inputkan program yang telah
dibuat agar dapat mengaktifkan kipas angin jika suhu yang terbaca adalah besar sama dengan 30 derajat celcius,
jika suhu berada di bawah 30 celcius maka kipas angin tidak akan hidup. Komponen yang digunakan sebagai
kipas angin pada rangkaian adalah Motor DC, Output dari AT mega16 dihubungkan pada L293D yang nantinya
saat Suhu berada pada 30 derajat celcius atau lebih akan memutar Motor DC. Pada rangkaian juga dipasang
indikator lain yaitu LED yang akan berkedap kedip jika suhu yang terbaca oleh LM35 adalah besar sama dengan
30 derajat celcius.
/*****************************************************
This program was produced by the
CodeWizardAVR V2.04.5b Evaluation
Automatic Program Generator
© Copyright 1998-2009 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date : 10/12/2012
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:

Chip type : ATmega16


Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size :0
Data Stack size : 256
*****************************************************/

#include <mega16.h>
#include <delay.h>
#include <stdlib.h>

int temp;
float vin;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{

#define ADC_VREF_TYPE 0x00

// Read the AD conversion result


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;
}
// Declare your global variables here

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

// Input/Output Ports initialization


// Port A initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=In Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=T State0=T
PORTB=0x00;
DDRB=0xFF;

// Port C initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=T
PORTC=0x00;
DDRC=0x01;

// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 15.629 kHz
// Mode: Fast PWM top=FFh
// OC0 output: Inverted PWM
TCCR0=0x7C;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization


// INT0: On
// INT0 Mode: Rising Edge
// INT1: Off
// INT2: Off
GICR|=0x40;
MCUCR=0x03;
MCUCSR=0x00;
GIFR=0x40;

// Timer(s)/Counter(s) Interrupt(s) initialization


TIMSK=0x00;

// Analog Comparator initialization


// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC Clock frequency: 500,125 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: Free Running
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0xA3;
SFIOR&=0x1F;
//PORTB.6=0;
// Global enable interrupts
#asm("sei")
PORTC.0=1;
while (1)
{
// Place your code here

temp = read_adc(0);
vin=(float)temp*500/1024;

OCR0=0;
if(vin>30)
{
PORTB.0=1;
delay_ms(30);
PORTB.0=0;
delay_ms(30);
PORTB.6=1;
}
if(vin<30)
{
PORTB.6=0;
PORTB.0=0;
} ;
};
}
Flow chart
READ

Perintah “Serial.read()” digunakan untuk membaca data dari serial port. Berikut contoh penulisan
perintah “Serial.read()”

int incomingByte = 0; // for incoming serial data

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600
bps
}

void loop() {

// send data only when you receive data:


if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

// say what you got:


Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}

WRITE

Perintah “Serial.write()” digunakan untuk membaca binner dari serial port. Data ini dikirim dalam
bentuk byte atau deretan data byte. Contoh penulisan perintah “Serial.write()”

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

void loop(){
Serial.write(45); // send a byte with the value 45

int bytesSent = Serial.write(“hello”); //send the string “hello”


and return the length of the string.
}