I bought a Makey Makey a few months ago and when I started playing with it, I realised quickly that having to attach one of the alligator clip to your wrist or finger to be able to use the device properly made the experience a bit less exciting for me.
What I really wanted was to be able to simply touch any conductive surface to create a reaction, without have to touch the other wire usually connected to the “earth” part of the board.
So I started looking for a solution to turn this board into a real capacitive sensor. At first I thought it would not be possible but, after looking for a few days, I finally found a solution.
So, if like me, you’d like to make your board do something different, follow the steps below:
-
Plug a wire in the pin number 5 of the board.
-
Plug your Makey Makey in your computer.
-
Launch the Arduino IDE and in the “Board” section of the menu, select the Makey Makey.
-
Copy and paste the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
int capSensePin = 5;
// This value may be different.
int touchedCutoff = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
if (readCapacitivePin(capSensePin) > touchedCutoff) {
Serial.println(readCapacitivePin(capSensePin));
}
}
uint8_t readCapacitivePin(int pinToMeasure){
// This is how you declare a variable which
// will hold the PORT, PIN, and DDR registers
// on an AVR
volatile uint8_t* port;
volatile uint8_t* ddr;
volatile uint8_t* pin;
// Here we translate the input pin number from
// Arduino pin number to the AVR PORT, PIN, DDR,
// and which bit of those registers we care about.
byte bitmask;
if ((pinToMeasure >= 0) && (pinToMeasure <= 7)){
port = &PORTD;
ddr = &DDRD;
bitmask = 1 << pinToMeasure;
pin = &PIND;
}
if ((pinToMeasure > 7) && (pinToMeasure <= 13)){
port = &PORTB;
ddr = &DDRB;
bitmask = 1 << (pinToMeasure - 8);
pin = &PINB;
}
if ((pinToMeasure > 13) && (pinToMeasure <= 19)){
port = &PORTC;
ddr = &DDRC;
bitmask = 1 << (pinToMeasure - 13);
pin = &PINC;
}
// Discharge the pin first by setting it low and output
*port &= ~(bitmask);
*ddr |= bitmask;
delay(1);
// Make the pin an input WITHOUT the internal pull-up on
*ddr &= ~(bitmask);
// Now see how long the pin to get pulled up
int cycles = 16000;
for(int i = 0; i < cycles; i++){
if (*pin & bitmask){
cycles = i;
break;
}
}
// Discharge the pin again by setting it low and output
// It's important to leave the pins low if you want to
// be able to touch more than 1 sensor at a time - if
// the sensor is left pulled high, when you touch
// two sensors, your body will transfer the charge between
// sensors.
*port &= ~(bitmask);
*ddr |= bitmask;
return cycles;
}
- Upload the code onto the Makey Makey and open the serial monitor.
You should see the value 0 printed when you’re not in contact with the wire plugged in pin 5. If it changes to 1 when you’re touching it, then it’s working!
Now if you plug the wire in a conductive matter, you should be able to produce an effect by touching it without having to hold the cable plugged in the earth port of the board! :)
To get started, you could try to connect an Arduino with an LED and make it turn on when you’re touching the wire!
Hope it helps!