Introduction: Magic Light (Capacitance Sensor, First Arduino Project)
All you need is:
Arduino
wires
high resistor (mine is 10 mega ohms)
leds
tin foil or other conductive material
I build a housing for mine using an empty salsa jar and a toilet paper tube that happened to be the perfect size to snap together like legos.
Step 1: Code and Circuit
Set up a breadboard according the semantic. Download the attached code.
Update: added Fritzing diagram and schematic (Its a great program, check it out frizting.org)
/*this code is a cap. sensor that fades between 2 leds
* set up: pin 8 > high resistor > one wire to foil, one to pin 9
*Led set up pin 2>resistor>led>grnd
*based on http://arduino.cc/forum/index.php/topic,8609.0.html
* ajust if statment to fit resistor, currently using a 10Mohm
*/
Once it is set up, run the code and open the serial monitor. Move the set up away from your computer to help diminish interference Note what numbers are being out put when nothing is near the foil sensor, also note what it is when your open palm is extremely close to the sensor.
Change the int low cap to just above the number output when nothing is near your sensor.
Change high cap to the number output when you are almost touching the sensor.
You will have to adjust these numbers often to "calibrate" the light. Many factor interfere with the readings to it needs to be set up whenever it is moved.
Attachments
Step 2: Housing
To defuse the light coming through the jar I "mod-podged" toilet paper to the inside of the jar. To do this I mixed a little bit of elmers glue or mod-podge with just a tiny bit of water, and painted it onto the inside of the jar. Then I pressed on ripped up scraps of white tissue paper (actually just 1 ply toilet paper).
To create the tree, I ripped foil into thin strips, about an inch wide, and rolled them between my palms into "wires." I then hot glued them down onto the jar. To make it wider in places I just glued several of them right next to each-other. Afterwards to make it apear smooth on top, thinly coat sections with hot glue then press on a small flat peice of foil. I used my fingernail to score around the ends and tear of excess.
I covered the cardboard base with paper, with hole for the power and usb wires.
Step 3: That's It!
It was a great introduction to arduino for me, and I hope it can help you too!
Sorry for the photo quality, will update if I can.
The video is of the light without the base attached.
Eventually, I would like to build my own circuit board for this so I can take out the arduino. I would also like to make it so that it does not need to be "calibrated" (any ideas?)
Questions, comments and feedback welcome! :]

Participated in the
UP! Contest

Participated in the
Make It Glow

Participated in the
Instructables Design Competition

Participated in the
Holiday Gifts Contest
21 Comments
7 years ago
The code didn't work? Do you guys have an alternative?
Reply 7 years ago
I made this several years ago, so I no longer have it set up. You do have to adjust the capacitance range almost every time you turn it on to get it to work.
I believe I linked the code I based mine on in thr discription as well.
7 years ago
Where will I attach the battery?
Reply 7 years ago
I didn't use a battery, I powered it off USB
Reply 7 years ago
Thank you.
7 years ago
Can u explain this code:
"
for (i=0; i < 4 ; i++ ){ // do it four times to build up an average - not really neccessary but takes out some jitter
// LOW-to-HIGH transition
PORTB = PORTB | 1; // Same as line below - shows programmer chops but doesn't really buy any more speed
// digitalWrite(8, HIGH);
// output pin is PortB0 (Arduino , sensor pin is PortB1 (Arduinio 9)
while ((PINB & B10) != B10 ) { // while the sense pin is not high
// while (digitalRead(9) != 1) // same as above port manipulation above - only 20 times slower!
x++;
}
delay(1);
// HIGH-to-LOW transition
PORTB = PORTB & 0xFE; // Same as line below - these shows programmer chops but doesn't really buy any more speed
//digitalWrite(8, LOW);
while((PINB & B10) != 0 ){ // while pin is not low -- same as below only 20 times faster
// while(digitalRead(9) != 0 ) // same as above port manipulation - only 20 times slower!
y++;
}
delay(1);
}"
Reply 7 years ago
The code was pretty much directly taken from the code credited in the comments. I think the original coder was giving examples of mutliple ways of doing the same thing. I was originally using digitalRead- but this worked better, sorry I cant be of more help.
7 years ago
Hi!
How do u make two individual capacitance function in one program?
Reply 7 years ago
This only uses one sensor. It checks to see if it is high or low, and then fades to either red or blue to match. You could probably ad a second sensor on a different pin, if that is what you are asking.
8 years ago on Introduction
no, im sorry. wish i could help.
8 years ago on Introduction
I really like this project! Im thinking of doing something similar for my senior project in college. I will definately credit you on it :) I just want to add music to it for a more special needs kids based toy. but I'm not sure how to go about doing that. :P
Reply 8 years ago on Introduction
Id love to see it if you do make it :)
Best of luck, wish I could offer advice, but Im just a tinkerer.
10 years ago on Introduction
Cool project! I don't know how to read the schematic however. Or at least I don't have the confidence reading them yet. Do you have a Fritzing project for it?
Reply 10 years ago on Introduction
I'd never heard of Frizting before now. It look really usefull, I'll definitely make one soon!
Reply 10 years ago on Introduction
Made a quick diagram with it, added it to step 1. They're a bit messy but hopefully Ill play around some more with this program
Reply 10 years ago on Introduction
Hey! Wow. That's what I needed! Thank you so much. Have fun with Fritzing and will watch for more of your instructables!
Reply 10 years ago on Introduction
Love Fritzing. Lol.
10 years ago on Introduction
pretty neat. voted for all 3 contests, good luck
Reply 10 years ago on Introduction
Thanks!
10 years ago on Introduction
Awesome idea!