Total Time: 2.5 hours
In this lab, you will learn how to make a capacitive sensor from scratch!You will then use the capacitive sensors as input for your guitar hero lab.
In this lab, you'll create a capacitive sensors and learn:Before we start, please make sure you understand the following safety precautions:
Capacitive sensing is a versatile method for detecting touch and proximity. It’s widely used in devices like smartphones, touchpads, and interactive displays.
Capacitive sensing relies on the principle of capacitance—the ability of a system to store electrical charge. It requires just two materials: a conductive plate connected to power and another to ground, with a dielectric (non-conductive material) between them. The capacitance is calculated using the formula:
C = εA/d
Capacitance changes when any of these factors are altered, such as the dielectric properties or the proximity of a conductive object (e.g., a finger). Touch reduces the distance (d), increasing capacitance and altering the signal.
Capacitive sensing is a foundation for touchscreens, proximity sensors, and even gesture recognition, proving its importance in modern technology.
We will implement touch sensing using the principle of capacitive touch sensing. The setup includes:
When a user touches the touch button:
To delay the discharge from the user's finger and make the time difference measurable on the Arduino, you will add a resistor between the sender and the receiver pin.
Lets first make our capacitive touch pad. Take a roughly finger sized piece of copper tape. Poke a M-M (Male to Male; ie pointy end) jumper cable through about 1/2cm from one end (careful not to poke yourself). Then solder the jumper down to the copper. You may also just attach a smallr piece of copper tape on top to be faster. It should look like this:
Let's build the circuit and write the code for one touch button, later we will show you how to do this for multiple touch inputs. To get started, follow these steps:
The result should look something like this.
Install the CapacitiveSensor library by Paul Badger. Then, upload the following code to your ardiuno:
/*******************************************************************************
* Capacitive Sensing for Touch and Proximity
*
* Reads values from two capacitive sensors and displays results on the Serial Plotter.
*******************************************************************************/
#include <CapacitiveSensor.h>
// Define sender and receiver pins for the two touch pads
int sender = 2; // Shared sender pin
int touch_pin = 3; // Receiver for touch pad 2
// Number of samples to take per reading
int samples_touch = 10;
// Create capacitive sensor objects
CapacitiveSensor sensor1 = CapacitiveSensor(sender, touch_pin);
void setup() {
Serial.begin(9600); // Initialize Serial communication
Serial.println("Capacitive Touch Sensor Ready!");
}
void loop() {
// Read capacitive values
double analog_touch_1 = sensor1.capacitiveSensor(samples_touch);
// Print values to Serial Plotter (comma-separated for multi-channel display)
Serial.print(analog_touch_1);
Serial.println(",");
delay(10);
}
Examine the output on the serial plotter (top right button) in the Ardiuno IDE.
You will probably see something similiar to the graph below, where the values
"spike up" when you touch the pad.
💡 Now swap the 10k resistor for a 1M Ohm resistor. How does it change?
The MPR121 Adafruit shield allows us to use 12 capacitive touch sensors. Often we only need to know if the sensor is "touched" or "not-touched." The shield and library can set an automatic threshold for any object. The shield is made for alligator clips, in which we can clip to just about anything. We can also solder to it, which we would like you to do first.
Create a total of 6 capacitive touch sensors out the copper tape (you can swap later with any material you want during your remix).
First apply the copper tape
into the template pads, then place the wire on the pad, when it's snugly on the pad, put another layer of copper tape on top of it-- this is so it's not permenant and you can just swap out materials later much more quickly.
(Make sure the copper tape on adjacent pads don't touch!!).
Using the shield is easy. Install the Adafruit MPR121 library. Then go to File -> Examples -> Adafruit MPR121 -> MP121test.
It should work out of the box 📦
You have access to the following materials for creating your touch-sensitive designs. Choose a method other than using copper tape to experiment with a new approach.
A 3D-printable material that contains conductive additives. Keep in mind that its resistivity is high, which might limit its performance for certain applications.
A versatile option that can turn almost any surface conductive. It’s ideal for irregular shapes but may require careful application to ensure even coverage.
A flexible, pre-made conductive material. Can also lasercut using the fiber laser cutter.
A thread with conductive properties, perfect for integrating into textiles or other flexible assemblies. Ccan be sewn into designs.
Select one material other than copper tape for your project. Consider the requirements of your design, such as flexibility, resistivity, and application ease.
Integrating fabrics with 3D printing opens up so many design possibilities, especially when using conductive materials like 3D Printing filament or copper meshes. Here's how to approach this:
Conductive filament can be printed onto non-conductive fabric to create custom circuits or sensing areas. However, its high resistivity may limit performance in applications requiring low resistance.
Conductive mesh is an excellent alternative since copper is a good conductor-- but it is limiting in form factor. You can combine it with non-conductive 3D printing material to create hybrid structures, leveraging the mesh's low resistance for improved functionality.
Based on the material you chose, sketch your guitar and how you plan to wire connections to the material of your choice
(ie plan this out and discuss with your instructor). We have also provided a DXF file for a guitar here, which we will give you next lab!
Congratulations, your multi-input capacitive sensor is ready! 🎉