Introduction: Turn a Pencil Drawing Into a Capacitive Sensor for Arduino

Did you know?  You can make pencil drawings reactive to touch for use with your projects!  It's really easy, and gives you a lot of flexibility in making interfaces for whatever microcontroller project you're making.



I put this together as part of my UnoJoy project, where we're using the Arduino as a platform from which to explore how we interact with video games.  You can check out more of our projects for UnoJoy at unojoy.tumblr.com, or more of our other projects at the Exertion Games Lab.

Step 1: Materials

You'll need the following:

A pencil - the softer the lead, the better
Some 1+Megaohm resistors 
Paperclips - make sure they're bare metal, not coated in plastic
Wire
An Arduino
Clear tape (optional)

Step 2: Theory

There are 3 ideas going on here:

1 - When you touch a conductive object, you create a certain degree of capacitance.  This increases the ability of the conductive material you touched to store a charge.

2 - We can create a cheap capacitive sensor by measuring how long it takes for a piece of conductive material to go from a grounded state to a higher potential state when pulled up to that higher state through a resistor.  The higher the capacitance, the longer it will take the conductive material to be pulled up to the high state.

3 - Graphite conducts electricity.  You may have seen this before in the Drawdio project, where they use a pencil trace to create sound.

Therefore, if we take our conductive pencil line, pull it to ground, then try and pull it to a higher state, we can measure how long it takes, and if we're touching the drawing, it will take longer to get to a high state than usual.  Conveniently, we can use the Arduino to automatically pull our trace to ground on and off. If we attach a pull-up resistor to our line, when the ground connection inside the Arduino is turned off, everything attached to the pin will start to be pulled up to VCC.

So, our circuit diagram will look something like the above.  We use an external pull-up resistor rather than the Arduino's internal pin pull-up resistors since we need much more resistance than the 30K ohm internal ones, otherwise, the resistance of the graphite tends to dominate and prevent the sensor from working.


Step 3: Putting It Together

Now to put everything together!

First, draw something - You'll want to follow the following rules:
- Make a big filled area at the edge of the paper - this is where you'll connect your wire to the drawing via paperclip.
- Make sure all of your drawing is connected - you'll only be able to read from parts that are all touching.
- Re-trace over your lines at least once or twice - you'll want to get some nice, thick lines of graphite on the paper.

Now take one side of your wire and connect it to a paper clip - you can just strip it and wrap the wire around the clip, but you might want to solder it make sure it stays on.

Connect the wire up like so:


Then load the attached code to your Arduino.

Step 4: Test It!

You may need to make some changes at the top of the code to get the correct cutoff value for your particular drawing, and you may need to go and re-trace over your drawing some more to get the parts of your drawing that are further away to work properly.

Once you get it working, you can take some clear tape and cover up your drawing - this will decrease its sensitivity a bit, but it will keep your drawing from smudging as people touch it.

I've put together a full video game controller with this as part of the UnoJoy project, and there will be a video over at unojoy.tumblr.com in a couple of days.

Comments

author
HernanD17 (author)2016-11-22

Hi everyone! I'm really new to Arduino and I'm having problems with the code. Does anyone know why "readCapacitivePin" is not declared in this scope? And how I can fix that? Thanks you and really good project.

In function 'void loop()':

DrawnSensorExample:22: error: 'readCapacitivePin' was not declared in this scope

exit status 1

'readCapacitivePin' was not declared in this scope

author
LoktakpatT (author)HernanD172017-02-01

just check "readCapacitivePin" was mention or introduce in earleir statement.. eg int x; float y;

author
mdeudon (author)2016-10-23

Take care, if you power your arduino with a battery this won't work !! The negative pole should be grounded.

author
mdeudon (author)2016-09-02

Excellent !

author
rafaelnfs (author)2016-05-22

thanks for the code, Im begginer but is usefully for me to read code and try to understood it all, Im trying to descifrate the readCapacitivePin funtion :) if somebody can provide me some code more easy to lear based on it , it could be great but thanks for ur time and code :)

author
vrrivaro (author)2016-01-04

