Arduino and ESP (Espressif Systems’ Platforms) are popular platforms used by electronics enthusiasts, hobbyists, and professionals alike for building innovative projects and IoT (Internet of Things) solutions. At the heart of programming for these platforms lies the utilization of C and C++, two powerful and versatile programming languages. Both Arduino IDE and ESP-IDF primarily use C/C++. Understanding how C and C++ are employed in Arduino and ESP development is essential for harnessing the full potential of these platforms. If you are new to the world of C, C++ and microcontroller programming then we suggest reading these two topics:
Computer’s C, C++ Vs Microcontroller’s C, C++
Although we mostly use C language (C++ is in use in more recent times) for microcontrollers, the way we write the logic and compile the files for microcontrollers is not the same as for computers. You can use a g++ compiler (meant for C++ compiling for computers) to compile programs for ARM microcontrollers, but that is not the standard way. Of course, both the computers and microcontrollers use the same C and C++. But the libraries and compilers are different since things are different!
So, the method we described to write Hello World program in C++ and compile on the command line – How to Compile C++ Program and Run, in simple word will not work for the microcontrollers. Computer and microcontrollers are different in many aspects and the engineering streams are different. This snippet to generate Hello World is intended for computers:
---
1 2 3 4 5 6 | #include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; } |
We do not need the instruction to define serial monitor, baud rate, delay etc. Including iostream simplifies our job. Here we have standard output since we are using a full operating system.
It will work on desktops, laptops, Android smartphones, Raspberry Pi etc devices but not on ESP32 development board or Arduino UNO. In the case of microcontrollers, we have limited resources, and no full operating system is running. The hex file is getting directly executed repeatedly. If you are using Arduino IDE, you have to write in C++ in this way to get Hello World printed on serial display:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <Arduino.h> void setup() { // Initialize serial communication Serial.begin(115200); // Wait for serial port to connect while (!Serial) { delay(10); } // Print "Hello, World!" to the serial console Serial.println("Hello, World!"); } void loop() { // Empty loop as we only want to print "Hello, World!" once } |
If you want to write for ESP-IDF, you have to compose your logic in this way:
1 2 3 4 5 6 7 8 9 10 11 12 | #include <stdio.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" void app_main() { // Print "Hello, World!" to the console printf("Hello, World!\n"); // Delay for 1 second vTaskDelay(1000 / portTICK_PERIOD_MS); } |
ESP-IDF uses standard C, yet it is not exactly like the way we program for computers.
If you have learned C/C++ for computers, definitely it will help you in the microcontroller world. Programming for microcontrollers is of a different world. As for our present topic:
Arduino ecosystem: Usually uses custom version of C++ for the microcontrollers
ESP-IDF ecosystem: Usually uses traditional C for the microcontrollers
Arduino:
- Arduino programming primarily revolves around the Arduino IDE, which simplifies the development process by providing an integrated environment for writing, compiling, and uploading code to Arduino boards. The Arduino programming language is based on C/C++, offering a simplified syntax and abstraction layer to facilitate rapid prototyping and development.
- Developers write sketches, which are essentially C/C++ programs with specific Arduino functions and libraries.
- Sketches consist of two essential functions:
setup()for initialization andloop()for the main program execution. - Arduino libraries, written in C/C++, provide pre-written code for common tasks such as interfacing with sensors, controlling motors, and communicating with external devices.
ESP Line:
- Similarly, programming for the ESP line of microcontrollers involves using C and C++ within the Arduino IDE or other development environments such as PlatformIO. While the syntax and structure remain consistent with Arduino programming, developers gain access to additional features and capabilities offered by ESP8266 and ESP32 MCUs.
- Developers utilize libraries specifically designed for ESP platforms, leveraging their built-in functionalities like Wi-Fi and Bluetooth communication, deep sleep modes, and real-time operating system (RTOS) capabilities.
- ESP-specific libraries enable seamless integration of Wi-Fi connectivity, allowing developers to create IoT devices capable of connecting to local networks or the internet.
- Advanced features such as multitasking, secure communication, and over-the-air (OTA) updates are achievable through ESP-IDF (ESP32 IoT Development Framework) or other platform-specific development frameworks.

Conclusion
C and C++ serve as the foundation for programming Arduino and ESP platforms, empowering developers to create a wide range of embedded systems, IoT devices, and interactive projects. By understanding the role of these languages and their usage within the Arduino and ESP development environments, enthusiasts and professionals can unleash the full potential of these platforms to bring their ideas to life.
Whether it’s building simple sensor nodes with Arduino or developing complex IoT solutions with ESP32, proficiency in C and C++ programming is a valuable asset for anyone venturing into the exciting world of electronics and embedded systems development.