How to interface KY-036 touch sensor with Arduino

How to use a touch sensor (KY-036) with Arduino & how the touch sensor works are some questions that may arise in your mind while programming an Arduino.

Hello guy! Welcome back to my blog today we are going to see about Touch sensor KY 036. so let’s begin.

What are Touch sensors??

resistive touch sensor

KY-036 is a touch sensor module that generates an output signal when being touched. KY-036 touch sensor consists of KRS13 Darlington NPN transistor as the main element, along with LM393 comparator and potentiometer to adjust its sensitivity. 

KY-036 touch sensor

 How KY-036 touch sensor works??

A wire is bent over a transistor which acts as the base of the transistor. When we touch this wire by hand or some conducting material, then the signal is produced amplified by the amplifier, and fed to a comparator where it is compared with an already pre-defined value that switches digital output and on-board LED. When we touch the bent wire then the digital output will be 1 and if not touched then the output will be 0. In short when we set a threshold by rotating a knob and if the sensor value exceeds the threshold value then the output is 1 and if the sensor value is less than the set threshold value then the output will be 0 When we will touch the wire then the on-board led will starts blinking which indicates output. Actually, the sensor consists of two LEDs, one led shows that the board is working its power ON and the other led glows when we touch the sensor. Our human body is a good conductor of electricity it acts as a conductor therefore when touching a bent wire over the transistor of the touch sensor induces a current which is detected by Arduino through a sensor such a type of technology we often see in our day-to-day life in touch screen mobile phones.

how touch sensor Arduino works

You can control the sensitivity by adjusting or rotating the potentiometer. If we rotate the knob clockwise then sensitivity increases and if we rotate the knob anti-clockwise then sensitivity decreases. You adjust pre-defined values by this knob. The signal may be inverted means when a high value is measured, it will show low voltage. This type of sensor has wide applications in security systems, touch-door locks, detecting current in material, etc.

Parts Required

  • KY-036 (touch sensor module Arduino)
  • Jumper wires
  • LED
  • Breadboard

Schematic Diagram


Arduino touch sensor

Connect the ground pin of the touch sensor to the ground pin of the Arduino, the VCC pin to 5v, and the Signal pin to 8. Also, connect the positive lead of LED to Arduino pin 11.

Code - 

int ledpin=11;
int sensorpin=8;
int sensorvalue;
void setup()
{
 pinMode(ledpin,OUTPUT); 
 pinMode(sensorpin,INPUT);
 Serial.begin(115200);
}
void loop() 
{
 sensorvalue = digitalRead(sensorpin); 
 //Serial.println(sensorvalue);
 if(sensorvalue==HIGH)
 {
  digitalWrite(ledpin,HIGH);
  Serial.println("Touching");
  }
 else
 {
  digitalWrite(ledpin,LOW);
  Serial.println("NO Touch");
 }
 delay(50);
}

First, initialize pins of sensors & LED and variables. We have declared a variable name sensor value to read values from sensors. In the void setup, we configure pins as INPUT or OUTPUT. We want to read values from the sensor pin so we will declare it as INPUT. Also, we configure the baud rate to 115200.

In the void loop, we continuously read values from the touch sensor and store values in variable name sensor value and we check here condition if it is HIGH or not. HIGH means we have a touch wire on the module and the sensor sends a HIGH signal to our Arduino which we printed as “Touching”. Here we have written code to turn ON led when the light is blocked

When we don’t touch the bent wire on the module then the sensor sends a LOW signal to Arduino which is printed as “No Touch“ and the LED connected to pin 11 will be turned OFF. We have introduced a delay of 50 milliseconds.

touch sensor Arduino

ky-036 touch sensor

OUTPUT - 


Now we used the serial monitor to observe the output. . To open up the serial monitor, click on Tools > Serial Monitor or use the shortcut (SHIFT + CONTROL + M)You can see output on the Serial monitor. When we touch the sensor then the output will be “Touching” and when we don’t touch the sensor the output will be “No Touch”.

 Conclusion - 

Today we learn about what is KY-036 touch sensor or resistive touch sensor Arduino is, the working principle of the KY-036 touch sensor & how to use the KY-036 touch sensor with Arduino.

"I hope you find this IoT blog very helpful. In the upcoming lesson we will see more about IoT sensors till then bye. See you all in my next blog".

Close Menu