Thanks, Kirmanimous786.You did an awesome job with this project and in showing it to us. Thank you.

author
awesomeroks (author)2013-08-04

will this work only for arduino?pls reply

author
vrrivaro (author)awesomeroks2016-01-04

Only for Arduino... Let me see... How can I explain thins better... Ah... Of course:

No.

Indeed Kirmanimous786 already told you that. What he did not tell you is that if you use a 555 clock signal chip and yo hook it up correctly, you could thoretically use it WITHOUT any microcontroller.

It will of course be far more complicated and difficult to debug and correct, but you can do it.

author

You can use whatever mocrocontroller

author
MrAnima (author)2015-11-23

This experiment looks really cool but when I try to reproduce it with the same program, it doesn't work. I even tried touching the leg of the resistor to see if it wasn't a problem with my drawing. Do I need to tweak with the resistor's value or the program itself ?

author
NelloB (author)2012-06-10

This is a nice little project apart from a couple of basic problems.

1. How about an explanation? How does this work exactly? How does that map to your code?

2. A non-handwritten circuit diagram would be nice

3. Why paperclips? Surely any wire is sufficient, or did I miss something. Hard to say without an explanation. See point #1.

My son has built this, and it works. What did he learn? How to download a file from the internet, and decipher a hand-drawn circuit diagram. What does he know about capacitve sensors? The same as when he started.

author
Kirmanimous786 (author)NelloB2015-08-05

Im 12 by the way

author
Kirmanimous786 (author)NelloB2015-08-05

Then teach him

author
techiebot (author)NelloB2012-07-21

Hi NelloB-
I hope that this doesn't sound at all snotty - but as a long-time teacher, I felt like replying...
Instructables are (to my mind) meant to be like a bit of a show and tell. It's like having a ton of geeky friends who stop by and show off what they are working on. Most of us have multiple projects going in various stages of successful operation.

I love it that your son built this circuit. But stopping there kind of misses the point. After I built it, I became curious. What does a capacitor really do? Can a stack of coins be a capacitor? So I started to experiment. I tried putting various metals on the trace - then I tried touching the + and - terminals of a 9volt battery - then I tried touching a pencil to it the lead tip, and also the metal eraser holder - then I tried different plastics - wire attached to the cement floor - and on and on. The point of a circuit like this is what can or can't it do? How could I use it? How can I learn more about capacitance by experimenting with it.

Sorry - teacher mode - anyway I hope that your son and others take the circuit and do amazing things with it! And learn by doing...

author
jabelone (author)NelloB2012-06-10

**Just for the record coming from a 14 yo**

1. See step 2 in this Instructable it says this:

There are 3 ideas going on here:
1 - When you touch a conductive object, you create a certain degree of capacitance. This increases the ability of the conductive material you touched to store a charge.

2 - We can create a cheap capacitive sensor by measuring how long it takes for a piece of conductive material to go from a grounded state to a higher potential state when pulled up to that higher state through a resistor. The higher the capacitance, the longer it will take the conductive material to be pulled up to the high state.

3 - Graphite conducts electricity. You may have seen this before in the Drawdio project, where they use a pencil trace to create sound.

Therefore, if we take our conductive pencil line, pull it to ground, then try and pull it to a higher state, we can measure how long it takes, and if we're touching the drawing, it will take longer to get to a high state than usual. Conveniently, we can use the Arduino to automatically pull our trace to ground on and off. If we attach a pull-up resistor to our line, when the ground connection inside the Arduino is turned off, everything attached to the pin will start to be pulled up to VCC. So, our circuit diagram will look something like the above. We use an external pull-up resistor rather than the Arduino's internal pin pull-up resistors since we need much more resistance than the 30K ohm internal ones, otherwise, the resistance of the graphite tends to dominate and prevent the sensor from working.


2. The hand-drawn schematic as you are supposed to call it is very neat and very easy to understand if you know how to read them.

3. Paperclips are very easy to "clip" onto paper and conduct electricity so basically they are just extending the wire to the graphite.  That is why they are used.

4. What did he learn? See point #1

Be thankful someone has takenhours of their time to put together such a very easy to follow and useful Instructable for your benefit, not theirs.

