Search Code

TTP223B 터치 모듈과 릴레이를 사용하여 Arduino로 AC/DC 부하를 제어하기

TTP223B 터치 모듈과 릴레이를 사용하여 Arduino로 AC/DC 부하를 제어하기

이 튜토리얼에서는 Arduino와 함께 릴레이를 사용하여 AC 또는 DC 부하를 제어하기 위해 TTP223B 정전식 터치 모듈을 사용하는 방법을 살펴보겠습니다. 이 설정을 통해 전구나 기타 전기 부품과 같은 장치를 터치 기반으로 편리하게 활성화할 수 있습니다. 구성 요소를 배선하는 방법, Arduino 코드를 작성하는 방법, 터치 후 부하가 활성화 상태로 유지되는 시간을 조정하는 방법을 배우게 됩니다. 이 프로젝트는 기술을 확장하려는 초보자와 숙련된 사용자 모두에게 훌륭한 프로젝트입니다.

Schematic of TTP223 module
Arduino wring for TTP223 Touch sensor with relay
TTP223 Touch module - Top view
TTP223 Touch module - Top view

이 가이드 전체에서 필수 구성 요소, 배선 지침, 이 프로젝트를 실행하는 데 필요한 프로그래밍을 안내합니다. 또한 선호도에 따라 부하 활성화 타이밍을 수정하는 방법도 배우게 됩니다(비디오 10:15 참조). 프로세스의 시각적 데모는 첨부된 비디오를 꼭 확인하세요.

하드웨어 설명

이 프로젝트의 주요 구성 요소는 TTP223B 터치 모듈, 릴레이, Arduino입니다. TTP223B 모듈은 터치 입력을 감지하여 Arduino에 신호를 보내며, Arduino는 릴레이를 제어할 수 있습니다. 릴레이는 스위치 역할을 하여 고전압 AC 또는 DC 부하를 안전하게 제어할 수 있게 해줍니다.

TTP223B 칩은 Taiwan Semiconductor(TONTEK)에서 제조하며 모듈은 2.2V ~ 5.5V의 공급 전압에서 작동하고 VCC(전원), GND(접지), SIG(신호)의 세 핀이 있습니다. 터치패드가 활성화되면 SIG 핀이 Arduino에 하이 신호를 보냅니다. 전체 세부 사항은 데이터시트를 참조하세요. 반면 릴레이는 부하를 켜거나 끄기 위해 Arduino의 제어 신호가 필요합니다. 이 제어는 릴레이에 연결된 디지털 출력 핀을 통해 이루어집니다.

데이터시트 세부 정보

제조업체Taiwan Semiconductor(TONTEK)
부품 번호TTP223B
로직/IO 전압2.2 - 5.5V
공급 전압2.2 - 5.5V
출력 전류(채널당)최대 20mA
피크 전류(채널당)최대 50mA
PWM 주파수 지침해당 없음
입력 로직 임계값0.3 * VCC(로우), 0.7 * VCC(하이)
전압 강하 / RDS(on) / 포화해당 없음
열 제한해당 없음
패키지TO-220
참고 사항 / 변형BA6으로도 알려져 있음

  • 오작동 트리거를 방지하려면 적절한 접지를 확인하세요.
  • 터치 신호 라인의 노이즈를 필터링하려면 커패시터를 사용하세요.
  • 부하 요구 사항에 맞게 릴레이 사양을 확인하세요.
  • AC 연결 시 주의하세요. 적절한 절연과 안전 조치를 확인하세요.
  • 원하는 부하 활성화 시간에 맞게 코드에서 타이밍을 조정하세요.

배선 지침

TTP223B 터치 모듈과 릴레이를 Arduino에 배선하려면 다음 단계를 따르세요:

먼저 TTP223B의 VCC 핀을 Arduino 또는 외부 전원의 5V 전원에 연결합니다. 다음으로 TTP223B의 GND 핀을 접지에 연결합니다. SIG 핀은 터치 입력을 읽을 Arduino의 핀 2에 연결해야 합니다.

릴레이의 경우 VCC 핀을 동일한 5V 전원에 연결하고 GND 핀을 접지에 연결합니다. 릴레이의 제어 신호 핀은 Arduino의 핀 10에 연결해야 합니다. 릴레이가 제어하려는 부하에 올바르게 배선되었는지 확인하세요. 한 전선은 공통(COM) 핀에, 다른 전선은 상시 개방(NO) 핀에 연결합니다. 이 설정을 통해 릴레이는 Arduino의 제어 신호에 따라 부하를 켜고 끌 수 있습니다.

코드 예제 및 설명

다음 코드 스니펫은 TTP223B 터치 모듈과 릴레이의 설정을 초기화합니다. 입력 및 출력에 대한 핀 모드를 설정하여 Arduino가 터치 신호를 읽고 릴레이를 제어할 수 있게 합니다.

void setup() {
    Serial.begin(9600);
    pinMode(10, OUTPUT); // 릴레이 제어 핀
    pinMode(2, INPUT);   // 터치 입력 핀
    Serial.println("Robojax 테스트: TTP223B 터치");
}

설정에서 릴레이를 제어하기 위해 핀 10을 출력으로, 터치 신호를 읽기 위해 핀 2를 입력으로 정의합니다. 디버깅 목적으로 시리얼 모니터가 시작됩니다.

프로그램의 메인 루프는 터치 버튼이 눌렸는지 확인합니다. 눌렸다면 릴레이가 활성화되어 연결된 부하가 켜집니다.

