Capacitive Touch Sensor

The questions below are due on Friday March 22, 2024; 05:00:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Getting Help

Remember that labs are a learning experience, not a test, so please ask us questions as you're working through!

Although we do want everyone to work individually and build their own circuits, it is also more than OK to ask friends/neighbors for help, too.

A Note About Timing

For this lab, we also expect that checkoff 1 will take the majority of the time for this lab. Please read everything and don't rush through it.

In this lab, we'll experiment with RC networks. We'll start by running some small experiments to see that the currents and voltages throughout such a network match what we expect from circuit theory; and then we'll see this idea applied in a neat application, building a little touch sensor that works using the same principles as modern touchscreens, by detecting changes in capacitance as you touch the sensor:

1) Rise and Shine

Scope Setup

Before building, let's go ahead and turn on the scope (we'll need it later) and reset it to all of its defaults by:

  • Pushing the "Default Setup" button in the upper left, and
  • Under the "Wave Gen" menu (accessible by pushing the button in the bottom right), click the "Settings" button (the bottom one on the screen), then click the "Default Wave Gen" button (the bottom one again) You should get a message on screen saying that things have been reset.

Here is the basic form of the circuit we're going to be working with today (it should look familiar from recitation and lecture this week!):

To start, we'll use 33{\rm nF} for the capacitance. Recall that nano (n) means 10^{-9}.

Given the values of R and C above, what is the (theoretical) time constant of this circuit, in seconds?
\tau =~

In a moment, we're going to build the circuit above, and we're going to set up the voltage source so that it produces a 5Hz square wave, alternating between 3.3 Volts and 0 Volts like so:

But for now, we're just going to think about this in terms of theory first, to make sure we know what to expect before moving on.

Check Yourself 1:
Given this shape of V_s(t), sketch i_C(t) and v_C(t) as functions of time (by hand, not with a graphing calculator or desmos or whatever). If you're having trouble thinking about this, please ask us for help!

Among other things, it may be helpful to think about:

  • The time constant of our circuit, compared against the amount of time for which V_s(t) is held constant. This can help us figure out what we expect v_C(t) to look like.
  • What happens immediately before/after V_s(t) changes values, which can help us figure out some things about i_C(t).

Label your sketch with all the key values (time constants, min/max values) and try to get the shape as right as you can.

Be prepared to discuss these sketches and your method for generating them during your checkoff.

Given this shape of V_s(t), what are the approximate maximum and minimum values we expect i_C(t) to have? Enter your answers as a Python list \displaystyle [\max_t(i_C(t)), \min_t(i_C(t))] with the values measured in Amperes.

 

If you're having trouble with any of the above, please ask for help! But...
DO NOT PROCEED UNLESS YOU HAVE A DRAWING THAT YOU THINK IS CORRECT!

 

2) Building It

Now that we have a prediction in mind, let's build the circuit and run an experiment to verify that we actually see results that match our expectations. We should be able to verify the general shape that we're expecting, as well as the numerical values like the time constant and the minimum/maximum current.

Before Building

If you didn't already do so earlier, reset the scope to its default values by:

  • Pushing the "Default Setup" button in the upper left, and
  • Under the "Wave Gen" menu (accessible by pushing the button in the bottom right), click the "Settings" button (the bottom one on the screen), then click the "Default Wave Gen" button (the bottom one again) You should get a message on screen saying that things have been reset.

Let's go ahead and build the circuit now, by following these steps:

  • Hook up a resistor and capacitor as shown in the schematic above, using a 33{\rm nF} capacitor to start.

    Capacitors are in the same cabinet as the resistors. Capacitors are typically not labeled with nanofarads, though, only powers of 10^{-6} (so {\rm F}, \mu{\rm F}, {\rm pF}). So when you go to the cabinet, you'll need to pick the right one. Nano ({\rm n}) is 10^{-9} and micro (\mu) is 10^{-6}, so if we want 33{\rm nF}, what should we grab in terms of \mu{\rm F}?

  • Set up channel 1 on the scope to measure V_s(t) and channel 2 to measure v_C(t).

  • Set the trigger to normal mode, and have it trigger on the rising edge of channel 1. Slide your trigger up so that it is triggering when we cross around 1.65 Volts.

  • Set up your scope's wave generator to a square wave with a 5Hz frequency, 3.3Volt peak-to-peak amplitude, and an offset of 1.65Volts. This will act as the voltage source in the schematic diagram above.

  • Set the vertical scale to 500{{\rm mV}\over \text{div}} for each channel and set the time scale to 10{{\rm ms}\over \text{div}}. Using the knobs on the scope, adjust things so that you can see clearly see the exponential shape of the voltage across the capacitor.

