Capacitive Touch Sensor

The questions below are due on Friday October 11, 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 milliseconds?
Enter a single number, not an expression.
\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 (on a new breadboard):

  • 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. While we could do this with the scope's automated measurements, they tend to be less accurate than what what we can get with the cursors directly, so let's do that measurement directly for now:

  • Make sure your triggers are set so that the curve on channel 2 is consistently drawn in the same spot on the screen.
  • Use the knobs on the scope to zoom and pan until the curve takes up almost the whole vertical range of the scope (i.e., until 0V is right near the bottom of the screen and 3.3V is right near the top), and the exponential rise is clearly visible.
  • Put the Y1 cursor at 10% of our 3.3V (i.e., .33V) and the Y2 cursor at 90% of our 3.3V (i.e., 2.97V).
  • Line your X1 cursor up with where the Y1 cursor intersects the curve, and to the same for X2 and Y2.
  • After you've done this, the difference between the X1 and X2 cursors should be the 10-to-90 rise time (the same one discussed in the prelab, so 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 substantially faster) on pin 11 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 11 and 18 of the Teensy, then connect your 33{\rm nF} capacitor between pin 18 and ground. Put the channel 1 probe back on pins 11 and ground (i.e., measuring the output square wave) and put channel 2 back on pins 18 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.

The Teensy code will measure the voltage (pin 18) as well and use it to estimate \tau.

Check Yourself 6:
Despite the Teensy implementing the same circuit that we just did with the wave gen, this graph looks really different from what we saw before. Why does it look so different?

Take a photo of your scope, or otherwise keep track of what this curve looks like, so that we can talk about it during your checkoff.

4) Touch Sensor

After that experiment, we're finally 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 18, 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 18 and ground. You may need to zoom in quite a 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:
Use the scope's measurement tools to measure the rise time (we could do this manually again, but the measurement tool will make the rest of the lab way easier for us. To add this measurement: click "Meas", then choose "Rise Time" under the "type" submenu, make sure channel 2 is selected, and then add measurement.

Using that rise time, 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 18 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 somewhere in between them, and set tauThreshold to that value. Lower values of tauThreshold will make for a more senstitive touch sensor (but it may accidentally turn on sometimes), whereas higher values will make it harder to detect a touch (but when one is detected, we can be quite sure it's actually coming from a touch).

Then recompile the code and re-flash it to your Teensy. Before flashing, under Tools->CPU Speed, set it to "816MHz (overclock)". And be aware that the Teensy's going to get a little hot, so maybe don't touch it (or at least don't hold your finger on it for a long time).

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. If it's useful, you can also open up the "Serial Plotter" from the Teensy "Tools" menu, which will plot \tau as estimated by the Teensy, over time (or opening the "Serial Monitor" instead will cause the estimated \tau value to be displayed in the screen).

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 principle 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'll finish today's lab with a toned-down version of the that same idea (the "self capacitance multi-pad" 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 PCB with 5 metal pads on it:

There's absolutely nothing special about this board; it really is just 5 metal pads connected up to 5 pins, equivalent to making 5 of our little loopy thingies from before.

And all we're going to do in our simplified touch sensor is to replicate our circuit from the previous part, once for each pad. Like before, we'll use pin 11 to provide our input square wave. But now let's plug in the little touch sensor board so that it's hooked up to pins 14-18 of the Teensy. Then we can finish by connecting resistors from pin 11 to each of those pins (replicating our original circuit 5 times).

Then we'll also need more LEDs (5 in total), one for each little pad on the touch sensor. These LEDs should have their respective positive sides (long legs) connected to pins 0, 2, 4, 6, and 8, respectively; and their negative sides (short legs) should all be connected to ground.

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 you should have multi-touch capability, too).

You may also wish to tape the sides of the breadboard down to the table with tape, since it can otherwise be hard both to hold onto ground and to mess with the sensor.

You should also feel free to adjust your tauThreshold if you want; by setting it appropriately, it should be possible to make this work even when you don't have one hand on ground.

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 and LEDs and extra wires, including your little loopy thingy.
  • Bring the little PCB 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.