Agenda
⮚ Overview of STM32
⮚ STM32 Development Environment
⮚ Setting up the First STM32 Project
⮚ STM32 Microcontroller Architecture
1
Overview of STM32
STM32 is a family of 32-bit microcontrollers from
STMicroelectronics, based on ARM Cortex-M cores.
It includes various series like
• STM32F0 (entry-level),
• STM32F4 (high-performance),
• STM32L (low-power), and others.
STM32 offers a wide range of peripherals, power
management features, and processing power,
making it suitable for embedded applications.
2
Overview of STM32
STM32F103C8T6 Full Form & Meaning:
“Blue Pill” or STM32F103C8T6 name has a meaning
behind it.
STM – stands for the manufacturer’s name
STMicroelectronics
32 – stands for 32-bit ARM architecture
F103 – stands to indicate that the architecture ARM
Cortex M3
C – 48-pin
8 – 64KB Flash memory
T – package type is LQFP
6 – operating temperature -40°C to +85°C
3
STM32 Nucleo-64
• Supports Arduino and ST morpho connectivity
• ARDUINO® Uno V3 expansion connector
• 32.768 kHz crystal oscillator
• 1 user and 1 reset push-buttons
• 24 MHz or 48 MHz HSE
• USB Type-C®, Micro-B, or Mini-B connector for the ST-
LINK
• CAN FD header
• Memories: 256kB Flash, 48kB RAM
4
Why use stm32 over Arduino?
Uno STM32 Blue Pill
Pricing $20-23 $3-5
I/O Pins 14 37
PWM Pins 6 15
Analog In Pins 6 10
Flash Memory 32 kB 64 kB
SRAM 2 kB 20 kB
Clock speed 16 MHz 72 MHz
Voltage Level 5V 3.3 V
USB Connectivity Standard A/B USB Micro-USB
Hardware Serial Ports 1 3
I2C Support Yes (1x) Yes (2x)
5
STM32 Development Environment
Top IDEs for STM32 Development:
• Keil MDK (Microcontroller Development Kit)
• STM32CubeIDE
• PlatformIO with VSCode
• Atollic TrueSTUDIO
• IAR Embedded Workbench
• Eclipse IDE for STM32 Development
STM32CubeIDE
STM32CubeIDE is an official IDE developed by STMicroelectronics, specifically tailored for STM32
microcontrollers. It offers seamless integration with STM32CubeMX, a graphical tool for hardware
configuration, which speeds up the initialization process. The IDE is based on Eclipse and provides an
extensive range of plugins to enhance productivity. Moreover, STM32CubeIDE comes with advanced
debugging features like runtime variable monitoring and data visualization.
6
ARM Architecture
ARM stands for Advanced Risk
Machine.
It is one of the most popular
architectures used in devices like
cameras, mobile phones and
embedded system devices.
These are known for their low-
power-consumption vs better
performance abilities.
7
STM32 project to blink an LED
while (1)
{
// Toggle the LED
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
// Wait for 500 ms
HAL_Delay(500);
8
STM32 project to blink an LED
9
CEP with STM32
Q1
Daffodil Smart City aims to improve the safety, security, and
environmental quality of its community areas, including gates, parks,
walkways, swimming pools, and parking spaces. Residents often use these
spaces early in the morning and during the evening, requiring well-lit,
safe, and environmentally comfortable conditions. Additionally, ensuring
security during low-activity periods and after hours remains a challenge
for the management team. Design a cost-effective, scalable IoT-based
smart system using the STM32 platform to monitor air quality,
temperature, light levels, and motion, while also automatically controlling
streetlights and security alarms as needed.
10
Complex Engineering Problems (CEP)
with STM32
Problem Overview
Daffodil Smart City needs to enhance the safety, security, and
environmental quality of its community areas (gates, parks, walkways,
swimming pools, parking spaces). These areas are frequently used during
early mornings and evenings, necessitating well-lit, safe, and comfortable
conditions. Additionally, monitoring security during off-hours or low-
activity periods poses a challenge for city management. The goal is to
design a cost-effective, scalable IoT system based on STM32
microcontrollers to automatically monitor environmental parameters (air
quality, temperature, light) and detect motion, controlling streetlights and
security alarms accordingly. 11
Solution of the CEP with STM32
System Requirements
● Monitor air quality, temperature, and ambient light levels in real-time.
● Detect motion to identify human presence.
● Automatically control street lighting based on ambient light and motion.
● Trigger security alarms if motion is detected during restricted/off-hours.
● Ensure scalability for future expansions.
● Wireless communication for remote monitoring and control (optional but preferred).
● Use STM32 microcontroller as the core processing unit.
● Low power consumption for energy efficiency. 12
Solution of the CEP with STM32
Components Required
Component Description
STM32 Microcontroller Core processor to manage sensors and actuators
Air Quality Sensor e.g., MQ-135, to monitor pollutants
Temperature Sensor e.g., DHT22 or LM35
Ambient Light Sensor e.g., BH1750 or LDR sensor
PIR Motion Sensor For motion detection
Relay Module To switch streetlights and alarms ON/OFF
Streetlights (LED or other) Lighting actuators
Buzzer or Siren Security alarm system
Power Supply Suitable regulated power supply
Optional: Wi-Fi/Bluetooth Module For IoT connectivity (ESP8266, BLE module)
Supporting Components Resistors, capacitors, connectors, PCB etc. 13
Solution of the CEP with STM32
Software Design
Functional Flow
1. Initialization:
○ Initialize STM32 peripherals (GPIO, ADC, UART, timers).
○ Initialize sensors (air quality, temperature, light, motion).
○ Configure relay control pins.
2. Sensor Data Acquisition:
○ Read air quality sensor data.
○ Read temperature sensor data.
14
○ Read ambient light sensor value.
Solution of the CEP with STM32
Software Design
1. Decision Making:
○ If ambient light is below threshold and motion is detected → turn ON streetlights.
○ If no motion for a defined timeout → turn OFF streetlights.
○ If motion detected during off-hours (e.g., midnight to 6 am) → activate security alarm.
○ Continuously monitor air quality and temperature to log or send alerts if outside safe ranges.
2. Output Control:
○ Activate/deactivate relays for streetlights and security alarms accordingly.
3. Optional IoT Communication:
○ Transmit sensor data and alerts to remote server or user app via Wi-Fi/Bluetooth. 15
Solution of the CEP with STM32
Conclusion
● The designed STM32-based IoT system provides a smart, automated solution for
enhancing safety, security, and environmental monitoring in the Daffodil Smart City.
By integrating air quality, temperature, light, and motion sensors, the system
dynamically controls street lighting and security alarms based on real-time conditions
and usage patterns. The modular and scalable design allows future expansion with
IoT communication capabilities and additional sensors or actuators, supporting
sustainable smart city development at a cost-effective scale.
16