Você está na página 1de 12

#include <LiquidCrystal.

h>

#include <Servo.h>

Servo myservo1;

Servo myservo2;

int led_1 = 8;

int led_2 = 9;

int buzzer = 3;

int tombol_1 = 3;

int tombol_2 = 6;

int tombol_3 = 7;

int thold1 = 0;

int thold2 = 0;

int pos = 0;

LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);

#include <SPI.h>

#include <RFID.h>

RFID rfid(10,5);

// 4 , 129 , 107 , 26 , 244 depan

byte emaomos1[5] = {

0x04,0x81,0x6B,0x1A,0xF4};

// 116 , 53 , 106 , 26 , 49 belakang

byte emaomos2[5] =

0x74,0x35,0x6A,0x1A,0x31};
int iden = 0;

int t1;

int t2;

int t3;

byte serNum[5];

byte data[5];

int count = 0;

// boolean emaomos_card1 = true;

// boolean emaomos_card2 = true;

int steps = 0;

int mode = 0;

void setup()

Serial.begin(9600);

lcd.begin(16,4);

SPI.begin();

rfid.init();

myservo1.attach(2);

myservo2.attach(4);

pinMode(tombol_1,INPUT);

pinMode(tombol_2,INPUT);

pinMode(tombol_3,INPUT);

pinMode(led_1,OUTPUT);

pinMode(led_2,OUTPUT);

pinMode(buzzer,OUTPUT);

digitalWrite(tombol_1,HIGH);

digitalWrite(tombol_2,HIGH);
digitalWrite(tombol_3,HIGH);

myservo1.write(0);

myservo2.write(0);

void test_LCD()

lcd.setCursor(0,0);

lcd.print("TEST LCD");

void test_indikator()

digitalWrite(led_1,HIGH);

digitalWrite(led_2,LOW);

digitalWrite(buzzer,HIGH);

delay(500);

digitalWrite(led_1,LOW);

digitalWrite(led_2,HIGH);

digitalWrite(buzzer,LOW);

delay(500);

void loopaa()

myservo1.write(90);

myservo2.write(90);

delay(2000);

myservo1.write(0);
myservo2.write(0);

delay(2000);

void gerbang_tutup()

for(pos = 0; pos < 90; pos += 1)

myservo1.write(pos);

myservo2.write(pos);

delay(15);

//delay(2000);

void gerbang_buka()

for(pos = 90; pos>=1; pos-=1)

myservo1.write(pos);

myservo2.write(pos);

delay(15);

void tombol_aktif()

{
t1 = digitalRead(tombol_1);

t2 = digitalRead(tombol_2);

t3 = digitalRead(tombol_3);

//Serial.print(t1);

//Serial.print(" ");

//Serial.print(t2);

//Serial.print(" ");

//Serial.println(t3);

//delay(100);

void test_lcd()

lcd.setCursor(0,0);

lcd.println("helo world");

void loopaaa()

//read_RFID();

//test_indikator();

tombol_aktif();

void loop()

while(steps == 0)

{
lcd.setCursor(0,0);

lcd.print("Zainal Abidin");

lcd.setCursor(0,1);

lcd.print("41411010016");

delay(2000);

lcd.clear();

steps = 1;

while(steps == 1)

lcd.setCursor(0,0);

lcd.print("Miniatur Palang");

lcd.setCursor(0,1);

lcd.print(" Pintu Kereta");

delay(2000);

lcd.clear();

steps = 3;

while(steps == 3)

tombol_aktif();

lcd.setCursor(0,0);

lcd.print(" Menu");

lcd.setCursor(0,1);

lcd.print("Tutup Buka");

lcd.setCursor(0,2);

lcd.print(" Mode");

lcd.setCursor(0,3);
lcd.print("Manual");

if(t2 == 0)

thold1 =1;

if(t1 == 0)

thold2 =1;

if(thold1 == 1)

gerbang_tutup();

thold1 = 0;

if(thold2 == 1)

gerbang_buka();

thold2 = 0;

else if(t3 == 0)

delay(1000);

lcd.clear();

steps = 20;

}
while(steps == 20)

tombol_aktif();

lcd.setCursor(0,0);

lcd.print(" Menu");

lcd.setCursor(0,1);

lcd.print("Tutup Buka");

lcd.setCursor(0,2);

lcd.print(" Mode");

lcd.setCursor(0,3);

lcd.print("Otomatis");

if(t3 == 0)

delay(250);

lcd.clear();

steps = 3;

read_RFID();

void read_RFID()

boolean emaomos_card1 = true;

boolean emaomos_card2 = true;

if (rfid.isCard())

{ // valid card found


if (rfid.readCardSerial()){ // reads the card

delay(100);

data[0] = rfid.serNum[0]; // stores the serial number

data[1] = rfid.serNum[1];

data[2] = rfid.serNum[2];

data[3] = rfid.serNum[3];

data[4] = rfid.serNum[4];

//rfid.halt(); // RFID module to standby

//Serial.println("Card found - code:");

if(rfid.serNum[0] < 16){

// Serial.println(rfid.serNum[0],HEX);

if(rfid.serNum[1] < 16){

// Serial.println(rfid.serNum[1],HEX);

if(rfid.serNum[2] < 16){

// Serial.println(rfid.serNum[2],HEX);

if(rfid.serNum[3] < 16){

// Serial.println(rfid.serNum[3],HEX);
if(rfid.serNum[4] < 16){

//Serial.println(rfid.serNum[4],HEX);

for(int i=0; i<5; i++)

if(data[i] != emaomos1[i]) emaomos_card1 = false;

if(data[i] != emaomos2[i]) emaomos_card2 = false; // if it is not a valid card,


put false to this user

// Here you can check the another allowed users, just put lines like above
with the user name

Serial.println();

if (emaomos_card1)

{ // if a valid card was found

//Serial.println(" Sedang Proses... ");

//Serial.println("Hello user Marcelo!"); // print a message

else

{ // if a card is not recognized

//Serial.println(" ID TIDAK DIKENAL!");

if (emaomos_card1 && iden != 1)

{// add another user using an logical or condition ||


// Welcome messages and access permission

Serial.print(" Access DITERIMA depan! ");

gerbang_tutup();

test_indikator();

test_indikator();

count ++;

iden = 1;

Serial.println(iden);

if (emaomos_card2)

{ // if a valid card was found

//Serial.println(" Sedang Proses... ");

//Serial.println("Hello user Marcelo!"); // print a message

else

{ // if a card is not recognized

//Serial.println(" ID TIDAK DIKENAL!");

if (emaomos_card2 && iden != 2)

{// add another user using an logical or condition ||

// Welcome messages and access permission


Serial.println(" Access DITERIMA belakang!");

test_indikator();

test_indikator();

test_indikator();

test_indikator();

test_indikator();

gerbang_buka();

digitalWrite(led_1,LOW);

digitalWrite(led_2,LOW);

digitalWrite(buzzer,LOW);

delay(500);

iden = 2;

Serial.println(iden);

rfid.halt();

Você também pode gostar