Next time do a little research before posting a comment like this:
 
"What did he learn? How to download a file from the internet, and decipher a hand-drawn circuit diagram. What does he know about capacitve sensors? The same as when he started."

author
rzahid (author)2012-10-19

hello.. your project is amazing,, i tried it but my led is constantly glowing.. i dont knw what is the matter,, i checked all connections,, dont knw from where it is gettin the charges.. :/ ..

author
Kirmanimous786 (author)rzahid2015-08-05

Try adjusting the sensitivity in the program

author
Lukkasss (author)2014-04-27

Also, you only need one resistor or two(one 1M+, other 10-500k)?

author
Kirmanimous786 (author)Lukkasss2015-08-05

I used two 510 k ohm resistors, it worked good for me

author
Kirmanimous786 made it! (author)2015-08-05

Thanks! This is a great project. I'm now trying to make a concealed lock with this principle!

IMG_20150805_185327.jpg
author
matt4276 (author)2015-07-20

Very nice tutorial! I am having a lot of problems trying to add multiple sensors to different pins on the arduino. I'm very confused on what to change in order to get the sensors to work separately. Any help is appreciated!

author
Arsalan Ahmadi (author)matt42762015-07-31

im not really good in these things but i think for this line

int capSensePin = 2;

u can change like

int capSensepin1 = 1;

int capSensepin2 = 2;

and then write codes for 2 pins when u need to type capSensePin type capSensepin1 or capSensepin2

also u need another resistor for next sense.

sorry for my bad english.

author
eyecwan (author)2014-04-24

I altered a little bit after I made it

I connected the wire to a small plant (inside the soil) and surprisingly the cycle changes when I touched the leave.

author
fawstes (author)eyecwan2015-04-28

Hey, This is exactly what I'm trying to do, could you please help get mine working? could you share your code with me please?

author
popcorngoo (author)2015-03-18

Hello! I'm very new to the Arduino, but I really like your project! I was wondering how someone could do this but with sound also? Could it be activated in a way that every time you touch the drawing a chord or a note plays? Possibly through a phone or computer?

author
alan.chatham (author)popcorngoo2015-03-19

Something like this lets you make sounds directly with your Arduino:
https://www.adafruit.com/products/94
Otherwise, you might look up Processing and how to use that with Arduino to have your Arduino drive sounds on a computer. Hope it helps!

author
veerlepennock (author)2015-03-03

hellooooo:)

im just starting to understand the Arduino and everything works except that the LED that's integrated in my Arduino works but not the one I have on my breadboard. The rest works perfectly:)

author
RobertGoldring (author)2014-08-20

clever idea, and inventive with that, well done.

author
maiolinojv (author)2014-06-16

I tried but I have no results =(

author
romodo (author)2014-05-02

My students will love it!! Thanks :)

temp_297467008.jpg
author
Lukkasss (author)2014-04-27

How about the length of the drawings, it should have a limit or I can draw up my entire lines, no matter the length of it? I need just to link it?

author
alan.chatham (author)Lukkasss2014-04-28

You should only need one resistor per line, but bump up the value the longer the line gets. The longer the line, make sure you're making it a thick line, going over it a bunch of times with the pencil. Graphite on paper isn't a great conductor, so laying it on thick helps a lot.

author
Lukkasss (author)alan.chatham2014-04-28

Hey, thanks for answers, I'm looking into it right now, I don't know if I'm making mistakes, but should the "touchedCutoff" threshold be higher when using long wires to connect to the drawing?? I've a short wire and the touchedCutoff value is 20, but when I connect a longer wire, it keeps turning on while I'm managing the wire itself... I think it's getting the threshold... is it right or some kind of strange?

author
dts2504 (author)2014-03-26

How would you do this with a RGB LED?

author
TheWiseWalrus (author)2014-03-13

is there a way to do this analog?

author
bshikhar13 made it! (author)2014-03-02

Awesome...I tried it on an AVR microcontrollor also..:)

TrollFace.png
author
Valtymore (author)2013-01-27

