Membuat Digital FM Dengan Arduino
Posted by Tempatbelajararduino
» Tuesday, February 21, 2017
Membuat Digital FM Dengan Arduino,~ Selamat berjumpa lagi di www.tempatbelajararduino.com
Kali ini kita akan membuat project membuat Radio FM dengan Arduino, Asik bukan mengenal arduino lebih dalam kita bisa mengkreasikan proyek proyek yang keren dan sederhana dengan
Microcontroller Arduino ini, Oke di sini kita juga akan pake LCD 16x2 Untuk menampilkan Berbagai menu pilihan untuk menseting radionya, Baiklah saya tidak perlu panjang lebar lagi langsung saja.
Berikut komponen yang di perlukan :
- Modul Arduino Uno / nano/promicro
- LCD16x2 Warna silahkan sesuka anda
- LED indikator flashing dan alarm
- 2 buah tombol push button untuk seting radia
- Modul Fm tunner TEA5767
- 4 buah rasistor 1K
- 2 buah resistor 220 Ohm
- Kabel jumper secukupnya
Modul arduino uno
|
Modul arduino uno
|
|
Modul Fm TEA5767 |
LDC 16x2
|
LDC 16x2 |
Rangkaian Lengkap
|
Rangkaian Lengkap |
// Membuat Jam dan Radio FM TEA5767
// LIKNO01
// Programmer Suparno, S.Pd, M.Pd
// 24/01/2015
#include < avr/io.h>
#include < avr/interrupt.h>
#include < LiquidCrystal.h>
#include < Wire.h>
#include < EEPROM.h>
#define debug 0
byte LedPin=8;
byte LedPin2=9;
byte e1Pin=12;
byte e2Pin=13;
byte jam,menit,detik;
byte Ajam,Amenit,Adetik;
byte flag=1;
int sleep;
byte alarm; //0-1 alarm ON, 3-alarm OFF
char VARI[20];
int z,zz;
byte bz;
unsigned char frequencyH = 0;
unsigned char frequencyL = 0;
unsigned int frequencyB;
double frequency = 0;
byte bfrequency;
double gfrequency;
byte rdata[7];
byte signal;
int reading;
char *menu[]={" ","SLEEP","MODE_MEMO","MODE_SCAN","MODE_DIAL","ALARM","MEMORY","LEVEL-SCAN","TIME"};
char *menu1[]={" ","DIAL","CH: ","SCAN"};//mymode
byte bmemory;
byte memo;
byte mymenu;
byte mymode;
byte mylevel;
byte flag2;
LiquidCrystal lcd(7,6,5,4,3,2);
void setup(){
Serial.begin(9600);
lcd.begin(16, 4);
Wire.begin();
pinMode(LedPin, OUTPUT);
pinMode(LedPin2, OUTPUT);
pinMode(e1Pin, INPUT);
pinMode(e2Pin, INPUT);
//==================================
lcd.setCursor(-4,2);
lcd.print("Radio FM Mikro");
lcd.setCursor(-4,3);
lcd.print("Prog. : Suparno");
//==================================
cli();
TCCR1A=0;
TCCR1B=0;
OCR1A=15624;
TCCR1B |= (1< TCCR1B |= (1< TCCR1B |= (1< TIMSK1=(1< sei();
mymenu=0;
mymode=2; //si queremos que cuando se encienda la radio este en modo Dial poner 1
mylevel=2;
sleep=0;
alarm=3;
memo=0;
flag2=0;
bfrequency = EEPROM.read(0);
frequency=875+bfrequency; //aslinya :875
frequency/=10;
setFrequency();
}
void loop()
{
if(!digitalRead(e1Pin))
{
mymenu++;
if(mymenu>8)mymenu=0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(menu[mymenu]);
if(flag2==1)mymenu=0;
flag2=0;
delay(100);
while(!digitalRead(e1Pin));
}
switch(mymenu)
{
case 0:
switch(mymode)
{
case 1:
reading = analogRead(0);
frequency = ((double)reading * (108.0 - 87.5)) / 1024.0 + 87.5;
frequency = ((double)reading * 20.5) / 1024.0 + 87.5;
frequency = ((int)(frequency * 10)) / 10.0;
setFrequency();
if(!digitalRead(e2Pin))
{
if(debug)Serial.println(bfrequency);
while(!digitalRead(e2Pin));
}
break;
case 2:
if(!digitalRead(e2Pin))
{
memo++;
if(memo>19)memo=0;
bfrequency = EEPROM.read(memo);
frequency=875+bfrequency;
frequency/=10;
setFrequency();
while(!digitalRead(e2Pin));
}
break;
case 3:
if(!digitalRead(e2Pin))
{
menuScan();
while(!digitalRead(e2Pin));
}
break;
}
lcd.setCursor(0,0);
lcd.print(frequency);
lcd.print(" MHz ");
if(flag)
{
flag=0;
if(alarm==1) { sleep=10; alarm=0;}
if(sleep<1 br=""> {
digitalWrite(LedPin2,LOW);
lcd.setCursor(12,0);
lcd.print("OFF ");
}
else
{
if(!digitalRead(LedPin2))
{
digitalWrite(LedPin2,HIGH);
delay(500);
setFrequency();
delay(500);
setFrequency();
}
getDatos();
signal=rdata[4] >> 4;
lcd.setCursor(12,0);
if(detik & 2)
{
lcd.print("Pw");
lcd.print(signal);
lcd.print(" ");
}
{
if(rdata[3] & 128)
lcd.print("STE ");
else
lcd.print("MONO");
}
}
lcd.setCursor(0,1);
lcd.print(menu1[mymode]);
if(mymode==2)
{
lcd.print(memo);
lcd.print(" ");
}
lcd.setCursor(6, 1);
if(alarm==3)
lcd.print(" ");
else
lcd.print("A");
digitalWrite(LedPin, !digitalRead(LedPin));
sprintf(VARI,"%02d:%02d:%02d",jam,menit,detik);
if(debug)Serial.println(VARI);
lcd.setCursor(8, 1);
lcd.print(VARI);
}
break;
case 1:
lcd.setCursor(0,1);
lcd.print(sleep);
lcd.print(" menit ");
if(!digitalRead(e2Pin))
{
if(sleep>11)
sleep-=10;
else
sleep--;
if(sleep<0 sleep="60;<br"> flag2=1;
while(!digitalRead(e2Pin));
}
break;
case 2:
if(!digitalRead(e2Pin))
{
mymode=2;
mymenu=0;
bfrequency = EEPROM.read(memo);
frequency=875+bfrequency;
frequency/=10;
setFrequency();
while(!digitalRead(e2Pin));
}
break;
case 3:
if(!digitalRead(e2Pin))
{
mymode=3;
mymenu=0;
while(!digitalRead(e2Pin));
}
break;
case 4:
if(!digitalRead(e2Pin))
{
mymode=1;
mymenu=0;
while(!digitalRead(e2Pin));
}
break;
case 5:
sprintf(VARI,"%02d:%02d",Ajam,Amenit);
lcd.setCursor(0, 1);
lcd.print(VARI);
if(!digitalRead(e2Pin))
{
menuAlarm();
mymenu=0;
lcd.clear();
while(!digitalRead(e2Pin));
}
break;
case 6:
if(!digitalRead(e2Pin))
{
menuMemory();
while(!digitalRead(e2Pin));
lcd.clear();
mymenu=0;
}
break;
case 7:
lcd.setCursor(0,1);
lcd.print(mylevel);
if(!digitalRead(e2Pin))
{
mylevel++; if(mylevel>3)mylevel=1;
flag2=1;
while(!digitalRead(e2Pin));
}
break;
case 8:
sprintf(VARI,"%02d:%02d",jam,menit);
lcd.setCursor(0, 1);
lcd.print(VARI);
if(!digitalRead(e2Pin))
{
menuTime();
mymenu=0;
lcd.clear();
while(!digitalRead(e2Pin));
}
break;
}
}
void calculo()
{
bfrequency=frequency*10-875;
frequencyB = 4 * (frequency * 1000000 + 225000) / 32768;
frequencyH = frequencyB >> 8;
frequencyL = frequencyB & 0XFF;
}
void menuMemory()
{
lcd.setCursor(0,1);
lcd.print(memo);
lcd.setCursor(8,0);
lcd.print(frequency);
delay(500);
while(1)
{
if(!digitalRead(e2Pin))
{
memo++;
if(memo>19)memo=0;
lcd.setCursor(0,1);
lcd.print(memo);
lcd.print(" ");
while(!digitalRead(e2Pin));
}
if(!digitalRead(e1Pin))
{
if(debug)Serial.println(memo);
if(debug)Serial.println(bfrequency);
EEPROM.write(memo,bfrequency );
while(!digitalRead(e1Pin));
return;
}
}
void menuScan()
{
delay(100);
frequency+=0.1;
if(frequency>108)frequency=88.5;
calculo();
bz=mylevel<<5 br="">
bz=bz | 0x90;
Wire.beginTransmission(0x60);
Wire.write(frequencyH+0x40);
Wire.write(frequencyL);
Wire.write(bz);
Wire.write(0x1F);
Wire.write((byte)0x00);
Wire.endTransmission();
delay(100);
getDatos();
gfrequency=(((rdata[1]&0x3F)<<8 br="" rdata="">
if(debug)for (int i=1; i<6 br="" i="" rdata="" serial.println=""> frequency=gfrequency/10000;
if(debug)Serial.println(frequency);
z=frequency;
zz=z+5; z/=10; zz/=10;
if(debug)Serial.println(z);
if(debug)Serial.println(zz);
if(zz>z)
frequency=zz;
else
frequency=z;
frequency/=10;
if(debug)Serial.println(frequency);
calculo();
delay(100);
Wire.beginTransmission(0x60);
Wire.write(frequencyH);
Wire.write(frequencyL);
Wire.write(0xB0);
Wire.write(0x1F);
Wire.write((byte)0x00);
Wire.endTransmission();
delay(100);
}
void menuAlarm()
{
while(1)
{
lcd.setCursor(0,1);
lcd.print("Alarm ");
if(alarm==3)
lcd.print("OFF");
else
lcd.print("ON ");
if(!digitalRead(e2Pin))
{
if(alarm==3)
alarm=0;
else
alarm=3;
while(!digitalRead(e2Pin));
}
if(!digitalRead(e1Pin))
{
while(!digitalRead(e1Pin));
break;
}
}
while(1)
{
lcd.setCursor(0,1);
lcd.print("Hours ");
lcd.print(Ajam);
lcd.print(" ");
if(!digitalRead(e2Pin))
{
Ajam++;
if(Ajam==24)Ajam=0;
while(!digitalRead(e2Pin));
}
if(!digitalRead(e1Pin))
{
while(!digitalRead(e1Pin));
break;
}
}
while(1)
{
lcd.setCursor(0,1);
lcd.print("Minutes ");
lcd.print(Amenit);
lcd.print(" ");
if(!digitalRead(e2Pin))
{
Amenit++;
Adetik=0;
if(Amenit==60)Amenit=0;
while(!digitalRead(e2Pin));
}
if(!digitalRead(e1Pin))
{
while(!digitalRead(e1Pin));
break;
}
}
}
void menuTime()
{
while(1)
{
lcd.setCursor(0,1);
lcd.print("Hours ");
lcd.print(jam);
lcd.print(" ");
if(!digitalRead(e2Pin))
{
jam++;
if(jam==24)jam=0;
while(!digitalRead(e2Pin));
}
if(!digitalRead(e1Pin))
{
while(!digitalRead(e1Pin));
break;
}
}
while(1)
{
lcd.setCursor(0,1);
lcd.print("Minutes ");
lcd.print(menit);
lcd.print(" ");
if(!digitalRead(e2Pin))
{
menit++;
detik=0;
if(menit==60)menit=0;
while(!digitalRead(e2Pin));
while(!digitalRead(e1Pin));
break;
}
}
}
void setFrequency()
{
calculo();
//delay(100);
Wire.beginTransmission(0x60);
Wire.write(frequencyH);
Wire.write(frequencyL);
Wire.write(0xB0);
Wire.write(0x10);
Wire.write((byte)0x00);
Wire.endTransmission();
//delay(100);
}
void getDatos()
{
Wire.requestFrom(0x60,5); //reading TEA5767
if (Wire.available())
{
for (int i=1; i<6 br="" i="" rdata="" wire.read=""> }
ISR(TIMER1_COMPA_vect) //alarm yake
{
flag=1;
detik++;
if(detik>59)
{
detik=0;
menit++;
if(sleep>0)sleep--;
if(menit>59)
{
menit=0;
jam++;
if(jam>23)
{
detik=0;
menit=0;
jam=0;
}
}
}
if(alarm==0 && detik==0 && menit==Amenit && jam==Ajam)alarm=1; }
Selamat berkarya dan salam arduino indonesia
Sumber dari :http://cipto-suparno.blogspot.co.id