void loop() {
    if(digitalRead(2)) {
        Serial.println("버튼 터치됨"); 
        digitalWrite(10, LOW); // 릴레이 켜기     
        delay(LD); 
    } else {
        digitalWrite(10, HIGH); // 릴레이 끄기
    }
}

이 코드는 핀 2의 상태를 지속적으로 읽습니다. 터치 센서가 활성화되면 LD 변수로 정의된 지정된 시간 동안 릴레이를 켭니다. 센서가 터치되지 않으면 릴레이가 꺼집니다.

데모 / 예상 결과

배선을 완료하고 코드를 업로드하면 TTP223B 모듈을 터치할 때 연결된 부하(예: 전구)가 켜지는 것을 볼 수 있습니다. 부하가 켜져 있는 시간은 코드의 LD 변수로 제어됩니다. 부하를 더 오래 켜두려면 LD 값을 원하는 시간(밀리초)으로 늘리면 됩니다.

일반적인 문제로는 잘못된 배선으로 인해 릴레이가 활성화되지 않거나 터치 센서가 응답하지 않는 경우가 있습니다. 모든 연결이 안전하고 코드에 정의된 올바른 핀을 사용하고 있는지 확인하세요. 또한 감전이나 손상을 방지하기 위해 AC 부하를 작업할 때 주의하세요.

비디오 타임스탬프

  • 00:00 - 프로젝트 소개
  • 02:30 - 배선 개요
  • 05:15 - 코드 설명
  • 10:15 - 설정 시연

이미지

Arduino wring for TTP223 Touch sensor with relay (blue)
Arduino wring for TTP223 Touch sensor with relay (blue)
Arduino wring for TTP223 Touch sensor with relay
Arduino wring for TTP223 Touch sensor with relay
TTP223 Touch module - Top view
TTP223 Touch module - Top view
TTP223 Touch module - back view
TTP223 Touch module- back view
TTP223 Touch module - Top view
TTP223 Touch module - Top view
TTP223 Touch module - back view
TTP223 Touch module - back view
Schematic of TTP223 module
Schematic of TTP223 module
21-TTP223B capacitive touch sensor with relay and AC load code
언어: C++
/*
 * This is the Arduino code for TTP223B capacitive touch switch with relay
 * The output pin 10 is connected to the relay 
 * By touching the touch pad TTP223B or TTP223N-BA6, the relay will be turned ON

 * 
 * Written by Ahmad Nejrabi for Roboja Video
 * Date: December 4, 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 LD = 200; // Loop Delay. Controls how long after release the bulb is ON

void setup() {
    Serial.begin(9600);
    // output pins
    pinMode(10, OUTPUT);// LED for button 1
          

    // input pins
    pinMode(2, INPUT);// Button 1 input pin 2  
           


    Serial.println("Robojax Test: TTP223B touch");

}

void loop() {

    // button 1 action
    if(digitalRead(2)){
      Serial.println("Button Touched"); 
      digitalWrite(10, LOW); // Turn the LED ON     
      delay(LD); 
    }else{
      digitalWrite(10, HIGH);// Turn OFF the LED
    }


}// loop
29-How to turn on an AC bulb with a TTP223 capacitive touch Arduino and relay code
언어: C++
/*
 * This is the Arduino code for TTP223 Capacitive Touch switch with relay to turn AC or DC load
 // December 13, 2017
 // Written for Robojax.com video 
 // Using TTP223 Touch module to turn AC (or DC) load ON or OFF.
 // When the touch pad is touched the light on the relay will turn on and the COM and NO pin will be connected
 * watch video for details https://youtu.be/YSI1PdSLbt0
 * 

 * 
 * Written by Ahmad Nejrabi for RoboJax Video
 * Date: December 4, 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.
 * 
 */

 // December 12, 2017
 // Written for Robojax.com video 
 // Using TTP223 Touch module to turn AC (or DC) load ON or OFF.
 // When the touch pad is touched the light on the relay will turn on and the COM and NO pin will be connected


int touchPin = 2;// connect output from TTP223 to this
int val = 0; 
int relayPin = 10;// 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();
}
30-TTP223 Capacitive Touch Arduino with relay code and a 5-second delay
언어: C++
/*
 * This is the Arduino code for TTP223 Capacitive Touch switch with relay to turn AC or DC load with delay
 // December 13, 2017
 // Written for Robojax.com video 
 // Using TTP223 Touch module to turn an AC (or DC) load ON and waits for 5 seconds before it goes OFF
 // When the touch pad is touched the light on the relay will turn on and the COM and NO pins will be connected
 * Watch the video for details: https://youtu.be/YSI1PdSLbt0
 * 

 * 
 * Written by Ahmad Nejrabi for RoboJax Video
 * Date: December 4, 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.
 * 
 */

 // December 12, 2017
 // Written for Robojax.com video 
 // Using TTP223 Touch module to turn an AC (or DC) load ON or OFF.
 // When the touch pad is touched the light on the relay will turn on and the COM and NO pins will be connected


int touchPin = 2;// connect output from TTP223 to this
int val = 0; 
int relayPin = 10;// Connected to relay
int wait = 5;// wait for 5 seconds


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(wait*1000);
  }
  delay(100);
  Serial.println();
}

자원 및 참고자료

아직 자원이 없습니다.

파일📁

데이터시트 (pdf)

다른 파일들