코드 검색

Arduino용 TTP223 정전식 터치 모듈 소개

Arduino용 TTP223 정전식 터치 모듈 소개

이 튜토리얼에서는 TTP223 정전식 터치 모듈과 이를 아두이노와 통합하여 터치 감지 스위치를 만드는 방법을 살펴보겠습니다. TTP223은 릴레이나 조명과 같은 장치를 터치만으로 켜거나 끌 수 있게 해주는 간단하고 효과적인 모듈입니다. 이 프로젝트는 모듈을 연결하고 터치 입력을 읽고 출력 장치를 제어하는 기본 아두이노 프로그램을 작성하는 방법을 보여줄 것입니다.이 프로젝트의 코드와 배선은 설정을 쉽게 복제할 수 있도록 자세히 설명될 것입니다. 시각적 학습자를 위해 설정 및 코딩 과정에 대한 명확성을 위해 관련 비디오 튜토리얼을 시청하는 것을 추천합니다 (비디오에서 :15).

하드웨어 설명

TTP223 정전식 터치 모듈은 정전식 감지를 통해 터치 입력을 감지하는 작고 사용하기 쉬운 장치입니다. 터치가 감지되면 높은 신호를 보내는 단일 출력 핀이 있어 간단한 터치로 전자 장치를 제어하고자 하는 애플리케이션에 적합합니다. 이 모듈은 2.0에서 5.5볼트의 공급 전압에서 작동하므로 대부분의 아두이노 보드와 호환됩니다. 이 모듈은 일반적으로 몇 개의 핀을 가지고 있습니다: 전원을 위한 VCC, 접지를 위한 GND, 그리고 터치가 감지될 때 신호를 보내는 출력 핀입니다. 이 출력 핀은 아두이노의 디지털 입력 핀에 연결할 수 있어 터치 상태를 쉽게 읽을 수 있습니다. TTP223 모듈은 물리적 스위치가 바람직하지 않은 프로젝트에서 특히 유용합니다.

데이터시트 세부정보

제조업체씨드 스튜디오
부품 번호TTP223
로직/입출력 전압2.0 - 5.5 V
공급 전압2.0 - 5.5 V
출력 전류최대 20 mA
피크 전류30 mA
작동 온도-40에서 85 °C
패키지TO-220

  • 모듈 손상을 방지하기 위해 적절한 전압 공급(2.0 - 5.5 V)을 보장하십시오.
  • 출력 핀은 Arduino의 모든 디지털 핀에 연결할 수 있습니다.
  • GND 핀을 아두이노 접지에 연결하세요.
  • 모듈을 전기 노이즈의 원천에서 멀리 두어 잘못된 트리거를 피하십시오.
  • 필요한 경우 안정적인 판독을 위해 풀업 저항기를 사용하십시오.

배선 지침

TTP223 정전식 터치 모듈을 아두이노에 연결하려면, 먼저 모듈의 VCC 핀을 아두이노의 5V 핀에 연결합니다. 다음으로, 모듈의 GND 핀을 아두이노의 GND 핀 중 하나에 연결합니다. 터치 신호를 전송하는 TTP223의 출력 핀은 아두이노의 디지털 핀에 연결해야 하며, 예를 들어 핀 2에 연결할 수 있습니다. 터치 모듈과 함께 릴레이를 사용하는 경우, 릴레이 제어 핀을 다른 디지털 핀, 예를 들어 핀 8에 연결합니다. 릴레이의 전원 공급 장치가 사양에 맞게 올바르게 연결되었는지 확인하십시오. 여러 개의 터치 모듈을 사용하는 경우, 추가 출력 핀을 아두이노의 다른 디지털 핀에 연결하고 그에 따라 배선 과정을 반복할 수 있습니다.

코드 예제 및 안내

다음 코드 조각은 핀을 초기화하고 직렬 통신을 설정합니다. 변수touchPinTTP223 모듈의 출력에 연결되어 있습니다.relayPin릴레이를 제어합니다.


int touchPin = 2; // connect output from TTP223 to this
int relayPin = 8; // Connected to relay

void setup() {
  Serial.begin(9600);
  pinMode(touchPin, INPUT); 
  pinMode(relayPin, OUTPUT);
}

이 코드는 터치 모듈과 릴레이 핀을 초기화하여 루프 함수에서 사용할 준비를 합니다.Serial.begin(9600)명령은 직렬 통신을 위한 전송 속도를 설정하여 Serial Monitor를 통해 터치 상태를 모니터링할 수 있게 합니다. 루프에서 프로그램은 터치 입력의 상태를 확인하고 그에 따라 릴레이를 전환합니다. 터치가 감지되면 "Touched"라는 메시지를 Serial Monitor에 출력하고 릴레이를 켭니다.


