The Best DIY STEM Tutorials and Projects

OVERVIEW
In this project, we’ll use a potentiometer (a type of adjustable resistor) to control the brightness of an LED using PWM (Pulse Width Modulation)! As we turn the knob, the LED will smoothly fade in and out, just like a dimmer switch. This is a great way to learn how analog inputs work with Arduino and how we can control outputs dynamically. Let’s start playing with light! 💡✨
You can follow this video and the instructions below.
Video
Program / Code
Code is Explained in the Comments of the Code
const int potPin = A0; Potentiometer connected to analog pin A0 const int ledPin = 6; LED connected to digital pin 7 void setup() { Serial.begin(9600); Initialize serial communication at 9600 baud pinMode(ledPin, OUTPUT); Set LED pin as output } void loop() { int potValue = analogRead(potPin); Read potentiometer value (0-1023) Serial.println(potValue); Print potentiometer value to Serial Monitor analogWrite(ledPin, potValue 4); Set LED brightness (divide by 4 to fit PWM range) delay(100); Small delay to prevent flooding the Serial Monitor }
Thank you so much for going through our tutorial, we hope it was easy to follow and you enjoyed it, please share your feedback and pictures of the project (if you have made it) in the comments below .!