Switch Module(KY-004): 두 판 사이의 차이

아두위키 : Arduwiki
(새 문서: {{#seo:|title=아두위키 : 아두이노 스위치 모듈(KY-004) 가이드|title_mode=append|keywords=아두이노, 정보과학, 메이커학습, 수행평가, 스위치 모듈(KY-004), 아두이노 작품, 캡스톤작품, 아두이노 예제코드|description=아두이노로 스위치 모듈(KY-004)를 제어하는 방법(기본정보, 회로, 예제 코드)을 소개합니다. 정보과학과 메이커수업에 활용가능합니다.}} 파일:Ky004스위치모듈.jpg|...)
 
잔글편집 요약 없음
 
1번째 줄: 1번째 줄:
{{#seo:|title=아두위키 : 아두이노 스위치 모듈(KY-004) 가이드|title_mode=append|keywords=아두이노, 정보과학, 메이커학습, 수행평가, 스위치 모듈(KY-004), 아두이노 작품, 캡스톤작품, 아두이노 예제코드|description=아두이노로 스위치 모듈(KY-004)를 제어하는 방법(기본정보, 회로, 예제 코드)을 소개합니다. 정보과학과 메이커수업에 활용가능합니다.}}
{{#seo:|title=Arduwiki : Arduino Switch Module(KY-004) Guide|title_mode=append|keywords=Arduino, Information Science, Maker Learning, Performance Assessment, Switch Module(KY-004), Arduino Project, Capstone Project, Arduino Example Code|description=This introduces how to control a Switch Module(KY-004) with Arduino (basic information, circuit, example code). It can be used in Information Science and Maker classes.}}


[[파일:Ky004스위치모듈.jpg|가운데|class=coders100]]
[[파일:Ky004스위치모듈.jpg|가운데|class=coders100]]


== '''개요''' ==
== '''Overview''' ==
KY-004 스위치 모듈은 아두이노 보드와 호환되는 간단한 스위치 입력 모듈입니다. 아두이노 보드에 연결하여 스위치 입력을 받을 수 있습니다.
The KY-004 switch module is a simple switch input module compatible with Arduino boards. It can be connected to an Arduino board to receive switch input.


[[택트 스위치(Tact Switch)]]와 거의 동일한 기능을 하는 모듈이기 때문에 플로팅 현상, 풀업, 풀다운 저항 등 스위치와 관련된 다른 자세한 내용은 [[택트 스위치(Tact Switch)|택트 스위치]] 문서를 참고해주세요.
Since it functions almost identically to a [[Tact Switch]], for details related to switches such as floating phenomena, pull-up, and pull-down resistors, please refer to the [[Tact Switch|Tact Switch]] document.




== '''사양''' ==
== '''Specifications''' ==


* 작동 전압: 3.3V ~ 5V
*Operating Voltage: 3.3V ~ 5V
* 스위치 출력 레벨: LOW(0V) / HIGH(VCC)
*Switch Output Level: LOW (0V) / HIGH (VCC)




== '''활용 예제''' ==
== '''Application Example''' ==


=== 1. 시리얼 모니터로 스위치 입력 여부 확인 ===
=== 1. Checking Switch Input via Serial Monitor ===
스위치를 눌렀는지, 누르지 않았는지 시리얼 모니터로 확인하는 예제입니다.
This example demonstrates how to check whether the switch has been pressed or not using the serial monitor.


 
==== Circuit Configuration ====
==== 회로 구성 ====
[[파일:Ky004예제1회로.jpg|가운데|class=coders100]]
[[파일:Ky004예제1회로.jpg|가운데|class=coders100]]


==== 아두이노 코드 ====
==== Code ====
<syntaxhighlight lang="c++" line="1">
<syntaxhighlight lang="c++" line="1">
int switchPin = 2; // KY-004 모듈의 OUT 핀을 2번 디지털 핀에 연결
int switchPin = 2; // Connect the OUT pin of the KY-004 module to Arduino digital pin 2.


void setup() {
void setup() {
   pinMode(switchPin, INPUT);
   pinMode(switchPin, INPUT);
   Serial.begin(9600); // 시리얼 통신 시작
   Serial.begin(9600); // Start serial communication.
}
}


void loop() {
void loop() {
   int switchState = digitalRead(switchPin); // 스위치 상태 읽기
   int switchState = digitalRead(switchPin); // Read the switch status.
    
    
   if (switchState == LOW) { // 스위치가 눌렸을 때
   if (switchState == LOW) { // When the switch is pressed
     Serial.println("스위치 누름");
     Serial.println("Switch pressed");
   } else { // 스위치가 눌리지 않았을 때
   } else { // When the switch is not pressed
     Serial.println("스위치 누르지 않음");
     Serial.println("Switch not pressed");
   }
   }
    
    
   delay(100); // 100ms 딜레이
   delay(100); // Wait for 0.1second
}
}
</syntaxhighlight>
</syntaxhighlight>




==== 실행 결과 ====
==== Execution Result ====
스위치의 상태가 시리얼 모니터에 표시됩니다.
The status of the switch will be displayed on the serial monitor.


[[파일:Ky004예제1실행결과.png|가운데|class=coders100]]
[[파일:Ky004예제1실행결과.png|가운데|class=coders100]]




=== 2. 스위치와 LED를 함께 활용하기 ===
=== 2. Using Switch and LED Together ===
스위치를 누르면 LED가 켜지고, 누르지 않으면 LED가 꺼지는 예제입니다.
This example demonstrates that when the switch is pressed, the LED lights up, and when it is not pressed, the LED turns off.




==== 회로 구성 ====
==== Circuit Configuration ====
[[파일:Ky004예제2회로.jpg|가운데|class=coders100]]
[[파일:Ky004예제2회로.jpg|가운데|class=coders100]]




==== 아두이노 코드 ====
==== Code ====
<syntaxhighlight lang="c++" line="1">
<syntaxhighlight lang="c++" line="1">
int switchPin = 2; // KY-004 스위치 모듈 연결 핀
int switchPin = 2; // Connect the OUT pin of the KY-004 module to Arduino digital pin 2.
int ledPin = 13; // LED 연결 핀
int ledPin = 13; // Led Pin


void setup() {
void setup() {
   pinMode(switchPin, INPUT);
   pinMode(switchPin, INPUT);
   pinMode(ledPin, OUTPUT); // LED 핀을 출력으로 설정
   pinMode(ledPin, OUTPUT);
}
}


void loop() {
void loop() {
   int switchState = digitalRead(switchPin); // 스위치 상태 읽기
   int switchState = digitalRead(switchPin); // Read the switch status.


   // 스위치가 눌려있으면(LOW 레벨)
   // 스위치가 눌려있으면(LOW)
   if (switchState == LOW) {
   if (switchState == LOW) {
     digitalWrite(ledPin, HIGH); // LED 켜기
     digitalWrite(ledPin, HIGH); // Turn on the LED
   } else {
   } else {
     digitalWrite(ledPin, LOW); // LED 끄기
     digitalWrite(ledPin, LOW); // Trun off the LED
   }
   }
}
}
84번째 줄: 83번째 줄:




==== 실행 결과 ====
==== Execution Result ====
스위치를 누를 때만 LED가 켜지는 것을 확인하실 수 있습니다.
You can confirm that the LED lights up only when the switch is pressed.


[[파일:Ky004예제2실행결과.jpg|가운데|class=coders100]]
[[파일:Ky004예제2실행결과.jpg|가운데|class=coders100]]




== '''구매 링크''' ==
== '''Purchase Link''' ==
[https://gongzipsa.com/shop/1712917627 공집사몰]
[https://gongzipsa.com/shop/1712917627 GONGZIPSA]

2024년 8월 9일 (금) 15:40 기준 최신판


Overview

The KY-004 switch module is a simple switch input module compatible with Arduino boards. It can be connected to an Arduino board to receive switch input.

Since it functions almost identically to a Tact Switch, for details related to switches such as floating phenomena, pull-up, and pull-down resistors, please refer to the Tact Switch document.


Specifications

  • Operating Voltage: 3.3V ~ 5V
  • Switch Output Level: LOW (0V) / HIGH (VCC)


Application Example

1. Checking Switch Input via Serial Monitor

This example demonstrates how to check whether the switch has been pressed or not using the serial monitor.

Circuit Configuration

Code

int switchPin = 2; // Connect the OUT pin of the KY-004 module to Arduino digital pin 2.

void setup() {
  pinMode(switchPin, INPUT);
  Serial.begin(9600); // Start serial communication.
}

void loop() {
  int switchState = digitalRead(switchPin); // Read the switch status.
  
  if (switchState == LOW) { // When the switch is pressed
    Serial.println("Switch pressed");
  } else { // When the switch is not pressed
    Serial.println("Switch not pressed");
  }
  
  delay(100); // Wait for 0.1second
}


Execution Result

The status of the switch will be displayed on the serial monitor.


2. Using Switch and LED Together

This example demonstrates that when the switch is pressed, the LED lights up, and when it is not pressed, the LED turns off.


Circuit Configuration


Code

int switchPin = 2; // Connect the OUT pin of the KY-004 module to Arduino digital pin 2.
int ledPin = 13; // Led Pin

void setup() {
  pinMode(switchPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int switchState = digitalRead(switchPin); // Read the switch status.

  // 스위치가 눌려있으면(LOW)
  if (switchState == LOW) {
    digitalWrite(ledPin, HIGH); // Turn on the LED
  } else {
    digitalWrite(ledPin, LOW); // Trun off the LED
  }
}


Execution Result

You can confirm that the LED lights up only when the switch is pressed.


Purchase Link

GONGZIPSA