# 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.
Remove these ads by Signing Up

## 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:

## 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.
 1-40 of 73 Next »
RobertGoldring4 months ago

clever idea, and inventive with that, well done.

maiolinojv6 months ago

romodo7 months ago

My students will love it!! Thanks :)

Lukkasss7 months ago

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?

alan.chatham (author)  Lukkasss7 months ago

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.

7 months ago

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?

Lukkasss7 months ago

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

eyecwan7 months ago

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.

dts25048 months ago

How would you do this with a RGB LED?

TheWiseWalrus9 months ago

is there a way to do this analog?

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

Valtymore1 year ago
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 !
11 months ago

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.

LesPicard1 year ago
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...
awesomeroks1 year ago
will this work only for arduino?pls reply
JesusGeek1 year ago
@rbhat1, try grounding the wires, static interference may be to blame
Snoop Lion1 year ago
Awesome article! I am having some trouble with adding multiple different sensors, and I did:

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?
rbhat11 year ago
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! :)
contactscolored1 year ago
amazing
smh081 year ago
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.
JensonBut1 year ago
Thanks for the great article, and for sharing the great results to your effort
rzahid2 years ago
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.. :/ ..
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.
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.
2 years ago
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!
bbbbbbob2 years ago
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
techiebot2 years ago
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.
NelloB2 years ago
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.
2 years ago
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...
2 years ago
**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 taken hours 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."
jabelone2 years ago
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?
alan.chatham (author)  jabelone2 years ago
Thanks for trying out UnoJoy! This capacitive sensor technique goes great with UnoJoy, but you'll have to upload a new sketch onto your Arduino.

One of the great things about UnoJoy is that the process is totally reversible - if you plug the UnoJoy Arduino back into your computer and put it into DFU mode again (by shorting the same pins you did when converting it into a joystick), then run the 'TurnIntoAnArduino.bat' or .command program.

If you want some sample code that uses this graphite touch sensor as joystick input, you can give this code a try:

Let me know if you need any more help!
2 years ago
Thanks, but I can't upload sketches to the UNOjoy, so how would I put that sample code onto it? The only way I can upload code is to revert it back to proper Aduino but then it doesn't act as a Joystick. So exactly how would I be able to use the capacitive t
alan.chatham (author)  jabelone2 years ago
So, UnoJoy is a two part system -

1. Code that's running on the ATmega328p chip that reads in whatever input you want, then sends serial data to the communications chip.

2. A firmware for the communications chip which translates the serial data into joystick signals.

So, when developing your controller code for UnoJoy, you'll put your Arduino into the Arduino mode so you can upload code to the ATmega328p chip, then put the Arduino back into the UnoJoy mode, where it turns the serial data that the UnoJoy code on the ATmega328p is sending out into joystick signals.

While it's in Arduino mode, but running code that uses the UnoJoy library, the tool in the UnoJoyProcessingVisualizer folder takes in the serial data that the Arduino communication chip is passing through and provides a visualization of what sort of signals the code is putting out.
2 years ago
Ok, thanks, i thought that might be the case but wasn't to sure.
I am trying to make a platform game using Unity and then make a "Touch Controller" for the character and actions.

So... to confirm...
1) Upload Sample Capacitive Touch code to arduino (arduino mode)
2) Change into Unojoy and plug into pc for game controller (UNOJoy mode)
3) Play games with a "magic piece of paper."
alan.chatham (author)  jabelone2 years ago
Yep, that should get you close to where you need to be. I'd recommend using the UnoJoyProcessingVisualizer while working on the Arduino code, so the process will be:

1) Upload code to Arduino (Arduino mode)
2) Open up UnoJoyProcessingVisualizer.exe (Arduino Mode)
3) Test controller's functionality (Arduino mode)
4) Repeat steps 1-3 until satisfied with performance
5) Change into UnoJoy then plug into PC (UnoJoy mode)
6) Play games with 'magic paper'

Good luck!
2 years ago
Thank-you very much for all of your help. Would I be able to use a normal resistor or do I have to use this "pull up resistor." Sorry about my lack of understanding, I am just getting into electronics. :)
alan.chatham (author)  jabelone2 years ago
No problem!

So, a 'pull up' or 'pull down' resistor is a term that we use for a resistor of relatively high value (like 10K, 20K, 1M ohm) that connects a path to the voltage source or ground, respectively. We call it a 'pull up' or 'pull down' resistor because it puts a light pressure that 'pulls' the level on the line up or down if there's nothing else connected to the line.

Commonly, we'll see this used with switches - when the switch is closed, it will directly connect the pin to ground, so the level of the pin goes to 0. However, when the switch is released, the voltage on the line will bring the line back up to 1.
Heck, wikipedia is probably way better at explaining it than me:
http://en.wikipedia.org/wiki/Pull_up_resistor

At any rate, this project here relies on the fact that, after the pin switched to ground (which the Arduino does in the code), it takes a certain amount of time for the line to go back high, so we need a big value on our pull-up resistor (like 1M ohm) so that it takes a relatively long time for the voltage to go from 0 to 5v.
2 years ago
Hello again, I am very sorry for constantly bugging you. I have had another problem. I have hooked it all up right but I just cannot get the code right (been trying for days). Could you please email me a sample code or upload it to your wiki then comment, so that I can use the "Capacitive Touch Sensor" in UNOJoy mode to make a windows game controller. Thank-you very much in advanced and I promise I won't bug you again after this. :) Thanks, Jabelone. (btw email is temp12@jabelone.com )
alan.chatham (author)  jabelone2 years ago
No problem! There's some example code for the drawn sensor controller here: