DEV Community


Posted on

Creating an interactive drawing with arduino

I have to develop new arduino projects each week for my young pupil, who is passionate about electronics and hardware. For that, I found our last project creative and interesting, and I bet some of you can use it as a geek experiment.

What we need here is graphite based pencils (or directly graphite, works better), arduino, resistors, a led, a metallic clip, and a white regular paper. How does it works?

First we should know how this works. In arduino, we can use several sensors as INPUTS, such as a button, a light sensor, an humidity sensor, etc. But we can also attach home-made INPUTS using conductor materials. Steel and metal are common conductors materials (you can try this experiment with a coin, too) and so is graphite.

For making this work in arduino, we are using a special library called CapacitiveSensor04. Once our library is added, we can start designing the circuit. This is an example with steel paper, works the same with graphite. Only draw something (very dense), attach a paper clip to the drawing (be careful, it should be a single-line drawing) and a cable to the paper pin, which is the one connected to the resistor + 4 and 2 pins.

And this is our code:

#include <CapacitiveSensor.h>
CapacitiveSensor capSensor = CapacitiveSensor(4,2);

int threshold = 1000;
const int ledPin = 12;

void setup() {

    pinMode(ledPin, OUTPUT);


void loop() {

    long sensorValue = capSensor.capacitiveSensor(30);
    if(sensorValue > threshold) {
        digitalWrite(ledPin, HIGH);
    else {
        digitalWrite(ledPin, LOW);


Enter fullscreen mode Exit fullscreen mode

We might have to calibrate the threshold, in which case you will only have to open the Monitor and test. And... tadaah! interactive drawing hat lights a led. You can now do other things. Just experiment!

In case you are a tutor, teacher or parent, here's the content of my class in spanish ready for the students (answers, incomplete code for them and complete code with comments for the teachers and activities).

Top comments (1)

martincomito profile image
Martín Comito

Amazing! Thanks for sharing this :D