본문 바로가기

메이커 활동

아두이노로 사격장 만들기

안녕하세요!

몇몇 분들이 유투브에 소개된 사격장 만들기 소스에 관심이 많으셔서

만들어 본지는 조금 오래 되었지만, 기억을 더듬어서

만들었던 과정과 소스를

함께 공유를 해보고자 합니다.

 

 

 


아두이노 사격장 만들기


아두이노 사격장 시스템을 한번 만들어 보았는데요,

유기어스에 판매되고 있는 고무줄 총을 활용해서 한번 만들어 보았습니다.

 


사용 재료?

1. 아두이노
2. MDF 3t
3. Half 브레드보드
4. 서보모터 6개
5. 리미트스위치 6개
6. 푸쉬 버튼
7. I2C LCD 디스플레이
8. 고무줄총

를 사용했습니다.

 

조립식 고무줄총- 메이커 체험, 교육, 유기어스 : Make it Now

[Make it Now] 메이커 제품을 만날 수 있는 마켓입니다.

smartstore.naver.com

 


1. 도면 그리기


도면은 2D, 3D 편하신 툴을 활용하시면 좋을 것 같아요!

저는 레이저 커팅기를 활용할 것이기 때문에,

AutoCad를 사용해서 모델링 해보았습니다.
사용 재료는 mdf 3t를 사용했습니다.

사격 타겟은 크게 5점 10점 15점

세 가지로 나눴습니다.

 


2. 만드는 방법


만드는 방법은 아래 동영상을 보시면 됩니다.


3. 사용 코드


여기서 추가할 라이브러리는 LCD I2C 라이브러리만 추가 해주시면 됩니다.

회로는 아래 정의된 것들을 확인하시면 아마 이해가 쉽지 않을까요?

혹시 어려운게 있으면 댓글 남겨주세요 ^^

#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

#define RST 0
#define COIN 1
#define BTN1 2
#define BTN2 4
#define BTN3 7
#define BTN4 8
#define BTN5 12
#define BTN6 13

#define SV1 3
#define SV2 5
#define SV3 6
#define SV4 9
#define SV5 10
#define SV6 11

Servo svoArray[6];
LiquidCrystal_I2C lcd(0x27, 16, 2);

int dataArray[6] = {BTN1, BTN2, BTN3, BTN4, BTN5, BTN6};
int scoreArray[6] = {100, 50, 30, 200, 90, 180};
int svoPinArray[6] = {SV1, SV2, SV3, SV4, SV5, SV6};
int score = 0;

void reset();
void lcdprint(int scoreOrNum, int mode);
void playGame();

void setup() {
  Serial.begin(9600);
  Serial.println("Hello!");
  lcd.begin();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Game Start!");

  pinMode(RST, INPUT_PULLUP);
  pinMode(COIN, INPUT_PULLUP);
  pinMode(BTN1, INPUT_PULLUP);
  pinMode(BTN2, INPUT_PULLUP);
  pinMode(BTN3, INPUT_PULLUP);
  pinMode(BTN4, INPUT_PULLUP);
  pinMode(BTN5, INPUT_PULLUP);
  pinMode(BTN6, INPUT_PULLUP);

  for(int i = 0; i < 6; i++){
    svoArray[i].attach(svoPinArray[i]);
  }
  reset();
}



void loop() {
  Serial.println("Insert Coin!");
  lcd.setCursor(0,0);
  lcd.print("Insert Coin!    ");
  while (analogRead(A0) < 500){
    continue;
  }
  lcd.setCursor(0,0);
  lcd.print("Press SRT Button");
  Serial.println("Press Start Button");
  while (digitalRead(RST) ){
    continue;
  }
  playGame();
}

void playGame(){
  int centinal = 0;
  Serial.println("Game Start!");
  lcd.setCursor(0,0);
  lcd.print("Game Start!      ");
  delay(1000);
  while (true){
    centinal = 0;
    int standback;
    lcdprint(score, 1);
    while ( ! centinal ){
      if ( ! digitalRead(RST) ){
        reset();
        return;
      }
      for( int i = 0; i < 6; i++){
        if ( !digitalRead( dataArray[i] ) ){
          standback = i;
          centinal = 1;
          score += scoreArray[i];
          break;
        }
      }
      if ( centinal ){
        break;
      }
    }
    
    for( int i = 0; i < 6; i++){
      Serial.print( ! digitalRead( dataArray[i] ) );
      Serial.print("  ");
    }
    Serial.println();
    lcdprint(scoreArray[standback], 0);
    delay(1000);
    svoArray[standback].write(3);
    delay(1000);
    svoArray[standback].write(130);
  }
}

void reset(){
  score = 0;
  Serial.println("\nRestart!");
  lcd.setCursor(0,0);
  lcd.print("Restart!        ");
  for(int i = 0; i < 6; i++){
    svoArray[i].write(3);
  }
  delay(1000);
  for(int i = 0; i < 6; i++){
    svoArray[i].write(130);
  }
  lcdprint(score,1);
}

void lcdprint(int scoreOrNum, int mode){
  lcd.setCursor(0, 0);
  if (mode){
    lcd.print("Score : ");
    lcd.print(scoreOrNum);
    Serial.print("Score : ");
    Serial.println(scoreOrNum);
    Serial.println();
  }
  else{
    lcd.print("You Hit : ");
    lcd.print(scoreOrNum);
    Serial.print("You Hit : ");
    Serial.println(scoreOrNum);
  }
  lcd.print("           ");
}

 

이상 입니다!

많이 부족하지만, 도움이 되셨으면 좋겠습니다~!

사업자 정보 표시
메이크잇나우 | 김건욱 | (우 : 13487) 경기도 성남시 분당구 대왕판교로645번길 12 (경기창조경제혁신센터) 9층 | 사업자 등록번호 : 646-35-00394 | TEL : 070-8887-0703 | Mail : kgu0724@makeitnow.kr | 통신판매신고번호 : 2018-성남분당-0517호 | 사이버몰의 이용약관 바로가기