Projects / Touch-dimming reading lamp

Touch-dimming reading lamp

Beginner1.5 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANOLM2596

    Set the buck output

    Adjust the LM2596 to 5.0 V with no load and check with a meter.

  2. NANOIRLZ44

    Wire the MOSFET

    Gate resistor and pull-down as in the table.

  3. NANO

    Test with a fixed brightness

    Use analogWrite(GATE, 128) in a trial sketch.

  4. NANOTTP223

    Add the touch pad

    Wire it to D2.

  5. NANO

    Upload the sketch

    Tap to switch on and off.

  6. NANO

    Hold to dim

    Hold, release, then hold again to go the other way.

  7. NANO

    Power-cycle

    The last level is remembered.

  8. NANO8.6 mA

    Mount it

    Fit the strip in a lamp body that lets heat out.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
12 V adapter +LED strip + and LM2596 IN+Supply
12 V adapter -LM2596 IN- and a common ground railGround
LM2596 OUT+Nano 5V pinSet the output to 5.0 V with a meter before connecting the Nano
LM2596 OUT-Common ground railGround
Touch module VCCNano 5VPower
Touch module GNDCommon ground railGround
Touch module OUTNano D2High when touched
Nano D9220 Ω resistor then IRLZ44N gatePWM gate drive
10 kΩ resistorIRLZ44N gate and groundPull-down so the strip is off at reset
IRLZ44N sourceCommon ground railGround
IRLZ44N drainLED 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.

CheckExpected
TapLamp toggles
HoldBrightness ramps in one direction
Hold againRamps the other way
After power-cycleSame 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 →

Ask Lark AI

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.