const int flexPin = A0; // Analog pin connected to the voltage divider const int ledPin = 9; // PWM pin connected to an LED void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); } void loop() { int flexValue = analogRead(flexPin); // Read the analog value Serial.println(flexValue); // Print the value to Serial Monitor // Map the flex sensor value to PWM range int brightness = map(flexValue, 700, 900, 0, 255); brightness = constrain(brightness, 0, 255); // Ensure the value is within 0-255 analogWrite(ledPin, brightness); // Set LED brightness delay(100); // Small delay for stability }