Build it step by step
0 of 8 doneSet the buck output
Adjust the LM2596 to 5.0 V with no load and check with a meter.
Wire the MOSFET
Gate resistor and pull-down as in the table.
Test with a fixed brightness
Use analogWrite(GATE, 128) in a trial sketch.
Add the touch pad
Wire it to D2.
Upload the sketch
Tap to switch on and off.
Hold to dim
Hold, release, then hold again to go the other way.
Power-cycle
The last level is remembered.
Mount it
Fit the strip in a lamp body that lets heat out.
How do you build a touch-dimming reading lamp?
Tap a touch pad to turn on, hold it to dim a 12 V LED strip through a MOSFET, and the lamp remembers your level. You need Arduino Nano, Touch sensor module (TTP223), MOSFET IRLZ44N, 12 V LED strip warm white (5 m, 2835), 12 V 2 A DC adapter, Resistor 220 Ω, Resistor 10 kΩ and LM2596 Buck Module. It takes 8 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 8
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- SemiconductorsBuyMOSFET IRLZ44N × 1
- OptoelectronicsBuy
- PowerBuy
- PassivesBuyResistor 220 Ω × 1
- PassivesBuyResistor 10 kΩ × 1
- PowerBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| 12 V adapter + | LED strip + and LM2596 IN+ | Supply |
| 12 V adapter - | LM2596 IN- and a common ground rail | Ground |
| LM2596 OUT+ | Nano 5V pin | Set the output to 5.0 V with a meter before connecting the Nano |
| LM2596 OUT- | Common ground rail | Ground |
| Touch module VCC | Nano 5V | Power |
| Touch module GND | Common ground rail | Ground |
| Touch module OUT | Nano D2 | High when touched |
| Nano D9 | 220 Ω resistor then IRLZ44N gate | PWM gate drive |
| 10 kΩ resistor | IRLZ44N gate and ground | Pull-down so the strip is off at reset |
| IRLZ44N source | Common ground rail | Ground |
| IRLZ44N drain | LED strip - | Switched return |
Code
The IRLZ44N is a logic-level MOSFET, so a 5 V pin drives it fully. The 220 Ω gate resistor and the 10 kΩ pull-down keep the gate safe and the lamp off during start-up. A small buck module makes 5 V for the Nano from the 12 V adapter; set its output to 5.0 V with a meter before connecting the Nano. The code speeds up Timer 1 so the PWM on D9 is far above visible flicker. The strip should be under 3 A, which the MOSFET handles with barely any warmth. Only low voltage is used; the mains side is a ready-made 12 V adapter. Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Tap to toggle, hold to ramp the brightness up and down. The level is remembered.
#include <EEPROM.h>
const byte TOUCH = 2, GATE = 9;
byte level = 128; // 0 to 255
bool lampOn = false;
bool rampUp = true;
bool wasTouched = false;
unsigned long pressStart = 0;
bool holding = false;
void setup() {
pinMode(TOUCH, INPUT);
pinMode(GATE, OUTPUT);
TCCR1B = (TCCR1B & 0xF8) | 0x01; // Timer 1 prescaler 1: PWM on D9 and D10 at about 31 kHz, no visible flicker
level = EEPROM.read(0);
if (level < 10) level = 128;
analogWrite(GATE, 0);
}
void show() { analogWrite(GATE, lampOn ? level : 0); }
void loop() {
bool t = digitalRead(TOUCH);
unsigned long now = millis();
if (t && !wasTouched) { pressStart = now; holding = false; }
if (t && now - pressStart > 400) { // hold: ramp
if (!holding) { holding = true; lampOn = true; }
if (rampUp && level < 255) level++;
else if (!rampUp && level > 10) level--;
show();
delay(8);
}
if (!t && wasTouched) {
if (holding) { rampUp = !rampUp; EEPROM.update(0, level); } // next hold goes the other way
else { lampOn = !lampOn; show(); } // tap: toggle
}
wasTouched = t;
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Tap | Lamp toggles |
| Hold | Brightness ramps in one direction |
| Hold again | Ramps the other way |
| After power-cycle | Same brightness as before |
If it does not work
Lamp on at start
Check the gate pull-down.
Flicker
Check the Timer 1 line is present.
Touch not detected
Check the module VCC and its OUT wire.
MOSFET hot
Check the strip current and that the gate gets a full 5 V.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the touch-dimming reading lamp?
Arduino Nano, Touch sensor module (TTP223), MOSFET IRLZ44N, 12 V LED strip warm white (5 m, 2835), 12 V 2 A DC adapter, Resistor 220 Ω, Resistor 10 kΩ and LM2596 Buck Module.
How long does the touch-dimming reading lamp take to build?
About 90 minutes for a beginner maker, in 8 steps.
How do I know the touch-dimming reading lamp works?
Tap: Lamp toggles. Hold: Brightness ramps in one direction. Hold again: Ramps the other way.
Lamp on at start: what should I check?
Check the gate pull-down.
Flicker: what should I check?
Check the Timer 1 line is present.
Touch not detected: what should I check?
Check the module VCC and its OUT wire.
MOSFET hot: what should I check?
Check the strip current and that the gate gets a full 5 V.
