Posted by : Y
Friday, 16 December 2016
Oke sobat project kali ini adalah bagaimana cara membuat alat pendeteksi uang kertas menggunakan sensor TCS 3200 atau sensor warna untuk membedakan warna pada uang kertas. dan modul ISD 1760 sebagai pengolah suara yang dikeluarkan.
Langkah 1
Siapkan Bahan Yang diperlukan
1. Arduino Uno R3
2. TCS 3200
3. ISD 1760
4. Speaker Kecil ukuran 5volt
5. Kabel Jumper
6. Akrilik sebagai casingnya
Langkah 2
Lihat diagram blok rangkaian dibawah ini
Kemudian hubungkan pin pin seperti dibawah ini
Arduino ISD 1760
port 10 mosi
port 11 sck
port 12 miso
port 13 ss
Arduino TCS 3200
port 5 s3
port 6 s2
port 7 out
port 8 s1
port 9 s0
Langkah 3
rekam suara anda dari nominal uang kertas terkecil hingga terbesar pada modul ID1760
Langkah 4
hubungkan arduino dengan komputer/laptop. kemudian buka aplikasi arduino IDE
masukkan script di bawah ini
//define pins
#define DATAOUT 11 //mosi
#define DATAIN 12 //miso
#define SPICLOCK 13 //sck
#define SLAVESELECT 10 //ss
//opcodes
#define PU 0x01
#define STOP 0x02
#define RESET 0x03
#define CLR_INT 0x04
#define RD_STATUS 0x05
#define RD_PLAY_PTR 0x06
#define PD 0x07
#define RD_REC_PTR 0x08
#define DEVID 0x09
#define PLAY 0x40
#define REC 0x41
#define REC_LED 0x51//record with LED on
#define ERASE 0x42
#define G_ERASE 0x43
#define RD_APC 0x44
#define WR_APC1 0x45
#define WR_APC2 0x65
#define WR_NVCFG 0x46
#define LD_NVCFG 0x47
#define FWD 0x48
#define CHK_MEM 0x49
#define EXTCLK 0x4A
#define SET_PLAY 0x80
#define SET_REC 0x81
#define SET_REC_LED 0x91//set record with LED on
#define SET_ERASE 0x82
#define WAIT_TIME 10//waiting time (ms) after SS=LOW at least 500ns
#define WAIT_TIME2 100
const int s0 = 8;
const int s1 = 9;
const int s2 = 6;
const int s3 = 5;
const int out = 7;
const int button = 3;
int start_adress = 0x010;//test address to record
int end_adress = 0x024;//20unit
int red = 0;
int green = 0;
int blue = 0;
void setup() {
Serial.begin(9600);
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(out, INPUT);
pinMode(button, INPUT);
digitalWrite(s0, HIGH);
digitalWrite(s1, HIGH);
digitalWrite(button, HIGH);
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK, OUTPUT);
pinMode(SLAVESELECT, OUTPUT);
initialize();
}
void initialize()
{
byte clr;
digitalWrite(SLAVESELECT, HIGH); //disable device
digitalWrite(SPICLOCK, HIGH); //SCLK
digitalWrite(DATAOUT, LOW); //MOSI
SPCR = B01111111; //data lsb, clock high when idle, samples on falling
clr = SPSR;
clr = SPDR;
delay(10);
//start serial
Serial.begin(9600);
pu();
}
void loop()
{
while(digitalRead(button))
color();
Serial.print("R Intensity:");
Serial.print(red, DEC);
Serial.print(" G Intensity: ");
Serial.print(green, DEC);
Serial.print(" B Intensity : ");
Serial.print(blue, DEC);
//Serial.println();
if (red < 6 && red > 4 && green < 8 && green > 4 && blue < 6 && blue > 4)
{
Serial.println(" - (2 Ribu)");
set_play2(start_adress, end_adress);
delay(3000);
}
else if (red > 7 && red < 9 && green > 10 && green < 12 && blue > 8 && blue < 11)
{
Serial.println(" - (10 Ribu)");
set_play10(start_adress, end_adress);
delay(3000);
}
else if (red > 4 && red < 7 && green > 6 && green < 9 && blue > 6 && blue < 8)
{
Serial.println(" - (5 Ribu)");
set_play5(start_adress, end_adress);
delay(3000);
}
else if (red > 7 && red < 10 && green > 10 && green < 12 && blue > 6 && blue < 9)
{
Serial.println(" - (10 Ribu)");
set_play10(start_adress, end_adress);
delay(3000);
}
else if (red > 12 && red < 14 && green > 10 && green < 14 && blue > 6 && blue < 11)
{
Serial.println(" - (50 Ribu)");
set_play50(start_adress, end_adress);
delay(3000);
}
else if (red > 9 && red < 12 && green > 9 && green < 12 && blue > 9 && blue < 11)
{
Serial.println(" - (20 Ribu)");
set_play20(start_adress, end_adress);
delay(3000);
}
else if (red > 9 && red < 14 && green > 9 && green < 14 && blue > 9 && blue < 14)
{
Serial.println(" - (10 Ribu)");
set_play10(start_adress, end_adress);
delay(3000);
}
else if (red > 13 && red < 15 && green > 13 && green < 15 && blue > 10 && blue < 12)
{
Serial.println(" - (20 Ribu)");
set_play20(start_adress, end_adress);
delay(3000);
}
else if (red > 13 && red < 15 && green > 12 && green < 14 && blue > 10 && blue < 15)
{
Serial.println(" - (20 Ribu)");
set_play20(start_adress, end_adress);
delay(3000);
}
else if (red > 12 && red < 14 && green > 12 && green < 14 && blue > 7 && blue < 9)
{
Serial.println(" - (50 Ribu)");
set_play50(start_adress, end_adress);
delay(3000);
}
else if (red > 12 && red < 15 && green > 12 && green < 14 && blue > 7 && blue < 11)
{
Serial.println(" - (50 Ribu)");
set_play50(start_adress, end_adress);
delay(3000);
}
else if (red > 3 && red < 6 && green > 7 && green < 12 && blue > 6 && blue < 9)
{
Serial.println(" - (100 Ribu)");
set_play100(start_adress, end_adress);
delay(3000);
}
else if (red > 4 && red < 8 && green > 9 && green < 12 && blue > 6 && blue < 10)
{
Serial.println(" - (5 Ribu)");
set_play5(start_adress, end_adress);
delay(3000);
}
else {
Serial.println();
}
delay(500);
}
void color()
{
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
//count OUT, pRed, RED
red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
digitalWrite(s3, HIGH);
//count OUT, pBLUE, BLUE
blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
digitalWrite(s2, HIGH);
//count OUT, pGreen, GREEN
green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
}
void pu()//power up
{
digitalWrite(SLAVESELECT, LOW);
delay(WAIT_TIME);
spi_transfer(PU); // power up
spi_transfer(0x00); // data byte
digitalWrite(SLAVESELECT, HIGH);
delay(WAIT_TIME2);
}
void play()
{
digitalWrite(SLAVESELECT, LOW);
delay(WAIT_TIME);
spi_transfer(PLAY); // play
spi_transfer(0x00); // data byte
digitalWrite(SLAVESELECT, HIGH);
delay(WAIT_TIME2);
}
void stop()
{
digitalWrite(SLAVESELECT, LOW);
delay(WAIT_TIME);
spi_transfer(STOP); // stop
spi_transfer(0x00); // data byte
digitalWrite(SLAVESELECT, HIGH);
delay(WAIT_TIME2);
Serial.println("stop end");
}
void set_play(int starta , int enda )
{
int a = 07 ;
int b = 35 ;
digitalWrite(SLAVESELECT, LOW);
delay(WAIT_TIME);
spi_transfer(SET_PLAY); // clear interupt and eom bit
spi_transfer(0); // data byte
spi_transfer(a & 255); // data byte start
spi_transfer(a >> 8); // data byte last 3 bits
spi_transfer(b & 255); // data byte stop
spi_transfer(b >> 8); // data byte last 3 bits
spi_transfer(0); // data byte blank
digitalWrite(SLAVESELECT, HIGH);
delay(WAIT_TIME2);
}
void set_play50(int starta , int enda )
{
int a = 110 ; // setting mulai suara 50ribu
int b = 125 ; // setting berhenti suara 50ribu
digitalWrite(SLAVESELECT, LOW);
delay(WAIT_TIME);
spi_transfer(SET_PLAY); // clear interupt and eom bit
spi_transfer(0); // data byte
spi_transfer(a & 255); // data byte start
spi_transfer(a >> 8); // data byte last 3 bits
spi_transfer(b & 255); // data byte stop
spi_transfer(b >> 8); // data byte last 3 bits
spi_transfer(0); // data byte blank
digitalWrite(SLAVESELECT, HIGH);
delay(WAIT_TIME2);
}
void set_play100(int starta , int enda )
{
int a = 130 ; setting mulai suara 100ribu
int b = 150 ; setting berhenti suara 100ribu
digitalWrite(SLAVESELECT, LOW);
delay(WAIT_TIME);
spi_transfer(SET_PLAY); // clear interupt and eom bit
spi_transfer(0); // data byte
spi_transfer(a & 255); // data byte start
spi_transfer(a >> 8); // data byte last 3 bits
spi_transfer(b & 255); // data byte stop
spi_transfer(b >> 8); // data byte last 3 bits
spi_transfer(0); // data byte blank
digitalWrite(SLAVESELECT, HIGH);
delay(WAIT_TIME2);
}
void set_play20(int starta , int enda )
{
int a = 90 ;
int b = 110 ;
digitalWrite(SLAVESELECT, LOW);
delay(WAIT_TIME);
spi_transfer(SET_PLAY); // clear interupt and eom bit
spi_transfer(0); // data byte
spi_transfer(a & 255); // data byte start
spi_transfer(a >> 8); // data byte last 3 bits
spi_transfer(b & 255); // data byte stop
spi_transfer(b >> 8); // data byte last 3 bits
spi_transfer(0); // data byte blank
digitalWrite(SLAVESELECT, HIGH);
delay(WAIT_TIME2);
}
void set_play10(int starta , int enda )
{
int a = 70 ;
int b = 90 ;
digitalWrite(SLAVESELECT, LOW);
delay(WAIT_TIME);
spi_transfer(SET_PLAY); // clear interupt and eom bit
spi_transfer(0); // data byte
spi_transfer(a & 255); // data byte start
spi_transfer(a >> 8); // data byte last 3 bits
spi_transfer(b & 255); // data byte stop
spi_transfer(b >> 8); // data byte last 3 bits
spi_transfer(0); // data byte blank
digitalWrite(SLAVESELECT, HIGH);
delay(WAIT_TIME2);
}
void set_play5(int starta , int enda )
{
int a = 50 ;
int b = 70 ;
digitalWrite(SLAVESELECT, LOW);
delay(WAIT_TIME);
spi_transfer(SET_PLAY); // clear interupt and eom bit
spi_transfer(0); // data byte
spi_transfer(a & 255); // data byte start
spi_transfer(a >> 8); // data byte last 3 bits
spi_transfer(b & 255); // data byte stop
spi_transfer(b >> 8); // data byte last 3 bits
spi_transfer(0); // data byte blank
digitalWrite(SLAVESELECT, HIGH);
delay(WAIT_TIME2);
}
void set_play2(int starta , int enda )
{
int a = 35 ;
int b = 50 ;
digitalWrite(SLAVESELECT, LOW);
delay(WAIT_TIME);
spi_transfer(SET_PLAY); // clear interupt and eom bit
spi_transfer(0); // data byte
spi_transfer(a & 255); // data byte start
spi_transfer(a >> 8); // data byte last 3 bits
spi_transfer(b & 255); // data byte stop
spi_transfer(b >> 8); // data byte last 3 bits
spi_transfer(0); // data byte blank
digitalWrite(SLAVESELECT, HIGH);
delay(WAIT_TIME2);
}
void set_play1(int starta , int enda )
{
int a = 5 ;
int b = 35 ;
digitalWrite(SLAVESELECT, LOW);
delay(WAIT_TIME);
spi_transfer(SET_PLAY); // clear interupt and eom bit
spi_transfer(0); // data byte
spi_transfer(a & 255); // data byte start
spi_transfer(a >> 8); // data byte last 3 bits
spi_transfer(b & 255); // data byte stop
spi_transfer(b >> 8); // data byte last 3 bits
spi_transfer(0); // data byte blank
digitalWrite(SLAVESELECT, HIGH);
delay(WAIT_TIME2);
}
void ready_play_wait()
{
byte byte1;
byte byte2;
byte byte3;
while(byte3 << 7 != 128)
{
digitalWrite(SLAVESELECT, LOW);
delay(WAIT_TIME);
byte1 = spi_transfer(RD_STATUS); // clear interupt and eom bit
byte2 = spi_transfer(0x00); // data byte
byte3 = spi_transfer(0x00); // data byte
digitalWrite(SLAVESELECT, HIGH);
delay(WAIT_TIME2);
}
delay(100);
}
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1 << SPIF))) // Wait for the end of the transmission
{
};
return SPDR; // return the received byte
}
Langkah 5
Kemudian klik tombol “verify” (icon ceklist)
Hingga muncul tulisan “done compiling”
Langkah 6
Setelah sukses klik tombol “Upload” disamping kanan tombol “verify” hingga muncul tulisan “compiling done”
Selesai..selamat dicoba..selamat belajar
Jika bermanfaat tolong klik iklannya yya :D
Jika ada pertanyaan silahkan
gan, itu cara memisah rekamannya gimana yak? maksudnya untuk 1000 suara nya di simpan dimana? dan untuk yg lainnya gimana ya? apa diatur di arduino? lalu gimana?...
ReplyDelete