Picture of Capacitive Touch Arduino Lamp
EDIT: I made another one of these, and hacked an ikea lamp with it. You can see the 'ible overe HERE

The Problem

It is late night, and your cellphone rings. You can't see where it is, you blindly grope around your nightstand, trying in vain to find that illusive switch that will illuminate your side of the bed. You clumsily turn on the lamp, locate your cellphone...and you miss the call. Damn. If only your light was easier to turn on.

The solution

What if all you had to do to turn on your lamp...was to touch anywhere metal on your bedside table? That sounds complicated though, and I AM a strong believer in keeping things simple whenever possible. I wonder if there are any open-source solutions that would allow such a thing to happen? Enter ARDUINO. A cheap, easy to use micro-controller that is dead simple to program and implement.  This sounds like it might just work!

Since I am inherently thrifty (an HVAC-R apprentice, AND a Mennonite) I don't want to commit my only $35 arduino board to the project. This means i'll have to build my own Arduino, which will save me some money.  Additionally, I'm only using a couple of pins, and not doing any serial communications, so I really don't want to bother using an external oscillator. That means I'll have to figure out how to enable the internal oscillator on an atmega 168.


This 'ible will show you how to do the following (without a lot of hand-holding);

How to burn a bootloader to a standalone atmega168 using an Arduino UNO SMD edition.
How to enable the internal oscillator, so you can save $0.50 and not use a crystal.
How to program a standalone chip using an Arduino board and the Arduino IDE.
How capacitive touch objects work.

What is NOT covered
How to read a schematic diagram
How to solder
How to layout a protoboard

Since there are literally hundred of guides on how to solder, how to use schematic diagrams, and basics of digital electronics...I'm not going to go there. You'll notice that there is a search bar in the upper right hand corner of this wonderful site. I'm sure if you try using it, you'll find what you need. That said, if you are having troubles implementing THIS particular project, and it doesn't involve such things as "How do I solder a resistor" then please feel free to ask.

I am curmudgeonly, so my responses to questions that are not included in the scope of this 'ible may or may not include some lighthearted mocking. You have been warned.

This is a proof of concept i'd put together before building the standalone.

Remove these adsRemove these ads by Signing Up
timbit1985 (author) 2 years ago
"This is most likely a stupid question, but how does the intensity of the LED change when it's getting 12 volts straight from the power supply?"

This isn't a stupid question at all. I believe I touched briefly in a previous section about PWM, but I might be mistaken. PWM stands for pulse width modulation. PWM allows you to vary the duty cycle of a digital pin. This means that you are switching the digital pin on and off very rapidly. This rapid switching results in a decrease in brightness. If you look at the following code

if (mode == 0) targetBrightness = 0;
if (mode == 1) targetBrightness = 255;
if (mode == 2) targetBrightness = 128;
if (mode == 3) targetBrightness = 64;

targetBrightness = 0; means off.
255 is a 100% duty cycle. 128(half of 256) is a 50% duty cycle, 64 (1/4 of 256) is a 25% duty cycle.

The value vary between 0 and 255 because the atmega has 16bit address bus, allowing for 2^16 (256) bits.

A 50% duty cycle refers to the fact that the LED (or digital output pin) is HIGH (or turned on) for 50% of the time. This means that in a period of 1 second, the light is off for a total of 0.5 sec and on for a total of 1 second. This is a nice picture that graphically shows what different duty cycles look like. Notice how the pulse width size changes between the different duty cycles. Modulation means to change something.

What this means is
timbit1985 (author)  timbit19852 years ago
**EDIT: On for 0.5 second, off for 0.5 second in the last paragraph.
gregjd500010 days ago
Hey! Awesome ible but the name is a tad misleading. Cap Touch uses changing time constants because of an approaching ground (person) to detect touch without contacting any metal. This uses a resistor to pull high then the human to directly pull to ground. I really enjoyed reading the Instructable but wanted to mention that.
zootalaws2 months ago

Being curmudgeonly myself, I was tempted to correct your 'ible' to 'able', but - funkit, if we spent our time correcting silly grammar we wouldn't have time to make cool stuff :)

