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
| Qty | Part | What it does |
|---|---|---|
| 1 | STM32 Blue Pill (STM32F103C8) | the microcontroller board |
| 1 | 220 Ω resistor | Limits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down. |
| 1 | yellow LED | Lights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor. |
Wiring
| # | From | To |
|---|---|---|
| 1 | STM32 Blue Pill (STM32F103C8) PB12 | 220 Ω resistor leg 1 |
| 2 | 220 Ω resistor leg 2 | yellow LED anode (A, long leg) |
| 3 | STM32 Blue Pill (STM32F103C8) GND | yellow LED cathode (C, short leg) |
Step by step
- 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.
- Add the parts. Add a 220 Ω resistor and a yellow LED from the parts palette.
- Wire 1. Connect STM32 Blue Pill (STM32F103C8) PB12 to 220 Ω resistor leg 1.
- Wire 2. Connect 220 Ω resistor leg 2 to yellow LED anode (A, long leg).
- Wire 3. Connect STM32 Blue Pill (STM32F103C8) GND to yellow LED cathode (C, short leg).
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- 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
- STM32 Blue Pill HC-05 Bluetooth on USART2: Wiring, Code and Simulator
- STM32 Blue Pill Button Interrupt (EXTI): Wiring, Code and Simulator
- STM32 Blue Pill ADC Potentiometer and PWM LED: Wiring, Code and Simulator
- STM32 Blue Pill I2C BMP280 with Wire: Wiring, Code and Simulator
- STM32 Blue Pill Serial UART Echo: Wiring, Code and Simulator
- STM32 Blue Pill Servo Motor Sweep: Wiring, Code and Simulator