void loop() {
  val = digitalRead(touchPin); 
  if(val == 1) {
    Serial.println("Touched");
    digitalWrite(relayPin, LOW); // turn relay ON
  }
  delay(100);
}

이 발췌는 터치 입력이 어떻게 읽히고 처리되는지를 보여줍니다.digitalRead(touchPin)터치가 감지되었는지 확인하는 함수입니다. 감지되었다면, 릴레이가 설정되어 활성화됩니다.relayPin낮추다.

시연 / 기대할 사항

코드를 실행하고 TTP223 모듈을 터치하면 "Touched"라는 메시지가 시리얼 모니터에 출력되어 터치가 감지되었음을 나타냅니다. 연결된 릴레이는relayPin또한 활성화되어 연결된 모든 장치를 제어할 수 있습니다. 디바운스 효과에 유의하세요. 센서를 너무 빠르게 터치하면 여러 번 터치로 인식될 수 있습니다. 더 복잡한 설정을 위해 여러 개의 TTP223 모듈을 추가하여 다양한 장치를 제어할 수 있습니다. 각 모듈은 별도의 입력 핀에 연결할 수 있으며 동일한 루프 함수에서 관리할 수 있어 여러 출력을 다재다능하게 제어할 수 있습니다 (비디오에서 10:45).

비디오 타임스탬프

  • 00:00- TTP223 모듈 소개
  • 03:15- 배선 지침
  • 05:30- 코드 워크스루
  • 10:45- 터치 모듈 시연
8-The source code for the TTP223 touch module for Arduino
언어: C++
/*
 * This is the Arduino code for a TTP223 Touch module switch.
 * By touching the module, the pin 8 sends a signal to turn the relay or switch ON.
 * 
 * Written by Ahmad S. for Robojax.com 
 * Date: April 1, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code, given that this
 * note is kept with the code.
 * Disclaimer: This code is "AS IS" and for educational purposes only.
 * 
 */

int touchPin = 2;// connect output from TTP223 to this
int val = 0; 
int relayPin = 8;// Connected to relay

void setup() {
 Serial.begin(9600);
 pinMode(touchPin, INPUT); 
  pinMode(relayPin, OUTPUT);

}

void loop() {
  digitalWrite(relayPin, HIGH);
  val = digitalRead(touchPin); 
  if(val ==1){
  Serial.println("Touched");
  digitalWrite(relayPin, LOW);
  }
  delay(100);
  Serial.println();
}
9-The source code for the TTP223 touch module for Arduino for a two-touch module
언어: C++
/*
 * This is the Arduino code for a TTP223 touch module switch.
 * By touching the module, the pin 8 is sending a signal to turn the relay or switch ON.
 * 
 * Written by Ahmad S. for Robojax.com 
 * Date: April 1, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code, given that this
 * note is kept with the code.
 * Disclaimer: This code is "AS IS" and for educational purposes only.
 * 
 */

 // 1st channel
int touchPin1 = 2;// connect output from TTP223 to this
int val = 0; 
int relayPin = 8;// Connected to relay

 // 2nd channel
int touchPin2 = 3;// connect output from TTP223 to this
int val2 = 0; 
int relayPin2 = 9;// Connected to relay

void setup() {
 Serial.begin(9600);
 pinMode(touchPin, INPUT); // input from touch
 pinMode(relayPin, OUTPUT);// output to relay
 
  pinMode(touchPin2, INPUT); // input from touch (2)
 pinMode(relayPin2, OUTPUT);// output to relay (2)

}

void loop() {
 // start of channel 1 code 
  digitalWrite(relayPin, HIGH);// set the relay to HIGH (if your relay is low-trigger. If not, remove this line)
  val = digitalRead(touchPin); // read channel 1 touch module value
  if(val ==1){
  Serial.println("Channel 1 Touched");
  digitalWrite(relayPin, LOW);// turn relay (of switch) 1 ON
  }
  delay(100);
  Serial.println();
   // end of channel 1 code 
  
 // start of channel 2 code   
  digitalWrite(relayPin2, HIGH);// set the relay to HIGH (if your relay is low-trigger. If not, remove this line)
  val2 = digitalRead(touchPin2); // read channel 2 touch module value
  if(val2 ==1){
  Serial.println("Channel 2 Touched");
  digitalWrite(relayPin2, LOW);// turn relay (of switch) 2 ON
  }
  delay(100);
  Serial.println();
  // end of channel 2 code 
}

자원 및 참고자료

아직 자원이 없습니다.

파일📁

다른 파일들