Week 2: Digital vs. Analog
This week, I explored the difference between digital and analog data while working with a potentiometer, also known as a variable resistor. Previously, I had used a fixed-value resistor with my LED to prevent it from burning out, but this time the potentiometer allowed me to vary the resistance within a range, rather than being limited to one set number. I began to understand how this type of control existed all around me in everyday devices, such as dimmer switches, volume knobs, and dashboard light controls. During this challenge, I explored how the potentiometer controlled the center pin output, which in turn controlled the LED brightness.
Two LEDs, Same Brightness
The following code was used:
int sensorPin = 0;
int ledPin1 = 13;
int ledPin2 = 12;
void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop()
{
int sensorValue = analogRead(sensorPin);
// Turn both LEDs on
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
delay(sensorValue);
// Turn both LEDs off
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
delay(sensorValue);
}
Challenges and Reflections:
I ran into challenges when trying to use the potentiometer to control the brightness and speed of the LEDs. Even though I understood that the potentiometer should have allowed me to vary the voltage between 0 and 5 volts, the LEDs did not respond the way I expected. At times, the brightness barely changed or the blinking speed stayed the same no matter how far I rotated the knob. This made it difficult to tell if the issue was in the wiring, in the code, or simply in how I was reading the analog values. It was frustrating because I thought adjusting the potentiometer would immediately show clear results, but instead I had to slow down, retrace my steps, and keep testing different pin combinations and code adjustments. Through this struggle, I realized how sensitive and precise the connection between the circuit and the code actually was, and how troubleshooting is a major part of understanding how analog control truly works.
Two LEDs Alternating
The following code was used:
int sensorPin = 0;
int ledPin1 = 13;
int ledPin2 = 12;
void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop()
{
int sensorValue = analogRead(sensorPin);
// LED 1 on, LED 2 off
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
delay(sensorValue);
// LED 1 off, LED 2 on
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
delay(sensorValue);
}
Reflections:
One of the biggest challenges I faced was trying to get the potentiometer to control two LEDs with alternating speed. I kept adjusting the wiring, switching pin configurations, and rewriting sections of the code, but I still could not get both LEDs to respond the way I intended. Each time I thought I solved one issue, something else broke or reacted differently than expected. This experience taught me that even small changes in analog values or timing could completely shift the entire output. Although it was frustrating, it pushed me to slow down, document more carefully, and test one variable at a time instead of rushing to the “final result.” Even though the two LEDs did not alternate the way I wanted in the end, I walked away with a better understanding of how sensitive analog readings can be and how important it is to think step by step rather than assuming the code should just instantly work.
Project Reflections:
As I reflected on this week’s project, I realized how valuable this hands-on experimentation truly was for my learning. Working with the potentiometer pushed me to think differently about how analog data behaves compared to digital outputs, and it reminded me that electronics is not always predictable or straightforward. Even when the outcome did not match what I expected—like not being able to successfully control two LEDs with alternating speed—I still learned a lot from the trial and error process. Every misstep, adjustment, and failed test helped me see where my code logic needed clarity and where my wiring might have been off. I also gained a deeper appreciation for documenting each step because it allowed me to track what changed and what impact each change made. This week reinforced that making is not just about getting a perfect final result, but understanding, experimenting, and growing from every challenge along the way.