Check Yourself 2:
Does the shape you see on channel 2 match what you expected given the graph?

Let's also measure the rise time to see whether it matches our prediction from earlier. We can do this using the "Meas" button. Under the "Type" submenu, we can choose "rise time," which computes the measure we discussed in the prelab (if you haven't already done so, maybe worth going back and doing the that now).

Use this menu to add a measurement for the rise time of v_C(t). What is the measured rise time, in milliseconds?

Check Yourself 3:
What value of \tau does that rise time correspond to? How does that value compare to the result you calculated using theory in part 1?

Finally, we'll add another graph so we can measure the current. Unfortunately, like we saw last week, we don't have a great way to measure current directly (the scopes only really measure voltages). But luckily, we have a voltage elsewhere in the circuit that is proportional to i_C(t), so we can measure that and back-solve for i_C(t). In particular, we'll measure the voltage drop across the resistor.

Unfortunately, though, our scopes make measuring that value directly a little bit difficult, since the "-" sides of the scope's input channels are all internally wired to ground. So we can't just put probes across the resistor to measure this voltage. Luckily, though, the scope still gives us a way to make this measurement, using its built-in math capabilities. Click the "Math" button near the bottom left of the scope. This will bring up a menu where we can force the scope to compute various different values for us. The "Operator" submenu lets us choose a mathematical operation to perform, and we can also choose what sources are used for the calculation. The result will be plotted in pink on its own scale, which you can adjust using the knobs right near the Math button.

Check Yourself 4:
How can we compute the voltage drop across the resistor from the two signals we're already measuring?

Check Yourself 5:
Use the 'Math' menu to add a plot of the voltage drop across the resistor. Do these results match what you would expect given your predictions for i_C(t), both in terms of its general shape and in terms of its time constant and max and min values? Be prepared to discuss all of these during your checkoff.

Checkoff 1:
Discuss the results of your experiments so far with a staff member. Be prepared to explain your results and also to relate them to circuit theory.

3) Teensy

For the remainder of the lab, we'll see these ideas applied in a neat way: by building a touch sensor that works by measuring changes in capacitance that result from us touching a little sensor.

As a first step toward this, go ahead and grab a Teensy from the front of the room, and also download touchsensor.zip and open up the code in Arduino and flash it to your Teensy. Part of what that Teensy code is doing is generating a square wave (like the one we've been using but four times as fast) on pin 14 of the Teensy.

Then shuffle things around on your breadboard so that this resembles our circuit from before, but with the Teensy providing V_s(t). Hook up the resistor between pins 14 and 20 of the Teensy, then connect your 33{\rm nF} capacitor between pin 20 and ground. Put the channel 1 probe back on pins 20 and ground (i.e., measuring the drop across that capacitor) and verify that what you see on the scope matches what we saw from before.

Check Yourself 6:
Does your graph for the voltage look like what we saw before? Does the rise time match your expectation?

4) Touch Sensor

If that all looks like what we're expecting, we're ready to proceed with making our touch sensor! Here's what this part will look like in the end:

Notice how just a little touch of the sensor makes the LED light up.

We're going to build our little sensor by replacing the fixed 33{\rm nF} capacitor in the board with a different capacitance that's coming not from a discrete component like the one we grabbed from the cabinet, but from the outside world.

To start, remove the capacitor from your board. Then make a little loop of wire like the following (cut off a length of wire, strip the two ends, and then make a couple of loops on one side), which will act as our touch sensor:

Plug the non-loopy side of your loopy thing into the breadboard on pin 20, and don't connect the other end to anything (leave it sticking up in the air; that will be the thing that we touch):

Now, connect the scope back up to measure between pin 20 and ground. You may need to fiddle with the zoom levels a little bit to see it, but even though our input wave is a square wave, there is still a characteristic exponential curve here with a nontrivial rise time.

This might be surprising given that we're looking at an open circuit here, but that shape suggests that there is actually a closed loop here that has some capacitance, even though we don't explicitly have a capacitor connected! Something like:

Check Yourself 7:
What is the rise time of the curve now? Using this, what does this mean in terms of the capacitance of this phantom capacitor? Use this to estimate \tau and write that value down; we'll need it for later.

