Postingan kali ini berjudul Kendali Kecepatan Kipas Menggunakan Mikrokontroler dan Sensor Suhu LM35. Proyek kali ini yaitu kita akan mengatur kecepatan putar kipas berdasarkan sensor suhu LM35. Ketika suhu yang diterima sensor suhu LM35 tinggi maka kecepatan putar kipas akan tinggi, ketika suhu menurun maka kecepatan putar kipas juga akan menurun. Untuk skematiknya bisa dilihat dibawah ini:
untuk programnya bisa dilihat berikut ini,
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include "lcd.h"
void delay_ms(int ms)
{for (int i=0;i<ms;i++){_delay_ms(1);}}
void adc_init(void)
{
ADMUX= (0<<REFS1)|(1<<REFS0)| //Tegangan referensi
(0<<ADLAR)| //Format hasil konversi
(0<<MUX3)|(0<<MUX2)|(0<<MUX1)|(0<<MUX0);//PIN INPUT ADC
ADCSRA= (1<<ADEN)| //1= ADC enable
(0<<ADIE)| //1= interupsi ADC
(1<<ADPS2)|(1<<ADPS1)|(0<<ADPS0);
}
int baca_suhu(void)
{
adc_init();
_delay_ms(20);
ADCSRA |=(1<<ADSC);
loop_until_bit_is_set(ADCSRA, ADIF); //cek ADIF =1?
ADCSRA |=(1<<ADIF);
return ADCW;
}
int main (void)
{
lcd_init();
delay_ms(10);
DDRD=0xFF;
PORTD=0x00;
TCCR1A= (1<<WGM11)|(1<<WGM10)|
(1<<COM1A1)|(0<<COM1A0)|
(1<<COM1B1)|(0<<COM1B0);
TCCR1B= (0<<WGM13)|(1<<WGM12)|
(0<<CS12)|(0<<CS11)|(1<<CS10);
TCNT1=0x0000;
OCR1A=0;
OCR1B=0;
sei( );
while(1)
{
if (((baca_suhu()/2)-10)<0)
{
clrscr();
goto_xy(1,1);
printf("Suhu = %4d ",(baca_suhu()/2)-10);
LCD(223);
printf("C");
goto_xy(2,1);
printf("SANGAT RENDAH");
delay_ms(500);
OCR1A=0;
}
else if(((baca_suhu()/2)-10)>0&&((baca_suhu()/2)-10)<30)
{
clrscr();
goto_xy(1,1);
printf("Suhu = %4d ",(baca_suhu()/2)-10);
LCD(223);
printf("C");
goto_xy(2,1);
printf("RENDAH");
delay_ms(500);
OCR1A=250;
}
else if (((baca_suhu()/2)-10)>30&&((baca_suhu()/2)-10)<60)
{
clrscr();
goto_xy(1,1);
printf("Suhu = %4d ",(baca_suhu()/2)-10);
LCD(223);
printf("C");
goto_xy(2,1);
printf("SEDANG");
delay_ms(500);
OCR1A=500;
}
else if (((baca_suhu()/2)-10)>60&&((baca_suhu()/2)-10)<100)
{
clrscr();
goto_xy(1,1);
printf("Suhu = %4d ",(baca_suhu()/2)-10);
LCD(223);
printf("C");
goto_xy(2,1);
printf("TINGGI");
delay_ms(500);
OCR1A=750;
}
else if (((baca_suhu()/2)-10)>100)
{
clrscr();
goto_xy(1,1);
printf("Suhu = %4d ",(baca_suhu()/2)-10);
LCD(223);
printf("C");
goto_xy(2,1);
printf("SANGAT TINGGI");
delay_ms(500);
OCR1A=1000;
}
}
}
atau silahkan download proyek ini disini
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include "lcd.h"
void delay_ms(int ms)
{for (int i=0;i<ms;i++){_delay_ms(1);}}
void adc_init(void)
{
ADMUX= (0<<REFS1)|(1<<REFS0)| //Tegangan referensi
(0<<ADLAR)| //Format hasil konversi
(0<<MUX3)|(0<<MUX2)|(0<<MUX1)|(0<<MUX0);//PIN INPUT ADC
ADCSRA= (1<<ADEN)| //1= ADC enable
(0<<ADIE)| //1= interupsi ADC
(1<<ADPS2)|(1<<ADPS1)|(0<<ADPS0);
}
int baca_suhu(void)
{
adc_init();
_delay_ms(20);
ADCSRA |=(1<<ADSC);
loop_until_bit_is_set(ADCSRA, ADIF); //cek ADIF =1?
ADCSRA |=(1<<ADIF);
return ADCW;
}
int main (void)
{
lcd_init();
delay_ms(10);
DDRD=0xFF;
PORTD=0x00;
TCCR1A= (1<<WGM11)|(1<<WGM10)|
(1<<COM1A1)|(0<<COM1A0)|
(1<<COM1B1)|(0<<COM1B0);
TCCR1B= (0<<WGM13)|(1<<WGM12)|
(0<<CS12)|(0<<CS11)|(1<<CS10);
TCNT1=0x0000;
OCR1A=0;
OCR1B=0;
sei( );
while(1)
{
if (((baca_suhu()/2)-10)<0)
{
clrscr();
goto_xy(1,1);
printf("Suhu = %4d ",(baca_suhu()/2)-10);
LCD(223);
printf("C");
goto_xy(2,1);
printf("SANGAT RENDAH");
delay_ms(500);
OCR1A=0;
}
else if(((baca_suhu()/2)-10)>0&&((baca_suhu()/2)-10)<30)
{
clrscr();
goto_xy(1,1);
printf("Suhu = %4d ",(baca_suhu()/2)-10);
LCD(223);
printf("C");
goto_xy(2,1);
printf("RENDAH");
delay_ms(500);
OCR1A=250;
}
else if (((baca_suhu()/2)-10)>30&&((baca_suhu()/2)-10)<60)
{
clrscr();
goto_xy(1,1);
printf("Suhu = %4d ",(baca_suhu()/2)-10);
LCD(223);
printf("C");
goto_xy(2,1);
printf("SEDANG");
delay_ms(500);
OCR1A=500;
}
else if (((baca_suhu()/2)-10)>60&&((baca_suhu()/2)-10)<100)
{
clrscr();
goto_xy(1,1);
printf("Suhu = %4d ",(baca_suhu()/2)-10);
LCD(223);
printf("C");
goto_xy(2,1);
printf("TINGGI");
delay_ms(500);
OCR1A=750;
}
else if (((baca_suhu()/2)-10)>100)
{
clrscr();
goto_xy(1,1);
printf("Suhu = %4d ",(baca_suhu()/2)-10);
LCD(223);
printf("C");
goto_xy(2,1);
printf("SANGAT TINGGI");
delay_ms(500);
OCR1A=1000;
}
}
}
atau silahkan download proyek ini disini
penjelasan to be continued......
codingnnya gk sempurna ya mas ...
BalasHapus