질문게시판 > 서브모터,I2C LCD, RFID, 버튼을 이용한 아두이노

TODAY17,657 TOTAL6,609,652
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 질문게시판 | 서브모터,I2C LCD, RFID, 버튼을 이용한 아두이노

페이지 정보

작성자 돕고살려주세요 작성일2023-11-30 21:54 조회1,729회 댓글1건

본문

	
#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() {
 Serial.begin(9600);
  SPI.begin();
  lcd.begin(2,16);
  pinMode(OUTPUT, 5);
  pinMode(OUTPUT, 6);
  pinMode(OUTPUT, 7);
  pinMode(OUTPUT, 8);
  mfrc522.PCD_Init();
  lcd.print("   Press Button");    

}

void loop() {
  lcd.clear();
  lcd.print("  Press the 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);  
  /////////////////////////////////////////
  if(a==0)
  {
    lcd.clear();
    lcd.print("     Press the button    ");
    lcd.print("    give me your card");
    delay(9000);
    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);
    }
  }
  if(b==0)
  {
    lcd.clear();
    lcd.print("    Press the button  ");
    lcd.print("    give me your card");
    delay(9000);
    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);
    }
  }
  if(c==0)
    {
    lcd.clear();
    lcd.print("     Press the button    ");
    lcd.print("    give me your card");
    delay(9000);
    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);
    }
  }
  if(d==0)
      {
    lcd.clear();
    lcd.print("    Press the button  ");
    lcd.print("    give me your card");
    delay(9000);
    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);
}
}
제가 유튜브를 보고 RFID를 이용한 자판기를 만들어 볼려고 하는데, 유튜브에 있는대로 따라해봤지만 LCD에는 검은색 블록이 나열되어 출력이 되고, 버튼을 누른 뒤 RFID에 카드(RFID)를 접촉시키면, 360도 서브모터가 돌아가 과자가 떨어지게 행동이 됐어야 하는데, 어떠한 문제가 있는건지 RFID도 인식을 못하고, button을 눌러도 아무런 반응을 하지 않습니다. 핀도 모두 lcd는 아날로그 쪽에, RFID는 디지털 쪽에 점프선을 연결 했는데도 안됩니다. 혹시 어떠한 문제가 있는지, 해결방안도 설명해주시면 감사하겠습니다.

라이브러리도 다 깔았고 lcd의 주소도 확인하여 맞췄습니다. 제가 아두이노를 접한지 얼마 되지 않아서 도와주시면 감사하겠습니다.
혹시 제가 틀렸을수도 있으니, 제가 본 유튜브 링크 남겨보겠습니다.


작동방식
1. LCD에 "Press the button" 이라는 문구가 뜬다.
2. Give me your card라는 문구가 뜨면 RFID에 카드를 접촉시킨다.
3.그 버튼에 해당하는 서브모터가 돌아가면서 과자를 떨어뜨린다.
4.lcd에 Take the cookies라는 문구가 뜬다
5.lcd가 다시 초기화 한다.
  • BASIC4MCU 작성글 SNS에 공유하기
  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기

댓글 1

조회수 1,729

master님의 댓글

master 작성일

LCD 예제/ RFID예제/ 서보모터 예제/ 스위치예제/로 충분히 학습한 후에 다시 시도 해보세요

질문게시판HOME > 질문게시판 목록

MCU, AVR, 아두이노 등 전자공학에 관련된 질문을 무료회원가입 후 작성해주시면 전문가가 답변해드립니다.
ATMEGA128PWMLED초음파
아두이노AVR블루투스LCD
UART모터적외선ATMEGA
전체 스위치 센서
질문게시판 목록
제목 작성자 작성일 조회
공지 MCU, AVR, 아두이노 등 전자공학에 관련된 질문은 질문게시판에서만 작성 가능합니다. 스태프 19-01-15 24249
공지 사이트 이용 안내댓글[31] master 17-10-29 38753
질문 oled 모듈 연결 질문입니다!댓글[1] 펌린이 24-12-17 134
질문 Atmega 128 타이머 질문있습니다댓글[1] ednda 24-12-11 158
답변 답변글 답변 : Atmega 128 타이머 질문있습니다 master 24-12-11 118
질문 ATmega128 2개로 hc-05,hc-06블루트수 통신 동콩이 24-12-04 136
답변 답변글 답변 : ATmega128 2개로 hc-05,hc-06블루트수 통신댓글[4] master 24-12-04 1064
질문 lm75a 온도센서 관련 질문입니다.댓글[6] 이미지첨부파일 hanmw0707 24-12-01 2938
질문 리얼타임클락 질문이요 ㅠㅠ댓글[1] 이미지 팬케이크 24-11-22 225
질문 가속도센서 2개를 강아지 2마리에 각각 달아서 스마트폰으로 움직임을 보고 싶은데요댓글[1] gainomax 24-11-21 403
질문 라즈베리파이 4B 사용 중 막히는 부분 질문합니다댓글[1] 한마바키 24-11-12 6557
질문 스위치로 PI 모터 제어 바밤 24-11-11 197
답변 답변글 답변 : 스위치로 PI 모터 제어 master 24-11-12 186
질문 아트메가128 마이크로프로세서댓글[3] 옹심이 24-11-05 679
질문 초음파 센서로 장애물 인식댓글[1] 나난ㄴ 24-10-31 314
질문 이런 투명 LCD는 뭐라고 부르나요?댓글[2] 이미지 펌린이 24-10-29 475
질문 모터제어 중 RPM 계산 질문입니다.댓글[3] suuuuuuuh 24-10-24 622
질문 아트메가 128과 블루투스 모듈(HC-06) 연결 질문댓글[1] 메가아트 24-10-24 322
질문 ATmega128 질문 DFplayer mini댓글[1] Miin 24-10-18 6799
질문 스탭모터 3개 회로도 질문.. 삉삉이 24-10-11 328
답변 답변글 답변 : 스탭모터 3개 회로도 질문.. 이미지 master 24-10-12 363
질문 수분수위센서와 멀티플렉서댓글[3] 김고래쓰 24-10-10 910
질문 ATmegq128 PI 제어기 추가댓글[1] 바밤 24-10-08 357
답변 답변글 답변 : ATmegq128 PI 제어기 추가댓글[1] master 24-10-08 481
질문 아두이노 ide 네오픽셀 각 셀 각자 코드 현수 24-09-29 213
질문 아두이노 IDE 프로마이크로 네오픽셀 현수 24-09-29 242
답변 답변글 답변 : 아두이노 IDE 프로마이크로 네오픽셀 master 24-09-29 221
질문 아두이노 프로마이크로 ide 현수 24-09-28 245
답변 답변글 답변 : 아두이노 프로마이크로 ide master 24-09-28 344
질문 ATmega128로 압력센서댓글[1] 이미지첨부파일 바밤 24-09-27 492
게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기