Hey Alan!
At first great thanks for this article. It has helped a lot!
I have a little problem: everything works very well with the uno, then I tried with a mega2560, I didn't change the code, and it didn't work at all. So I wondered if I should change something in the code ?!
thx !

author
lgiusti84 (author)Valtymore2014-01-15

Something even simpler, leave the code as it is, connect the "read cable" it to PIN 19, not PIN 2.

The reason is the readCapacitivePin method/function manipulates the ports directly from the AVR chip, the PD2 port is wired to PIN 2 on the Arduino UNO and to pin 19 on the Arduino Mega2560.

If you want to change the code I would recommend you reading a "port manipulation tutorial" before doing so. If you want to find one remember that Google is your friend for stuff like that.

author
LesPicard (author)2013-11-04

Which pins I have to use, and where do I have to connect them? I can't see it very well at the photo :P...

author
Snoop Lion (author)2013-05-20

Awesome article! I am having some trouble with adding multiple different sensors, and I did:

int firstSensor = readCapacitivePin(2);
int secondSensor = readCapacitivePin(3);

but if I touch both sensors at the same time that causes the program to hang. I used the same voltage source and added a resistor from there to pin 4 as well. Any advice?

author
rbhat1 (author)2013-04-29

Hello, I have recently tried out this from a using a capsense PCB and apparently the wires at some level also carry a degree of capacitance.Is there anyway to filter the circuit more in order to get a better output?

By the way, this was a really cool project! :)

author
contactscolored (author)2013-03-26

amazing

author
smh08 (author)2013-02-08

Hey your project is very good and interesting. But when I tried it the LED is always on and when I touch the paper clip or writing it flickers/blink. I tried to change some of the code but it doesn't work. Do you know why I am having this problem? Thank You.

author
JensonBut (author)2013-01-20

Thanks for the great article, and for sharing the great results to your effort

author
padorange (author)2012-06-20

I just try last night but i did not work as a except.
I do not have a 1 Mohm, so i used serial 3x 330Kohms.

But it didn't work detecting anything with pencil draw.
It can detect when i touch directly the paper clip.

I got (return but serial connection) :
14 cycles (when i did not touch anything)
70 to 80 cycles when i touch the paper clip.

I used your code on an Arduino Uno R3 using pin 2 as in your example.

author
alan.chatham (author)padorange2012-07-13

If you're getting a response by touching the paper clip, then the circuitry is working. There may be an issue with the thickness of your pencil trace - I find that going over the line multiple times is sometimes necessary, and you can test the conductivity of your trace by touching the trace, then, holding the paperclip by the insulated wire, touching the paperclip to different parts of the trace and seeing if it still triggers the sensor.

author

When I built a Drawdio I experimented a LOT with different pencils, and there is a BIG difference in the way they respond with a circuit like this. I went to the art store and bought soft lead sketching pencils, and a 4b or 6b worked great, much better than a #2 or HB. The problem is not difficult to solve, experiment a bit!

author
bbbbbbob (author)2012-09-13

Hi
I'm a beginner in arduino and tried your wonderful project.
But my LED is staying lighted whatever the cutoff. I'm using an arduino MEGA2560. Should it make any difference ?
A last question about the circuit : should there be any connection between the ground of the arduino board and the drawing or myself ?

Thanks again for the great project and your help.
Julien

author
techiebot (author)2012-07-21

I got the circuit to work first try, but only by touching the paperclip. I think I need a better pencil to make it work with the graphite. (I tried various values to increase sensitivity but no go with graphite).

However, I have some Bare conductive paint from Sparkfun and it works great! I just painted a line and the circuit reacts all the way down. I am thinking of making an interactive popup book and touching the lines would be the way to interact with the page.

author
jabelone (author)2012-06-04

Hello, awesome idea.
I have converted my UNO into a joystick and can't upload sketches. So how would I be able to use this capacitive touch sensor to act as if I am pressing a button on the UNOjoy joystick?

About This Instructable

174,825views

389favorites

License:

More by alan.chatham:Remote-Control ThundercloudsTurn a pencil drawing into a capacitive sensor for ArduinoPlay Guitar Hero with a Real Guitar
Add instructable to: