STM32 Blue Pill LED Blink and Serial: Wiring, Code and Simulator

To build this STM32 Blue Pill LED Blink and Serial project you need an STM32 Blue Pill (STM32F103C8) and a 220 Ω resistor and a yellow LED. Arduino C++ on an STM32F103 (ARM Cortex-M3): the on-board LED on PC13 (lit when LOW) and an LED on PB12 blink once a second, and Serial counts. Make the 3 connections in the wiring table, upload the Arduino C++ code, and change delay(500) to delay(100) and run again. Notice PC13 is active-low: LOW turns it on.

Open this circuit in the free STM32 Blue Pill (STM32F103C8) simulator

Parts list

QtyPartWhat it does
1STM32 Blue Pill (STM32F103C8)the microcontroller board
1220 Ω resistorLimits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down.
1yellow LEDLights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor.

Wiring

#FromTo
1STM32 Blue Pill (STM32F103C8) PB12220 Ω resistor leg 1
2220 Ω resistor leg 2yellow LED anode (A, long leg)
3STM32 Blue Pill (STM32F103C8) GNDyellow LED cathode (C, short leg)

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the STM32 Blue Pill (STM32F103C8). No install or account is needed.
  2. Add the parts. Add a 220 Ω resistor and a yellow LED from the parts palette.
  3. Wire 1. Connect STM32 Blue Pill (STM32F103C8) PB12 to 220 Ω resistor leg 1.
  4. Wire 2. Connect 220 Ω resistor leg 2 to yellow LED anode (A, long leg).
  5. Wire 3. Connect STM32 Blue Pill (STM32F103C8) GND to yellow LED cathode (C, short leg).
  6. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  7. Run it. Press Run. Change delay(500) to delay(100) and run again. Notice PC13 is active-low: LOW turns it on.

Arduino C++ code

// Blink the Blue Pill's own LED (PC13, lit when the pin is LOW) and an LED on PB12.
void setup() {
  Serial.begin(115200);
  pinMode(PC13, OUTPUT);
  pinMode(PB12, OUTPUT);
  Serial.println("Hello from the STM32 Blue Pill");
}

int blinks = 0;

void loop() {
  digitalWrite(PC13, LOW);   // on-board LED on
  digitalWrite(PB12, HIGH);
  delay(500);
  digitalWrite(PC13, HIGH);  // off
  digitalWrite(PB12, LOW);
  delay(500);
  Serial.print("Blinks: ");
  Serial.println(++blinks);
}

What to try

Change delay(500) to delay(100) and run again. Notice PC13 is active-low: LOW turns it on.

Frequently asked questions

How do I wire the LED Blink and Serial project on an STM32 Blue Pill (STM32F103C8)?

Make 3 connections: STM32 Blue Pill (STM32F103C8) PB12 to 220 Ω resistor leg 1; 220 Ω resistor leg 2 to yellow LED anode (A, long leg); STM32 Blue Pill (STM32F103C8) GND to yellow LED cathode (C, short leg).

What parts do I need for this STM32 Blue Pill project?

An STM32 Blue Pill (STM32F103C8) and a 220 Ω resistor and a yellow LED.

Can I simulate this STM32 Blue Pill project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is built with the STM32duino core and runs on an STM32F103 emulated instruction by instruction: its ARM Cortex-M3 core, NVIC and peripherals (GPIO, EXTI, USART, timers, ADC and I²C).

What does the code do?

Arduino C++ on an STM32F103 (ARM Cortex-M3): the on-board LED on PC13 (lit when LOW) and an LED on PB12 blink once a second, and Serial counts.

More STM32 Blue Pill (STM32F103C8) projects