This project demonstrates how to use FreeRTOS on an Arduino UNO to run two independent tasks concurrently. Each task controls an LED with a different blinking period, showing how real-time scheduling works without blocking execution.
Project OverviewInstead of using delay(), which blocks the CPU, FreeRTOS allows tasks to sleep independently using vTaskDelay(). This enables accurate timing and parallel execution on a single microcontroller.
The FreeRTOS library is included at the start of the program:
#include <Arduino_FreeRTOS.h>Hardware SetupThe circuit is simple and can be tested on real hardware or simulated using Wokwi:
- Arduino UNO
Red LEDconnected toPin 8Green LEDconnected toPin 9
Red LED Task (Pin 8)
This task blinks the red LED with a 1-second period (500 ms ON, 500 ms OFF).
void TaskBlinkIO8(void *pvParameters) {
pinMode(8, OUTPUT);
while (1) {
digitalWrite(8, HIGH);
vTaskDelay(500 / portTICK_PERIOD_MS);
digitalWrite(8, LOW);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}Green LED Task (Pin 9)
This task blinks the green LED with a 0.5-second period (250 ms ON, 250 ms OFF).
void TaskBlinkIO9(void *pvParameters) {
pinMode(9, OUTPUT);
while (1) {
digitalWrite(9, LOW);
vTaskDelay(250 / portTICK_PERIOD_MS);
digitalWrite(9, HIGH);
vTaskDelay(250 / portTICK_PERIOD_MS);
}
}Task Creation and Scheduler Start
Both tasks are created inside the setup() function using xTaskCreate(). After this, the FreeRTOS scheduler takes control automatically.
void setup() {
xTaskCreate(TaskBlinkIO8, "Blink8", 128, NULL, 1, NULL);
xTaskCreate(TaskBlinkIO9, "Blink9", 128, NULL, 1, NULL);
}The loop() function remains empty because FreeRTOS manages task execution:
void loop() {
// FreeRTOS scheduler runs the tasks
}Key Takeaways- Demonstrates basic FreeRTOS task creation on Arduino
- Shows true multitasking without blocking delays
- Each task runs independently with its own timing
- Understand how xTaskCreate() defines concurrent tasks
- Learn how vTaskDelay() provides precise task timing
- Gain a solid introduction to RTOS-based embedded design
This project is an excellent first step toward real-time embedded programming with FreeRTOS on Arduino.
That's all!If you have any questions or suggestions, don’t hesitate to leave a comment below.


_ztBMuBhMHo.jpg?auto=compress%2Cformat&w=48&h=48&fit=fill&bg=ffffff)

Comments