You have the LED attached to Pin 11. This is a digital I/O pin. You need to use a PWM pin. The PWM pins for an Uno or Nano are 3, 5, 6, and 9. Follow this example to fade your LED slowly...
https://docs.arduino.cc/built-in-examples/basics/Fade/
Try something like this... (I moved the LED pin)
// https://forum.arduino.cc/t/how-can-i-make-fade-led-using-tpp223-touch-sensor-and-arduino/1261218
// https://docs.arduino.cc/built-in-examples/basics/Fade/
const int TTP223 = 7;
const int led = 9;
const int fadeAmount = 5; // how many points to fade the LED by
int brightness = 255; // how bright the LED is
void setup() {
pinMode(led, OUTPUT);
pinMode(TTP223, INPUT);
}
void loop() {
int sensorState = digitalRead(TTP223);
if (sensorState == HIGH) {
digitalWrite(led, HIGH);
fade();
}
else
digitalWrite(led, LOW);
}
void fade() {
for (int i = 0; i < 255; i++) {
analogWrite(led, 255 - brightness);
brightness = brightness - fadeAmount;
}
delay(250); // this slows the fade time
}
for WOKWI.COM
diagram.json
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-nano", "id": "nano", "top": 0, "left": 0, "attrs": {} },
{
"type": "wokwi-pushbutton",
"id": "btn1",
"top": -51.4,
"left": 134.4,
"attrs": { "color": "green" }
},
{
"type": "wokwi-resistor",
"id": "r1",
"top": -24.85,
"left": 67.2,
"attrs": { "value": "10000" }
},
{
"type": "wokwi-led",
"id": "led1",
"top": -70.8,
"left": 33,
"attrs": { "color": "red", "flip": "1" }
}
],
"connections": [
[ "nano:7", "r1:1", "green", [ "v0" ] ],
[ "nano:5V", "btn1:1.r", "red", [ "v14.4", "h85.9", "v-115.2", "h-9.8" ] ],
[ "nano:GND.2", "r1:2", "black", [ "v0" ] ],
[ "r1:2", "btn1:2.l", "green", [ "v0" ] ],
[ "nano:GND.2", "led1:C", "black", [ "v0" ] ],
[ "nano:9", "led1:A", "green", [ "v0" ] ]
],
"dependencies": {}
}