Feed on

We had a working touch lamp and then all of a sudden it wouldn’t work anymore, it’s happened to a similar lamp, these lamps are probably 10 years+ old, it’s a Mirabella TL007.

After a quick inspection, the circuit board didn’t smell or look too good. We could try to find the fault and repair the board but I thought it might be more interesting to make our own touch lamp with an ATtiny and just re-use the existing lamp base.

I won’t be wiring it up to the mains, instead since I have an alarm clock already running at 5V (with an 3.3V LDO), I can just wire up directly to the 5V source. The LED will just be one of those 1/2W LEDs you can pick up off Ebay for $1-2 so we’ll just need some dropper resistors or if you wanted to, you could make or buy a constant current driver.

For the touch sensing, you can buy a chip to do that (or it could be integrated already to an MCU you choose) or do it by hand, of course I went with the by hand method as I’ll be using an ATtiny13A. Once touch is detected, we’ll just turn on a mosfet to power on the LED.

To start off, we can use the ADC on a pin to look for any voltage fluctuation but we can’t just leave the pin floating, the pull down resistor needs to be high enough that the pin won’t float, can’t be too low or it won’t detect when we touch it, for me that ended up being 4.7M ohms.

Here’s the code, we just wait for a high reading (which took a bit of adjusting to get right) and then XOR the mosfet output, wait a little bit and then wait until the voltage dropped low enough after a bit of quick averaging. Download ATtiny13A_Touch_Sensor

I was able to re-use the existing light contacts and when connecting up the wire up to the metal base of the lamp, the detect touch code had to be adjusted slightly. Once touch was detected, the LED would go on, but if you left your hand there for just too long, the LED would keep cycling on and off. We just need something to store the charge until we let go, a capacitor will do!

After playing around trying to find the right value while tweaking the ADC values, I came to 2x 2.2nF in parallel to the 4.7M ohm resistor, now I can touch the lamp and leave my hand there for a few seconds and the light will maintain it’s current state. Depending on the weather, more tweaking might be needed as now that we’re in winter, it does seem like I have to apply a little bit more pressure when touch the lamp where as in summer, a soft touch would suffice.


I’ve just placed the LED in the middle pointing up and it seems to work alright for a 1-2W LED, I probably should change the colour to a warm white one. I remember with some of these touch lamps after a blackout the lights would come on, I might add a timer to detect if the lamp has been on for more than 15 minutes, it should turn off.

Leave a Reply