Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:hardware2:sensors_touch [2023/11/17 11:31] raivo.sellen:iot-open:hardware2:sensors_touch [2023/11/23 12:37] (current) pczekalski
Line 1: Line 1:
 +====== Touch Sensors ======
 +{{:en:iot-open:czapka_b.png?50| General audience classification icon }}{{:en:iot-open:czapka_e.png?50| General audience classification icon }}\\
 +== 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// (figure {{ref>button1}}). 
 +<figure button1>
 +{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:push_button_c.jpg?100 | Pushbutton}}
 +<caption>Pushbutton</caption>
 +</figure>
 +
 +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. The 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 (figure {{ref>microswitch1}}).
 + 
 +<figure microswitch1>
 +{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:micro_switch_c.jpg?100 | Microswitch}}
 +<caption>Microswitch</caption>
 +</figure>
 +
 +The most common use of a pushbutton is as an input device. Both force solutions can be used as simple object detectors or end switches in industrial devices. The button can be connected to any available digital pin configured as input or input with a pull-up. In the configuration presented in figure {{ref>pullup1}}, a pull-up resistor is connected externally, so enabling it in the microcontroller is unnecessary.
 +
 +<figure pullup1>
 +{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:sch_apz_shemas_button.png?200 | Schematics of Arduino Uno and a push button}}
 +<caption>Schematics of Arduino Uno and a push button</caption>
 +</figure>
 +
 +An example code:
 +<code c>
 +
 +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
 +}
 +
 +</code>
 +
 +== 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 mechanical forces. Because the force sensor changes its resistance linearly, it should be connected to the analogue input. Connecting another resistor to form the voltage divider is also required, as shown in the figures {{ref>forcesensor1}} and {{ref>forcesensor2}}. The internal ADC of the microcontroller measures the voltage.\\
 +Force sensors are used as control buttons, object presence detectors, or to determine weight in electronic scales.
 +
 +<figure forcesensor1>
 +{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:preasure_sensor_c.jpg?100 | Force sensitive resistor}}
 +<caption>Force sensitive resistor (FSR) </caption>
 +</figure>
 +
 +<figure forcesensor2>
 +{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:sch_apz_shemas_fsr.png?200 | Voltage is measured by applying and measuring constant voltage to the sensor}}
 +<caption>The voltage is measured by applying and measuring constant voltage to the sensor</caption>
 +</figure>
 +
 +An example code:
 +<code c>
 +
 +//Force Sensitive Resistor (FSR) is connected to the analogue 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 analogue 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);
 +}
 +</code>
 +
 +== Capacitive Sensor ==
 +Capacitive sensors are a range of sensors that use capacitance to measure changes in the surrounding environment. A capacitive sensor is a capacitor charged with a certain amount of current until the threshold voltage is reached. A human finger, liquids or other conductive or dielectric materials that touch the sensor can influence the sensor's charge time and voltage level. 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 that they can be connected directly to a digital input pin.\\
 +Capacitive sensors are input devices and can measure proximity, humidity, fluid level and other physical parameters or serve as an input for electronic device control. Sample sensor and its connection are presented in the figures {{ref>capacity1}} and {{ref>capacity2}}.
 +
 +<figure capacity1>
 +{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:touch_senor_c.jpg?200 | Touch button module}}
 +<caption>Touch button module</caption>
 +</figure>
 +
 +<figure capacity2>
 +{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:sch_apz_shemas_capacitive.png?200 | Arduino and capacitive sensor schematics}}
 +<caption>Arduino and capacitive sensor schematics</caption>
 +</figure>
 +
 +<code c>
 +//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; 
 +}
 +</code>
 +
 +<note important>Most of the buttons and switches are of simple construction, so they are subject to a debouncing, as a single press or release of the switch may trigger many changes in the signal (not just a single swap from //LOW// to //HIGH// or opposite). This is because applying force and moving connectors is imperfect and may involve vibration and twinkling. We discuss this problem in the [[en:iot-open:introductiontoembeddedprogramming2:cppfundamentals:programmingpatterns|programming patterns chapter]].
 +</note>
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