This is an old revision of the document!


Touch Sensors

Button

A pushbutton is an electromechanical sensor that connects or disconnects two points in a circuit when force is applied. The button output discrete value is either HIGH or LOW.

 title
Figure 1: Pushbutton.

A microswitch, also called a miniature snap-action switch, is an electromechanical sensor that requires very little physical force and uses a tipping-point mechanism. Microswitch has three pins, two of which are connected by default. When the force is applied, the first connection breaks and one of the pins is connected to the third pin.

 title
Figure 2: Microswitch.

The most common use of a pushbutton is as an input device. Both force solutions can be used as simple object detectors, or as end switches in industrial devices. The button can be connected to any available digital pin that must be configured as input or input with a pullup. In the configuration presented in the figure below a pullup resistor is connected externally so there is no need to enable it in the microcontroller.

 title
Figure 3: Schematics of Arduino Uno and a push button.

An example code:

int buttonPin = 2; //Initialization of a push button pin number
int buttonState = 0; //A variable for reading the push button status
 
void setup() {
  Serial.begin(9600);  //Begin serial communication
  pinMode(buttonPin, INPUT); //Initialize the push button pin as an input
}
 
void loop() {
  //Read the state of the pin where a button is connected
  //it is LOW if a button is pressed, HIGH otherwise
  //the buttonState variable holds the compliment state of the buttonPin
  buttonState = !digitalRead(buttonPin);
  //Check if the push button is pressed. If it is, the buttonState variable is HIGH
  if (buttonState == HIGH) { 
    //Print out text in the console
    Serial.println("The button state variable is HIGH - it is pressed."); 
  } else {
    Serial.println("The button state variable is LOW - it is not pressed.");
  }
  delay(10); //Delay in between reads for stability
}
Force Sensor

A force sensor predictably changes resistance, depending on the applied force to its surface. Force-sensing resistors are manufactured in different shapes and sizes, and they can measure not only direct force but also tension, compression, torsion and other types of mechanical forces. Because the force sensor changes its resistance linearly it should be connected to analog input. It is also required o connect another resistor to form the voltage divider, as shown in the figure below. The voltage is measured by the internal ADC of the microcontroller.

Force sensors are used as control buttons, object presence detectors, or to determine weight in electronic scales.

 title
Figure 4: Force sensitive resistor (FSR).
title
Figure 5: The voltage is measured by applying and measuring constant voltage to the sensor.

An example code:

//Force Sensitive Resistor (FSR) is connected to the analog 0 pin
int fsrPin = A0; 
//The analog reading from the FSR resistor divider
int fsrReading;      
 
void setup(void) {
  //Begin serial communication
  Serial.begin(9600);   
  //Initialize the FSR analog pin as an input
  pinMode(fsrPin, INPUT); 
}
 
void loop(void) {
  //Read the resistance value of the FSR
  fsrReading = analogRead(fsrPin); 
  //Print 
  Serial.print("Analog reading = "); 
  Serial.println(fsrReading);
  delay(10);
}
Capacitive Sensor

Capacitive sensors are a range of sensors that use capacitance to measure changes in the surrounding environment. A capacitive sensor consists of a capacitor that is charged with a certain amount of current until the threshold voltage. A human finger, liquids or other conductive or dielectric materials that touch the sensor, can influence a charge time and a voltage level in the sensor. Measuring charge time and voltage level gives information about changes in the environment. Ready-to-use sensors include an electronic element that performs measurements and returns digital information at the output, so they can be connected directly to a digital input pin.

Capacitive sensors are used as input devices and can measure proximity, humidity, fluid level and other physical parameters or serve as an input for electronic device control.

 title
Figure 6: Touch button module.
 title
Figure 7: Arduino and capacitive sensor schematics.
//Capacitive sensor is connected to the digital 2 pin
int touchPin = 2; 
 
//The variable that stores digital value read from the sensor
boolean touchReading = LOW; 
//The variable that stores the previous state of the sensor
boolean lastState = LOW; 
 
void setup() {
  //Begin serial communication
  Serial.begin(9600);  
  //Initialize the capacitive sensor analogue pin as an input
  pinMode(touchPin, INPUT);  
}
 
void loop() {
  //Read the digital value of the capacitive sensor
  touchReading = digitalRead(touchPin); 
  //If the new touch has appeared
  if (currentState == HIGH && lastState == LOW){ 
    Serial.println("Sensor is pressed");
    delay(10); //short delay
  }
  //Save the previous state to see relative changes
  lastState = currentState; 
}
en/iot-open/hardware2/sensors_touch.1688049394.txt.gz · Last modified: 2023/06/29 11:36 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0