본문 바로가기
모두의 아두이노/아두이노 쉴드

[아두이노 쉴드] 아두이노 다기능 확장 쉴드

by 로니킴 2021. 11. 16.


본 절은 [아두이노 다기능 확장 쉴드] 를 사용하기 위해 알아야 할 내용과 실습 방법에 대해 설명한다. 아두이노 다기능 확장 쉴드의 특징, 동작원리, 사양, 연결 핀 배열, 출력 값, 주의사항을 알아본다. 아두이노와 센서를 연결하고, 간단한 코딩으로 센서를 쉽게 실습할 수 있다. 

 

목차

     

     

     


    아두이노 다기능 확장 쉴드

     

     

     

     

     

     

     

     


    아두이노 다기능 확장 쉴드 란?

    아두이노 우노 계열의 보드에 적층해서 사용하는 확장 쉴드입니다. 아두이노 보드에 적층하여 사용할 수 있으며, 스위치, 부저, 가변저항, LED, 세그먼트 등이 내장되어 있어 여러 센서들을 입문하기에 좋은 쉴드다.

     

    Arduino Multi Function Shield.pdf
    0.37MB

     

     


     

    아두이노 다기능 확장 쉴드 특징

    아두이노 다기능 확장 쉴드의 특징은 다음과 같다. 

     

    - -DS18B20, LM35(A4) 온도센서를 끼울 수 있는 핀헤더가 납땜되어 있다.(온도센서는 포함되어 있지 않다.)
    - 74HC595의 시프트 레지스터를 이용해 적은 핀 수로 세그먼트를 제어할 수 있다.
    - 가변저항(A0), 택트 스위치(A1, A2, A3)와 LED(D10, D11, D12, D13)가 내장되어 있다.
    - PWM(D5, D6, D9), A5는 M타입 핀헤더가 나와있다.

     

     

     

     

     

     


    아두이노 다기능 확장 쉴드 동작 원리

    센서는 다음과 같이 구성되어 있다. 

     

     

    https://blog.daum.net/rockjjy99/2685

     

     

     


    아두이노 다기능 확장 쉴드 구입하기

    [아두이노 다기능 확장 쉴드]는 알리익스프레스, 네이버 쇼핑몰, 아마존 등에서 센서를 구입할 수 있다

     

     

    알리 익스프레스에서 구입할 수 있다. 

     

     

     

     

     


     

    아두이노 다기능 확장 쉴드 라이브러리 설치하기

    다음과 같이 라이브러리를 설치한다. 

     

    https://github.com/DireCat/MFShield

     

    GitHub - DireCat/MFShield: A tiny and complete library for Arduino Multifunction Shield

    A tiny and complete library for Arduino Multifunction Shield - GitHub - DireCat/MFShield: A tiny and complete library for Arduino Multifunction Shield

    github.com

     

    MFShield는 일반적인 저렴한 Arduino Multi-Function Shield를 위한 작고 쉬운 라이브러리이다. 코드 작성 및 핀 정의를 사용할 필요가 없다. 단순히 라이브러리 함수를 호출하기만 하면 된다.

    MFShield-master.zip
    0.01MB

     

     

    [동작]

    • 버튼이 눌렸을 때 함수를 호출한다. onKeyPress(yourFunction (uint8_t button_number))
    • 디스플레이에 숫자를 표시한다. display (int value)
    • 전위차계의 아날로그 값을 읽는다. int readTrimmerValue ()
    • 일정 시간 동안 부저와 함께 소리를 낸다.beep (int ms)

     

     

     


     

     Arduino Uno 로 다기능 쉴드를 사용해 4자리 FND 7 Segment 출력해 보기

    하드웨어 연결이 완료되면, 아두이노 IDE를 이용해 아두이노 센서 소스코드를 코딩할 수 있다. 

     

    센서 코드는 다음과 같다. 

     
    #define LATCH_DIO 4
    #define CLK_DIO 7
    #define DATA_DIO 8
     
    /* Segment byte maps for numbers 0 to 9 */
    const byte SEGMENT_MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};
    /* Byte maps to select digit 1 to 4 */
    const byte SEGMENT_SELECT[] = {0xF1,0xF2,0xF4,0xF8};
    
    
    unsigned long Cur_ms_Count; // Stores the current time in ms
    unsigned long Last_ms_Count; // Stores the last time in ms the counter was last updated
    int Count; // Stores the value that will be displayed
    
    void setup ()
    {
      /* Set DIO pins to outputs */
      pinMode(LATCH_DIO,OUTPUT);
      pinMode(CLK_DIO,OUTPUT);
      pinMode(DATA_DIO,OUTPUT); 
      
      /* Initiliase the registers used to store the crrent time and count */
      Cur_ms_Count = millis();
      Last_ms_Count = 0;
      Count = 0;
    }
    
    /* Main program */
    void loop()
    {
     
      /* Get how much time has passed in milliseconds */
      Cur_ms_Count = millis();
      
      /* If 100ms has passed then add one to the counter */
      if(Cur_ms_Count - Last_ms_Count > 100)
      {
    
        Last_ms_Count = Cur_ms_Count;
        
        if(Count < 9999)
        {
          Count++;
        } else
        {
          Count = 0;
        }
      }
      
      /* Update the display with the current counter value */
      WriteNumber(Count);
    }
    
    
    /* Write a decimal number between 0 and 9999 to the display */
    void WriteNumber(int Number)
    {
      WriteNumberToSegment(0 , Number / 1000);
      WriteNumberToSegment(1 , (Number / 100) % 10);
      WriteNumberToSegment(2 , (Number / 10) % 10);
      WriteNumberToSegment(3 , Number % 10);
    }
    
    /* Wite a ecimal number between 0 and 9 to one of the 4 digits of the display */
    void WriteNumberToSegment(byte Segment, byte Value)
    {
      digitalWrite(LATCH_DIO,LOW); 
      shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_MAP[Value]);
      shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_SELECT[Segment] );
      digitalWrite(LATCH_DIO,HIGH);    
    }

     

     

     


    동작 확인

    다음과 같이 동작을 확인할 수 있다. 

    https://youtu.be/9PahM2-kA9Y

     

     

     

     

     


     

    Arduino Uno 로 다기능 쉴드를 사용해 LED 차례로 점등시켜 보기

    하드웨어 연결이 완료되면, 아두이노 IDE를 이용해 아두이노 센서 소스코드를 코딩할 수 있다. 

     

    쉴드 코드는 다음과 같다. 

    
    /* Define the DIO pin numbers for each LED */
    const byte LED[] = {13,12,11,10};
    
    void setup()
    {
      /* Set each pin to outputs */
      pinMode(LED[0], OUTPUT);
      pinMode(LED[1], OUTPUT);
      pinMode(LED[2], OUTPUT);
      pinMode(LED[3], OUTPUT);
    }
    
    
    /* Main program */
    void loop()
    {
      byte Index;
      
      /* Step through each LED and turn it on in sequence */
      for(Index = 0; Index <= 3; Index++)
      {
        /* First turn all the LED's off */
        digitalWrite(LED[0], HIGH);
        digitalWrite(LED[1], HIGH);
        digitalWrite(LED[2], HIGH);
        digitalWrite(LED[3], HIGH);
        /* Then turn the next LED ON */
        digitalWrite(LED[Index], LOW);
        /* Wait a little between each sequence */
        delay(100);   
      }
      
      /* Do the same thing but in reverse order */
      for(Index = 3; Index > 0; Index--)
      {
        /* First turn all the LED's off */
        digitalWrite(LED[0], HIGH);
        digitalWrite(LED[1], HIGH);
        digitalWrite(LED[2], HIGH);
        digitalWrite(LED[3], HIGH);
        /* Then turn the next LED ON */
        digitalWrite(LED[Index], LOW);
        /* Wait a little between each sequence */
        delay(100);   
      }
    }

     

     

     


    동작 확인

    다음과 같이 동작을 확인할 수 있다. 

     

    https://youtu.be/BbilkpJzpTM

     

     


     

    Arduino Uno 로 다기능 쉴드를 사용해 피에조 Buzzer 소리내 보기

    하드웨어 연결이 완료되면, 아두이노 IDE를 이용해 아두이노 센서 소스코드를 코딩할 수 있다. 

     

    센서 코드는 다음과 같다. 

    
    /* Define the analogue pin used to read the potentiometer */
    #define POT_DIO 0
    
    /* Define the digital pin used to control the buzzer */
    #define BUZZER_DIO 3
    
    #define OFF HIGH
    #define ON LOW
    
    void setup()
    {
      /* Set the buzzer pin to an output and turn the buzzer off */
      pinMode(BUZZER_DIO, OUTPUT);
      digitalWrite(BUZZER_DIO, OFF);
    }
    
    /* Main Program */
    void loop()
    {
      /* Read the current position of the 10K potentiometer and use it 
         as a time delay */
      delay(analogRead(POT_DIO));
      
      /* Turn the buzzer on for 20ms and then turn it back off again */
      digitalWrite(BUZZER_DIO, ON);
      delay(20);
      digitalWrite(BUZZER_DIO, OFF);
    }

     

     

     


    동작 확인

    다음과 같이 동작을 확인할 수 있다. 

     

    https://youtu.be/ZiRdq0MA7sI

     

     

     

     

     

     


     

    ShieldDemo 파일 실행하기

    하드웨어 연결이 완료되면, 아두이노 IDE를 이용해 아두이노 센서 소스코드를 코딩할 수 있다. 

     

     

    쉴드 코드는 다음과 같다. 

    #include <MFShield.h>
    
    /* Create an object which is needed by library to control the shield */
    	MFShield mfs;
    
    /* This function is called every time any button is pressed */
    /* The only argument means the number of the button pressed */
    void showKey (uint8_t key)
    {
    	// print out the button number
    	Serial.println("Button pressed: " + String (key, DEC));
    
    	// turn on and off a led which has the number equal to the button's number
    	mfs.setLed (key, !mfs.getLed (key));
    
    	// make a short beep for 5 ms (because it's too loud)!
    	mfs.beep (5);
    }
    
    void setup()
    {
    	Serial.begin(9600);
    
    	// Assign the custom function 'showKey' (see above) to the button press event
    	// Note: this function must have one argument (8-bit variable) which defines the button number is being pressed
    	mfs.onKeyPress (showKey);
    }
    
    void loop()
    {
    	// Always insert mfs.loop() in the main loop, without this function the MFShield library wont work.
    	// It's a neccessary routine needed to update the display, poll the buttons and run the internal timer.
    	mfs.loop();
    
    	static uint32_t t = millis();
    	// Run this cycle once every 200 msec
    	if (millis() - t >= 200)
    	{
    		t = millis();
    		// Shows the potentiometer (trimmer) value on it's numeric display
    		uint16_t trimmer = mfs.getTrimmerValue();
    		mfs.display(trimmer);
    	}
    }

     

     

     


    동작 확인

    다음과 같이 동작을 확인할 수 있다. 

     

     


     

    마무리

    아두이노와 아두이노 다기능 확장 쉴드를 연결하고, 간단한 코딩으로 센서를 쉽게 실습할 수 있다. 

     

     

     

     

     

     


     

    모두의 아두이노 환경 센서 책

    [모두의 아두이노 환경 센서] 책은 예스24, 인터넷 교보문고, 알라딘, 인터파크도서, 영풍문고, 반디앤루니스 , 도서11번가 등에서 구입할 수 있다. 이 책에서는 PMS7003, GP2Y1010AU0F, PPD42NS, SDS011 미세먼지 센서, DHT22 온습도 센서, MH-Z19B 이산화탄소 센서, ZE08-CH2O 포름알데히드 센서, CCS811 총휘발성유기화합물 TVOC, GDK101 방사선(감마선) 센서, MQ-131 오존(O3) 센서, MQ-7 일산화탄소, MICS-4514 이산화질소 센서, MICS-6814 암모니아 센서, DGS-SO2 아황산가스(SO2) 센서, BME280 기압 센서, GUVA-S12SD 자외선(UV) 센서, MD0550 기류 센서, QS-FS01 풍속 센서(Wind speed) 를 사용한다.  

     

    모두의 아두이노 환경 센서

    아두이노와 센서로 내 건강을 지킬 수 있다!다양한 환경 센서를 실생활 프로젝트에 응용해보자!시중에 판매되고 있는 간이측정기도 센서로 값을 측정합니다. 똑같은 센서를 아두이노에 연결하

    book.naver.com

    반응형


    댓글