A circuit that responds
4 minA touch pad, a board and an LED are the shortest path from the physical world to data. You'll follow that path and tune the one line that decides when the light comes on.
Lesson video
Tastebud · 4:01 · Captions on screen
A board reads a touch as a number, and one if line you wrote decides what lights.
- Why. Pads, wires and rooms all change the number. When you know which line compares it, a light that misfires takes minutes to fix.
- Real example. Conductive material wired to pin D0 and a threshold of 2000. Every 100 milliseconds the board prints the raw value, and adds Button touched! while a touch is detected. (Arduino UNO R4 WiFi, Nov 2026)
- When to break it. To test in a day whether people will touch at all, clip a banana to a Makey Makey. It types a space bar press with no code to write.
- Common mistake. Pasting setThreshold(2000) from the tutorial and never printing your own readings. The light stays on, or never comes on, and nobody knows which number to change.
Our take. Print the raw number before you write the if. A threshold copied from a tutorial was tuned on someone else's pad, so it misfires in your shop window and you can't say why.
Print the raw number before you write the if
Open the Serial Monitor and watch the raw reading with nobody near the pad, then with a finger on it. Set the threshold in the gap between the two. The numbers in the picture are pretend; your pad, wire and room give their own.
The threshold belongs in the gap between resting and touched readings
- Nobody near: 1,200. The resting reading. A threshold below it lights the diya with nobody there.
- Threshold: 2,000. Set inside the gap, with room on both sides.
- Finger pressed flat: 3,200. The touched reading. A threshold above it means no touch ever lights the LED.
One if line decides what counts as a touch
Arduino's tutorial sets 2000 for a pad on pin D0, and the library's own example sets 500 on its LOVE_BUTTON pin. Neither number knows your pad. Copy one without printing yours, and the light may stay on or never come on.
- setThreshold(2000), pasted as it was
- No readings printed from this plate
- Diya lit all evening, or never
- Nobody knows which number to change
- Resting and touched readings printed first
- Threshold set in the gap between them
- Checked again in the shop window itself
- Both readings written in the notes
A made-up Diwali window, built for this lesson.
The same path can press a key on a computer
A Makey Makey swaps the LED for a computer. Clip a banana to the Space input, hold the Earth clip and touch the banana. The circuit closes through your body, and the board sends a space bar press, as a keyboard would.
A Makey Makey turns a touched banana into a key press
- You to Banana: Touch, holding the Earth clip. Your other hand holds an alligator clip on the Earth row, so you become part of the switch.
- Banana to Makey Makey: Circuit closes on Space. A small, safe signal runs through the banana and your hand back to Earth.
- Makey Makey to Web page: Space bar press. The board acts as a keyboard, so any page that listens for the space bar reacts.
- Web page to You: A bongo plays. Makey Makey's own bongo page plays a drum on the space bar and the left arrow.
Try it
Tune the touch that lights the diya
A simulation with pretend numbers. In a Diwali shop window made up for this lesson, a brass plate on pin D0 lights an LED diya (a small oil lamp). Bring the finger closer, then change the threshold in your if line. A real plate gives its own numbers.
Write the line that lights the diya
Finish loop() so the LED on pin 13 lights when the reading is above your threshold and goes dark when it isn't. Use a number from the gap you measured. The Arduino_CapacitiveTouch library (version 1.4) is open source under the Mozilla Public License 2.0, so a client prototype can use it.
- Prints the reading so you can measure the gap (done)
- Compares the reading with a threshold (not yet)
- Sets pin 13 HIGH when touched (not yet)
- Sets it LOW when not touched (not yet)
Quick check
The diya in your Diwali window stays lit all evening, even with nobody near the brass plate. What do you check first?
Watch next
Watch it for The raw value in the Serial Monitor used to pick a threshold on an UNO R4, then an LED added at 6:14.
Watch it for Bananas played as a piano and Play-Doh used as a game pad. Each touch closes a circuit the board turns into a key press.
Connects to: 2.3 JavaScript for interaction · 7.1 What a camera can sense · 13.1 Data as a creative material · 16.3 Building the prototype
Sources · checked Nov 2026
- Arduino Docs: UNO R4 Capacitive-Touch TutorialThe UNO R4 WiFi and Minima have a Capacitive Touch Sensing Unit (CTSU); the Arduino_CapacitiveTouch library; the Detecting Touch Example on pin D0 with setThreshold(2000), printing the raw value every 100 ms and Button touched!; metal objects, moist materials and bananas as pads; tune the threshold for your environment, such as humidity and nearby electronics
- GitHub: arduino-libraries/Arduino_CapacitiveTouch (README and library.properties)Version 1.4; Mozilla Public License 2.0; the LOVE_BUTTON example with setThreshold(500) and the note that lower values increase sensitivity; isTouched() compares the raw value to the threshold; D0 is a touch pin on both boards
- Arduino Docs: BlinkLED_BUILTIN is D13 on the UNO; a 220 ohm resistor from the pin to the LED's long leg (anode), the short leg (cathode) to GND; the resistor limits current and protects the LED and the output pin
- Makey Makey blog: Why is there an EARTH connection?Hold the Earth clip and touch a banana wired to the space bar input; the circuit runs through your body; the board acts as a keyboard and mouse; the bongo page plays on the space bar and left arrow
- GitHub: arduino/arduino-ide releasesArduino IDE 2.3.11, released 12 Nov 2026
- Arduino UNO R4 WiFi datasheet (ABX00087), modified 19 Nov 2026Section 11.3 Pin Current: the GPIOs can safely handle up to 8 mA. With a red LED near 2.2 V on a 5 V pin, 470 ohms gives about 6 mA