Projects / From blink to fade

From blink to fade

Beginner30 minGuided buildReviewed

Build it step by step

0 of 6 done
  1. UNO13.3 mA

    Blink with delay

    Upload the stage 1 code. The green LED blinks, but nothing else can run during the waits.

  2. UNO13.3 mA

    Wire the second LED and the pot

    Red LED on D9, pot middle pin to A0.

  3. UNO

    Try to do both with delay

    Notice the pot only responds once per delay. That is the problem.

  4. UNO

    Switch to millis

    Upload the stage 2 and 3 code. Green blinks steadily while the pot controls the red brightness smoothly.

  5. UNO

    Read the code

    millis() compares the time since the last toggle without stopping.

  6. UNO

    Change the numbers

    Make green blink faster and compare analogWrite values to the pot position.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Green LED anodeUno D8 through 220 ΩBlinks with millis()
Red LED anodeUno D9 through 220 ΩPWM fade pin
Both LED cathodesUno GNDCommon ground
Pot outer pinsUno 5V and GNDReference
Pot middle pinUno A0Brightness 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.

CheckExpected
Green LEDBlinks at 1 Hz with no stutter
Turn the potRed LED fades smoothly from off to full
Both at onceNeither interferes with the other
Move the red LED to D7PWM 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 →

Ask Lark AI

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.