In this example, I'll be showing you how to map distance readings (0 to a set maximum) from an ultrasonic sensor to PWM values (0–255) and use them to dynamically adjust LED brightness.
Components Used:
1- Arduino UNO
2- Ultrasonic sensor (HC-SR04)
3- LED
4- Resistor
5- Breadboard & jumper wires