Arduino Touch Lamp with TTP223 Touch Sensor and Relay
Level 43 · Just a Touch · 30 minutes
A touch lamp: one touch turns it on, the next touch turns it off, and holding changes nothing.

Preview the project free; a course seat is required to run and submit. No hardware kit needed.
Your project challenge
Make a touch lamp: one touch turns it on, the next touch turns it off. Wire it up: - Touch sensor: VCC to 5V, GND to GND, I/O to D2 - Relay: VCC to 5V, GND to GND, IN to D7 Holding the pad must not switch it again.
Components you’ll use
- Arduino Uno
- TTP223 Touch Sensor
- Relay Module
What you’ll build
A touch lamp. Touch the pad once and the lamp comes on. Touch it again and it goes off.
How it works
- The touch sensor feels your finger through a metal pad. Nothing moves.
- While your finger is on the pad, I/O is
HIGH. When you lift it, I/O isLOW. - For half a second after power-on, the chip measures the empty pad. It ignores touches then.
- The relay is active low:
LOWturns the lamp on.
The key idea
The sensor is momentary, but a lamp must toggle. So act on the moment I/O changes from LOW to HIGH.
if (touch == HIGH && lastTouch == LOW)
Then remember this reading in lastTouch for the next loop.
⚠ Watch out
If you flip the lamp whenever I/O is HIGH, holding your finger on the pad makes the lamp flicker on and off. The chip also has a jumper, B, that makes it toggle by itself. Leave it open here: your sketch does the toggling.
The interactive editor includes the wiring guide, code editor and simulation controls.