BASIC4MCU | 질문게시판 | 아두이노 자판기 질문입니다
페이지 정보
작성자 한세월두세월 작성일2023-12-06 22:22 조회1,199회 댓글1건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=23528
본문
#include <Servo.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo servo;
int a, b, c, d ;
void setup(){
for(int i=5;i<=8;i++)pinMode(i,INPUT_PULLUP); // <-- 수정
lcd.init();
lcd.backlight();
lcd.print(" Press Button");
SPI.begin();
mfrc522.PCD_Init();
Serial.begin(9600);
}
void loop() {
lcd.clear();
lcd.print(" Press Button");
a = digitalRead(5);
b = digitalRead(6);
c = digitalRead(7);
d = digitalRead(8);
Serial.print(a);
Serial.print(b);
Serial.print(c);
Serial.print(d);
//////////////////////////////////////a////////////////////////////////
if( a== 0)
{
lcd.clear();
lcd.print(" 5$ ");
delay(2000);
lcd.clear();
lcd.print(" give your card");
delay(3000);
if( ! mfrc522.PICC_IsNewCardPresent())
return;
if(! mfrc522.PICC_ReadCardSerial())
return;
Serial.print("UID tag : ");
String content ="";
byte letter;
for(byte i=0; i<mfrc522.uid.size; ++i)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? "0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if( content.substring(1) == "2B 3C C9 23")
{
servo.attach(A0);
servo.write(80);
delay(2000);
servo.detach();
delay(2000);
lcd.clear();
lcd.print(" Take the cookies");
delay(5000);
}
}
//////////////////////////////////////b////////////////////////////////
if( b== 0)
{
lcd.clear();
lcd.print(" 6$ ");
delay(2000);
lcd.clear();
lcd.print(" give your card");
delay(3000);
if( ! mfrc522.PICC_IsNewCardPresent())
return;
if(! mfrc522.PICC_ReadCardSerial())
return;
Serial.print("UID tag : ");
String content ="";
byte letter;
for(byte i=0; i<mfrc522.uid.size; ++i)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? "0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if( content.substring(1) == "2B 3C C9 23")
{
servo.attach(2);
servo.write(80);
delay(2000);
servo.detach();
delay(2000);
lcd.clear();
lcd.print(" Take the cookies");
delay(5000);
}
}
//////////////////////////////////////c////////////////////////////////
if( c== 0)
{
lcd.clear();
lcd.print(" 6$ ");
delay(2000);
lcd.clear();
lcd.print(" give your card");
delay(3000);
if( ! mfrc522.PICC_IsNewCardPresent())
return;
if(! mfrc522.PICC_ReadCardSerial())
return;
Serial.print("UID tag : ");
String content ="";
byte letter;
for(byte i=0; i<mfrc522.uid.size; ++i)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? "0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if( content.substring(1) == "2B 3C C9 23")
{
servo.attach(3);
servo.write(80);
delay(2000);
servo.detach();
delay(2000);
lcd.clear();
lcd.print(" Take the cookies");
delay(5000);
}
}
/////////////////////////////////////d////////////////////////////////
if( d== 0)
{
lcd.clear();
lcd.print(" 8$ ");
delay(2000);
lcd.clear();
lcd.print(" give your card");
delay(3000);
if( ! mfrc522.PICC_IsNewCardPresent())
return;
if(! mfrc522.PICC_ReadCardSerial())
return;
Serial.print("UID tag : ");
String content ="";
byte letter;
for(byte i=0; i<mfrc522.uid.size; ++i)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? "0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if( content.substring(1) == "2B 3C C9 23")
{
servo.attach(4);
servo.write(80);
delay(2000);
servo.detach();
delay(2000);
lcd.clear();
lcd.print(" Take the cookies");
delay(5000);
}
}
delay(100);
}
원래 스위치를 누르고 give your card라는 문구가 lcd에 뜨면 rfid 카드를 가져다 대서 과자가 나오는 방식입니다
여기서 RFID에 카드를 가져다 대면 시리얼 모니터에 11111이라는 숫자가 계속 뜹니다. 혹시 정상적으로 작동할 수 있도록 할 수 있는 방법이 없을까요? 부탁드립니다..
댓글 1
조회수 1,199한세월두세월님의 댓글
한세월두세월 작성일rfid카드 식별번호도 기입했습니다..