This Arduino project demonstrates Pulse Width Modulation (PWM) by controlling the brightness of an LED and the position of a servo motor using a potentiometer. As you turn the potentiometer knob, the LED smoothly dims or brightens, while the servo motor rotates accordingly.
- The potentiometer reads an analog input (0β1023) from pin A0.
- The analog value is mapped to two ranges:
- 0β255 for LED brightness (PWM output to pin 10).
- 0β180Β° for servo motor rotation (signal to pin 9).
- The analogWrite() function adjusts LED brightness.
- The servo.write() function moves the servo.
- Potentiometer:
- Left pin β GND
- Middle pin β A0 (Analog Input)
- Right pin β 5V
- LED:
- Anode (+) β Pin 10 (via resistor)
- Cathode (β) β GND
- Servo Motor:
- VCC (Red) β 5V
- GND (Black/Brown) β GND
- Signal (Yellow/Orange) β Pin 9
π View the Project Simulation
- Add an OLED display to show live PWM and servo angle values.
- Use a button to toggle between different PWM modes.
This project is open-source and available under the MIT License.