That capacitance is actually coming from a (perhaps) surprising source. Again, we haven't connected a capacitor explicitly, but what is a capacitor? A pair of metal plates, right? It turns out that we've got a whole bunch of things like that inside of the breadboard; if we take off the backing of the breadboard, the way things are connected up is exactly a bunch of little metal plates. So the grey capacitor in the diagram above is actually coming from the breadboard mind_blown emoji:

Next, grab on to the ground clip of the scope with your left hand, and touch the touch sensor (your little loop from before) with your other hand, looking at your scope as you do so. You should see a dramatic change in the curve, meaning that the time constant has changed!

We can think of this as connecting up another component (YOU!) in parallel with the capacitance from the breadboard. Humans are complicated things, but in our lumped-element abstraction, we'll make a simplifiying assumption, modeling you purely as a capacitor:

This is definitely an oversimplification (you're more than just a capacitor...) but it can allow us to think about what is happening here.

Check Yourself 8:
What is the new rise time of the curve while you're holding ground and touching the sensor? Use this to estimate \tau and write that value down.

Did connecting yourself up cause the capacitance between pin 20 and ground to go up or down?

The Teensy code for today does some work to estimate the time constant associated with this circuit at any given time, and a threshold value called tauThreshold. If \tau is above this value, we assume that the touch sensor is being touched, and if it's below, we assume it's not being touched. Using your values from before, choose a value about halfway between them, and set tauThreshold to that value (then recompile the code and re-flash it to your Teensy). Before flashing, under Tools->CPU Speed, set it to "816MHz (overclock)".

To see whether it's working, we'll connect an LED (light-emitting diode) between pin 0 and ground. We have LEDs at the front of the room; pick your favorite color. Make sure when you plug it in that the longer of the two legs is connected to pin 0, and the shorter one is connected to ground.

If everything is working, you should see the LED light up when you're holding the ground connector and touching the sensor.

For an extra, but totally optional, challenge, try making it light up when you touch the sensor, regardless of whether you're also holding ground.

Checkoff 2:
Show your working touch sensor to a staff member, and discuss how you made your measurements to figure out what value tauThreshold should have.

5) A Real Sensor

The principle behind the little sensor we just built is the same princple that is used to detect touch in most modern touchscreens, laptop trackpads, etc; those things generally also work by detecting changes in capacitance when someone's finger is on (or near) the device, just that instead of a single loopy thing, they usually have a huge array of a whole bunch of electrodes, each of which acts like a single one of our loopy things, allowing us to detect changes in capacitance. If you're interested in finding out more about how those things work, this document provides a brief overview of various kinds of capacitive touchscreens.

We're not going to do anything quite that complicated, but we'll finish today's lab with a dramatically toned-down version of the same idea (the "self-capacitance" method described in that document, which is the same thing we just did with our little loop). We'll do a little 1-d spatial touch sensor using that principle. From the cart, grab yourself one of our little touch sensors, which just consists of a little piece of plastic with 5 copper pads on it:

All we're going to do in our simplified touch sensor is to replicate our circuit from the previous part, once for each pad. Our last example had our input source on pin 14, our loopy thing on pin 20, and the associated LED on pin 0. Let's hook up all 5:

  • Square wave from pin 14, copper pad on pin 20, output LED on pin 0
  • Square wave from pin 14, copper pad on pin 19, output LED on pin 2
  • Square wave from pin 14, copper pad on pin 18, output LED on pin 4
  • Square wave from pin 14, copper pad on pin 17, output LED on pin 6
  • Square wave from pin 14, copper pad on pin 16, output LED on pin 8

Once you've done this, you should have a working touch sensor! While connected to ground with one hand, you should be able to make the LEDs light up by touching each of the pads (and we should have multi-touch capability, too, though probably limited to around 3 LEDs on at the same time). Feel free to adjust your tauThreshold if you want.

You may also wish to tape the sides of the sensor down to the table with masking tape (like we did in the video at the very top of the page), since it can otherwise be hard both to hold onto ground and to mess with the sensor.

Checkoff 3:

Demonstrate your working touch sensor to a staff member. When you are all done, clean up by putting things back where they belong:

  • Remove everything but the Teensy from the breadboard.
  • Throw away (or keep as souvenirs) all of your capacitors and resistors, including your little loopy thingy.
  • Bring the little panel with the copper tape on it back to the front of the room.
  • Bring the breadboard (with the Teensy still in it, DON'T TRY TO REMOVE THE TEENSY, you'll break it) back to the front of the room, there is a box where it should go.
  • Hang up your scope probes and throw away any trash around your lab table.