Good 'able, btw ;) I have about 50x $3 Arduino Nanos hanging around and a box full of addressable LEDs - this will come in handy for gesture switching.

solaron991 year ago
Hi Timbit1985, fantastic project!

another crazy question:

Can I use an ATmega328P chip instead of the ATmega168 chip for use in this project
using : Tools/Board/LilyPad Arduino w/ ATmega328 ?

timbit1985 (author)  solaron991 year ago
Did you end up using the ATmega328P ? Did it work out okay for you?

Yes, it worked out perfectly! Will attempt using an Attiny 85. Thx again.

timbit1985 (author)  solaron991 year ago
I don't see why not. I believe the lilypad with atmega328 uses an oscillator, where as I chose a firmware that does not. This means that you will have to install a crystal for it to work. Make sure that the pin outs are the same on the atmega328 vs the 168.

Oh thats a realy nice instructable. I was looking for something like this since a long time. Well done!!

have one question about this. I have a Arduino Duemilanove which i
dont need anymore and I have enough Place to place it in my Lamp. Can i
upload your skatch and it will work to? Just to skip the Step for
programming the Standalone Chip.

timbit1985 (author)  maestro_dom1 year ago

Oops, sorry I missed this. I don't see why it wouldn't work. Good luck! Thanks for checking out my instructables.

It works perfektly ;) thank you again!

solaron991 year ago
Yes, it worked out. Awesome!
scanning1 year ago
That is a good explain and release my problem.Thank You!
scanning2 years ago
I don't understand how to set control the vary with level of LED in the circuit . I only saw a relay with 12V contact direct connect to LED only.
timbit1985 (author)  scanning2 years ago
The relay is actually an SSR, which has a very rapid switching rate compared to a mechanical relay. You could use a mosfet as well, which would be cheaper. I just used what I had on hand.

Basically the microcontroller turns the SSR on and off rapidly, which in turn switches the LED on and off rapidly. This rapid switching is known as Pulse Width Modulation (PWM), and is a very common way of controlling LED brightness without varying the current or voltage.
iwalton12 years ago
This is most likely a stupid question, but how does the intensity of the LED change when it's getting 12 volts straight from the power supply?
samaddon2 years ago
Nice work man i appreciate it Very well done!
samaddon2 years ago
Nice work man i appreciate it Very well done!
mrmerino2 years ago
...Can't you just look for the light from your cell phone's screen?
timbit1985 (author)  mrmerino2 years ago
you COULD if the cellphone was in sight. I always keep it in my pants, so I don't forget it when I leave the house.
Fair enough. This is still a good Instructable though.
timbit1985 (author)  mrmerino2 years ago
Thanks. I appreciate the comments.
This is a great project - very similar to one I did a while back except I didn't use Arduino at all (primarily because it's unnecessary overhead). Although I used a constant current driver, a simple MOSFET switch is sufficient in controlling the brightness through PWM.

The only thing I would really recommend is that you try to use a smaller chip than the ATmega168 - kind of a huge waste of pins and program space (and money) to just read a sensor and turn on/off some lights! I did my whole project with the 8 pin ATtiny25 and still had a few pins and a lot of space left over, but this is the smallest chip that isn't surface mount.

For Light Diffusion:
Try arranging your LED strip(s) in various shapes and angles and placing the light inside a real light fixture or lamp shade.

Schematic-v3.jpgFixture 2.jpg
timbit1985 (author)  Kurt E. Clothier2 years ago
Thanks Kurt. I used what I had on hand, which was the atmega168 ;) I have a bunch of attiny85's on the way, which I actually plan on switching into this project once they arrive.

That's a good idea regarding the light fixture. I did the same thing inside of my car.
Jazzy132 years ago
You got my vote! Nice thinking.
timbit1985 (author)  Jazzy132 years ago
Thank you very much :) I am always trying to come up with little ideas to make my wife's life a bit easier.
That's sweet. Make to check out my instructables. B-)

***WARNING*** I am curmudgeonly, so my responses to questions that are not included in the scope of this 'ible may or may not include some lighthearted mocking. You have been warned.


This is an excellent idea, too. Awesome job!

timbit1985 (author)  jessyratfink2 years ago
Thanks! I'm glad you like it :)