Introduction
A metal touch sensor is a type of switch that only operates when it’s touched by a charged body. It has a high-frequency transistor which is energized when receiving electromagnetic signals.
Components
– 1 * SunFounder Uno board
– 1 * USB data cable
– 1 * Touch Switch module
– 1 * 3-Pin anti-reverse cable
Experimental Principle
In this experiment, touch the base electrode of the transistor to make it conduct electricity, for human body itself is a kind of conductor and an antenna that can receive electromagnetic waves in the air.
Experimental Procedures
Step 1: Build the circuit
Step 2: Program (Please refer to the example code in LEARN -> Get Tutorial on our website)
Step 3: Compile
Step 4: Upload the sketch to SunFounder Uno board
When the module is electrified, the original state of pin SIG is low and the LED onside is on. Now, touch the electrode with your finger. Then it outputs high and the LED on it and that attached to pin 13 on the SunFounder Uno board will go out. Move away and touch it again, and it’ll output low with the LEDs turned on, and so forth. Thus, the output level changes between high and low with each touch, together with LEDs brightening and dimming.
Code
/*************************************************** name:Touch Switch function: ************************************************/ //Email:support@sunfounder.com //Website:www.sunfounder.com const int SensorPin=7; //touch switch attach to pin7 const int ledPin = 13; //pin13 built-in ledint SensorState=0; //store the value of touch switchvoid setup() { pinMode(SensorPin,INPUT);//set sensorPin as INPUT pinMode(ledPin,OUTPUT); // set ledPin as OUTPUT Serial.begin(9600); //initialize the serial monitor }void loop() { SensorState=digitalRead(SensorPin);//read the value of pin7 Serial.println( SensorState);//print it in serial monitor if(SensorState==HIGH) //if the value is HIGH { digitalWrite(ledPin,LOW); //turn off the led } else { digitalWrite(ledPin,HIGH); //turn on the led } } |