The LEDs are connected in series so there is only one resistor for all of them. Because the LEDs are in series, they divide the voltage from the battery.
The LEDs are connected in parallel or have their own resistor. Because they are in parallel each LED gets the full voltage of the battery.
The Arduino pin only provides a small digital signal (HIGH/LOW) to the base of the transistor. The transistor acts as a switch to turn on or off the stronger current for the LED because of this, even though the arduino has a small power, it can still control very strong loads.
The potentiometer is like a variable resistor, which changes voltage from 0V to 5V and is passed through the Arduino's analog input (A0-A5) as an analog signal (value 0-1023). In the program, it is used to control the PWM output so the LED brightness changes not just on/off.
Th Arduino sends a digital signal (HIGH = 5V, LOW = 0V) to each LED. In the program, the LEDS are set to blink while in sequence.
// C++ code
//
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
int potPin = A0; // Potentiometer connected to A0
int ledPin = 9; // LED connected to PWM pin 9
int potValue = 0; // Variable to store potentiometer value
int ledValue = 0; // Variable for PWM brightness
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
potValue = analogRead(potPin); // Read potentiometer (0–1023)
ledValue = map(potValue, 0, 1023, 0, 255); // Convert to PWM range (0–255)
analogWrite(ledPin, ledValue); // Set LED brightness
}
// Potentiometer Analog Input Reader
// Reads a potentiometer and displays the value
const int POT_PIN = A0; // Analog pin for potentiometer
const int LED_PIN = 9; // PWM pin for LED (optional)
const int SAMPLE_DELAY = 100; // Delay between readings (ms)
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Configure pins
pinMode(POT_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
Serial.println("Potentiometer Reader Started");
Serial.println("==============================");
}
void loop() {
// Read the analog value (0-1023)
int rawValue = analogRead(POT_PIN);
// Convert to voltage (0-5V for Arduino Uno)
float voltage = rawValue * (5.0 / 1023.0);
// Convert to percentage (0-100%)
int percentage = map(rawValue, 0, 1023, 0, 100);
// Convert to PWM value (0-255) for LED control
int pwmValue = map(rawValue, 0, 1023, 0, 255);
// Control LED brightness based on pot position
analogWrite(LED_PIN, pwmValue);
// Display readings
Serial.print("Raw: ");
Serial.print(rawValue);
Serial.print(" | Voltage: ");
Serial.print(voltage, 2);
Serial.print("V | Percentage: ");
Serial.print(percentage);
Serial.print("% | PWM: ");
Serial.println(pwmValue);
// Optional: Visual bar graph
Serial.print("[");
for(int i = 0; i < 50; i++) {
if(i < percentage / 2) {
Serial.print("=");
} else {
Serial.print(" ");
}
}
Serial.println("]");
delay(SAMPLE_DELAY);
}
// Alternative: Smoothed reading using averaging
int smoothedRead(int pin, int samples = 10) {
long sum = 0;
for(int i = 0; i < samples; i++) {
sum += analogRead(pin);
delay(2);
}
return sum / samples;
}