1. Overview

Pushing objects around on a screen by just flicking your fingers has become has become second nature. But have you ever wondered how touch screens work? Let’s find out by building our own touch sensor!

Added benefit: getting a feel for differential equations, literally with fingers!

2. Prelab

Although there are many possibilities for sensing touch, including resistive, pressure, optical, etc, capacitive has become the preferred solution in touch screens.

Figure 1 shows the principle. Electrodes, usually behind glass or another non-conductive medium, form one plate of a capacitor with the environment serving as the other. The presence of a finger increases the “coupling” and hence the capacitance. The effect is dominated by the water in living tissue whose permittivity is about 80 times higher than that of air. In displays, Indium tin oxide (ITO), a transparent conductor, is used for the electrodes.

cap touch
Figure 1. Principle of a capacitive touch screen (Acknowledgement)

In this project we use round copper electrodes as sensors. Figure 2 shows the circuit, where capacitor Ct represents the electrode capacitive and Rt is a resistor. The electrode and resistor are connected to a microcontroller input.

cap button
Figure 2. Schematic of the capacitive button sense circuit

Detecting touch now amounts to measuring the value of Ct, which increases in the presence of a finger or other object with high permittivity. Again, there are many options for doing this and many microcontrollers include special interfaces for capacitive touch sensors. A very simple solution consists in pulling Vt high (to 3.3V) with the MCU and then measuring the time taken for it to decay.

In the space provide below, sketch Vt versus time assuming that the MCU GPIO pin is programmed as an output pulling high for t < 0 and as an input for t ≥ 0. Draw two waveforms, one for Ct = 5pF and one for Ct = 50pF and calculate and mark the time t1 at which Vt = 1V for Rt = 1MΩ[1].

Ct t1

5pF

50pF

Write a Python function that takes a pin D as argument, initializes Vt to 3.3V, switches D to an input, and returns the time elapsed until D reads as zero (False).

Save your code in a file called button.py. A simple way to determine the elapsed time t1 uses a counter i initialized to zero. In a loop, increment the counter and stop when D = 0. The final counter value is proportional to the elapsed time.

Template (you’ll need to complete this to make it work!):

# initializations ...
for i in range(300):
    # check if d is zero
    if ...
           print("count", i)
           break

3. Lab

3.1. Oscilloscope

Call the function in button.py for D set to the pin connected to node T4 on the board in a loop and monitor the voltage with the oscilloscope. For convenience, node T4 is available on the header at the side of the board.

Connecting an oscilloscope probe (or anything else) to node T4 adds significant additional capacitance that will change the time constant from when no extra load is present. Be sure to minimize the added capacitance, e.g. by setting the probe attenuation to 10x or 100x and not connecting anything else.

Checkoff:

3.2. Control LED by Touch

Find the threshold for the time delay for each touch button and modify button.py such that the function returns a boolean indicating touch or no-touch.

Then write a program that performs a different action for each button when touched. E.g. turn on an LED, blink, play a sound, etc. Can you control more than one action by touching several buttons simultaneously?

Checkoff:


1. The resistors you soldered to the board may differ from this value.