Build it step by step
0 of 6 doneBlink with delay
Upload the stage 1 code. The green LED blinks, but nothing else can run during the waits.
Wire the second LED and the pot
Red LED on D9, pot middle pin to A0.
Try to do both with delay
Notice the pot only responds once per delay. That is the problem.
Switch to millis
Upload the stage 2 and 3 code. Green blinks steadily while the pot controls the red brightness smoothly.
Read the code
millis() compares the time since the last toggle without stopping.
Change the numbers
Make green blink faster and compare analogWrite values to the pot position.
How do you build a from blink to fade?
Start with a blinking LED, then use millis() for two blink rates at once, then fade with PWM. You need Arduino Uno R3, LED 5 mm red, LED 5 mm green, Resistor 220 Ω × 2, Potentiometer 10 kΩ, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to B cable (Uno / Mega). It takes 6 steps and about 30 minutes.
- Level
- Beginner
- Time
- About 30 min
- Parts
- 8
Parts list
- Development BoardsBuyArduino Uno R3 × 1
- SemiconductorsBuyLED 5 mm red × 1
- SemiconductorsBuyLED 5 mm green × 1
- PassivesBuyResistor 220 Ω × 2
- PassivesBuy
- PrototypingBuy
- PrototypingBuy
- Cables & WiresBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Green LED anode | Uno D8 through 220 Ω | Blinks with millis() |
| Red LED anode | Uno D9 through 220 Ω | PWM fade pin |
| Both LED cathodes | Uno GND | Common ground |
| Pot outer pins | Uno 5V and GND | Reference |
| Pot middle pin | Uno A0 | Brightness input |
Code
Arduino IDE, board "Arduino Uno". No libraries. Stage 1 is in comments so you can try delay() first. The final sketch does two jobs together, which delay() cannot do.
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Stage 1: blink with delay (try this first, then replace with the code below)
// void setup() { pinMode(8, OUTPUT); }
// void loop() { digitalWrite(8, HIGH); delay(500); digitalWrite(8, LOW); delay(500); }
// delay() blocks everything, so nothing else can happen while it waits.
// Stage 2 and 3: two jobs at once with millis(), plus a pot that sets PWM brightness
const byte GREEN = 8, RED = 9, POT = A0;
unsigned long lastToggle = 0;
bool greenOn = false;
void setup() {
pinMode(GREEN, OUTPUT);
pinMode(RED, OUTPUT);
}
void loop() {
if (millis() - lastToggle >= 500) { // green blinks every half second, with no delay()
lastToggle = millis();
greenOn = !greenOn;
digitalWrite(GREEN, greenOn);
}
int level = analogRead(POT) / 4; // 0 to 1023 becomes 0 to 255
analogWrite(RED, level); // red brightness follows the pot at the same time
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Green LED | Blinks at 1 Hz with no stutter |
| Turn the pot | Red LED fades smoothly from off to full |
| Both at once | Neither interferes with the other |
| Move the red LED to D7 | PWM stops working because D7 has no PWM |
If it does not work
Red LED does not fade
It is on a pin without PWM. Use D3, D5, D6, D9, D10 or D11 on an Uno.
Pot reads noisy
Wires are loose. Check the middle pin and the supply.
Green blinks unevenly
A delay() is still in the loop. Remove it.
Upload fails
Choose the right board and port in the Tools menu.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the from blink to fade?
Arduino Uno R3, LED 5 mm red, LED 5 mm green, Resistor 220 Ω × 2, Potentiometer 10 kΩ, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to B cable (Uno / Mega).
How long does the from blink to fade take to build?
About 30 minutes for a beginner maker, in 6 steps.
How do I know the from blink to fade works?
Green LED: Blinks at 1 Hz with no stutter. Turn the pot: Red LED fades smoothly from off to full. Both at once: Neither interferes with the other.
Red LED does not fade: what should I check?
It is on a pin without PWM. Use D3, D5, D6, D9, D10 or D11 on an Uno.
Pot reads noisy: what should I check?
Wires are loose. Check the middle pin and the supply.
Green blinks unevenly: what should I check?
A delay() is still in the loop. Remove it.
Upload fails: what should I check?
Choose the right board and port in the Tools menu.
