This is a converted old lamp that was originally made for an incandescent light bulb. The new design uses a led, a custom made buck converter, an ATiny13A microcontroller and a capacitive sensor made out some aliminium foil.
The led can be toggled on/off by a simple touch. Holding the hand near the sensor for more than 2 seconds, changes the brightness. Depending on the surface material the lamp is on, the sensor detects a touch few cm away from the lamp as it can be seen in the video. Wood appears to be a good conductor of electric fields. This behavior is not always desired so it should be controlled by a different sensor layout.
|
| The led heatsink is held in place by electrical tape. Not pretty but does the job. |
Contents
Schematic
The lamp can be powered by 4xAA batteries or by a 5.6V wall adapter. The diodes D1 and D2 are small signal diodes to drop the voltage to the microcontroller to 5V or less. The buck converter is powered directly.
J1 is the ISP programmer used to program the ATiny13A microcontroller via SPI. The job of the microcontroller is to monitor the led current using an ADC pin and to maintain the desired current using a PWM pin that controls the buck converter. It also read the capacitive sensor by measuring the charge time through a high value resistor.
R5 is a 10M resistor (disregard the 2M in the schematic) used to charge the capacitor that is the aluminium foil used as a sensor. The 2M initial value was too low. A higher value makes the sensor more sensitive but a value too high can have a negative effect. With this sensor, a value of 10M works best.
The capacitive sensor
The capacitive sensor can be anything electric conductive, such as aluminium or copper foil or a loop of wire. The largest the surface area, the greater the sensitivity. Copper tape with conductive glue for when the tape is overlapped would be a better option but I didn't had any. A wire connects the foil to the sensor pad. The wire must have electrical connection with the foil.Like mentioned in the introduction, the lamp can be controlled sometimes even when the surface on which it stands is touched. One can try fixing this by making the sensor less wide and then using another foil connected to ground. The idea is to make the electric field go to the provided ground near it instead of spreading that far down. However, I didn't test that.
How the capacitive sensor and library works it is described here: https://www.programming-electronics-diy.xyz/2025/10/capacitive-sensing-library.html.
The presence or removal of the batteries can affect the sensor calibration even when powered from mains adapter, and that is because the ground is connected to the negative electrode of the batteries which together compose a large surface area. To mitigate this effect, the battery compartment is shielded with aluminium foil that is under the led. This shield is connected to ground using a wire. This way, the amount of ground surrounding the sensor is roughly the same regardless of whether the batteries are present or not.
The buck converter
Transistors Q1, Q2 and A3 form a push-pull driver that drives the Q4 P-Channel mosfet that together with inductor L1 and Schottky diode D3 form a buck converter. R6 and R7 are current sense resistors. I didn't have a lower value so I have used two of them in parallel to half the resistance and to double the current rating. The precision doesn't matter that much since few milliamps won't make much difference. The maximum tested current was 150mA. If a higher current is needed and the current setup causes flickering, try a higher value inductor.
Software and sensor calibration
The code functionality is described by comments so there is not much to say here. The led light intensity is controlled by 3 current levels in milli-amperes:
uint8_t led_intensity_level[3] = {4, 35, 60};
The sensitivity of the sensor is set as an argument to the proxiSense function and is called the trip value:
sensor1_state = proxiSense(sensor1, 1400);
For my configuration the trip value of 1400 worked well enough. Lower value means higher sensitivity.
The difficult part of this project was the grounding because that affects the capacity of the sensor and thus its calibration. To save your time, don't make the mistakes that I've made. Also a cheap portable oscilloscope or a laptop that is not plugged to mains would be useful for calibration.
Don't calibrate the sensor with the ISP programmer connected because then the circuit is connected to ground. In my case, with the programmer connected the trip value was around 1 or 2. When the ISP is removed and the circuit was powered from mains adapter, the sensor was unusable being too sensitive. After a lot of trial and error, I found a proper trip value of 1400. Then after mounting the cover the capacitance changed again. So plan ahead and place the ISP header outside the enclosure so you can program and calibrate the sensor while is full assembled.
But why would the computer ground affect the capacitance? And why it behaves differently when a mains adapter is used? Well, the main adapter is not grounded... directly since it uses a transformer. Even a Switch Mode Power Supply uses a transformer so they are not connected to ground directly but they are capacitive coupled to ground through the windings and also through a Y capacitor that is connected between the primary and secondary coils. This is used to filter the induced switching frequency from the primary coil I believe.
But what about when the circuit is powered from the batteries? Then the capacitive sensor is referenced to battery ground while the body, to earth ground. The sensor can still work if the hand or finger is in the path of the electric field that goes from the sensor to its local ground, so the sensor layout should have a grounded area near the sensor. Notice that in the video I touch the power jack when the lamp is battery powered. This works because the outside of the power jack is grounded and the sensor is around it, so when another dielectric other than air, such as a finger, is in the path of the electric fields, the capacitance changes. To apply a different trip value in software depending of whether the circuit is battery powered or not, you would need a power connector that has a separate pin that indicates when a wall adapter is plugged in and an extra pin on the microcontroller to read that. Since in this project there are no more available pins, you would need to pick another microcontroller.
Links
| KiCAD schematic and PCB | |
| v1.0 | CapacitiveLamp_v1.0.zip |
| Firmware | |
| v1.0 | TouchLamp firmware |
Changelog |
|
| v1.0 (2025-11-15) | Public release under GNU GPL v3 license. |
References |
|
|
Capacitive sensing library |
|





No comments:
Post a Comment