ESP32 vs Arduino Speed Comparison

ESP32 vs Arduino Speed Comparison

This article will give you all the necessary information about the ESP32 and Arduino boards. I have included a detailed specification and a pin diagram of the ESP32 and Arduino Boards.

You will learn in detail about the speed and functionality difference between the ESP32 and Arduino Uno and Arduino Mega boards.

Supplies

Hardware components

Arduino Uno Rev3Amazon
Arduino Mega ( Optional )Amazon
ESP32Amazon
ESP8266 ( Optional )Amazon
USB cable type A/BAmazon
Micro-USB cableAmazon

Software

Arduino IDEArduino IDE

Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on Amazon.com.

Specification of ESP Board and Arduino Board

The following table compares the specifications and features of ESP32 and NodeMCU ESP8266 against the popular Arduino boards:

FunctionESP32NodeMCU ESP8266Arduino UNOArduino Mega2560
MicrocontrollerXtensa Dual Core 32-bit LX6 microprocessorTensilica 32-bit Xtensa LX106ATMega328PATMega2560
Flash Memory4MB4 MB32KB256 KB 
SRAM520MB128 KB2KB8KB
EEPROMNot AvailableNot Available512 bytes (Software)1KB4KB
CLOCK SpeedUpto 240 MHz80 or160 MHz16MHZ16 MHz
Operating Voltage3.3V DC3.3V DC5V DC5V DC
Input Voltage3.3V DC7-12 DC6V-20V DC7-12V
Current consumption80 mA  – 90mA15 µA – 400 mA45 mA – 80 mA150 uA
DC Current per I/O Pin40 mA12 mA20 mA20 mA
DC Current For 3.3V Pin50 mA1A50 mA50 mA
Digital IO Pins36171454
Analog Input PinsUp to 181616
UARTs3214
SPI4211
I2C2111
CANYesNoNoNo
PWM164614
Wi-FiYes,802.11 b/g/nYesNoNo
BluetoothYes, Bluetooth v4.2 BR/EDR and BLE specificationNoNoNo

Pin Comparison of ESP32 and Arduino UNO

You can refer to the ESP32 Schematic diagram  for more details about the components present on the ESP32 board. The pin diagram of ESP32 is depicted below.

ESP32 Pin Diagram
ESP32 Pin Diagram

You can also refer to the Arduino Uno Schematic diagram for details of components present on the Arduino UNO board. The pin diagram of Arduino UNO is depicted below.

Arduino Uno Pin Diagram
Arduino Uno Pin Diagram

How Is ESP32 Different From Arduino Uno?

This section will provide information about the CPU, clock, and speed-wise difference between ESP32 and Arduino Uno.

1. CPU

ESP32 has 32-bit LX6 Xtensa® Dual-Core microprocessors, which run 600 DMIPS. The two cores are named Protocol CPU (PRO_CPU) and Application CPU (APP_CPU).

The PRO_CPU processor handles the Wi-Fi, Bluetooth, and other internal peripherals like SPI, I2C, ADC, etc. The APP_CPU is left out for the application code.

Arduino Uno is designed with an AVR microcontroller. It is based on the ATmega328P 8-bit microcontroller. It is a single-chip microcontroller.

It has a modified Harvard architecture 8-bit RISC processor single-core CPU.

So, as you can see here, ESP32 is a 32 bit MCU with dual cores, while Arduino Uno is an 8 bit MCU with a single core.

2. CLOCK

ESP32 can be used clocked internally or externally. The ESP32 microcontroller can use an external crystal oscillator.

An external crystal clock source is selected as the default CPU clock upon reset. ESP32 has an internal 8 MHz oscillator. 

The application can select the clock source from the external crystal clock source. It has an external crystal of 40 MHz.

AVR microcontroller has a maximum clock, which defaults to using a 16MHz crystal. It takes 1 / 16 millionths of a second to perform a single operation.

It has three basic units: Clock Sources, Input and Clock Control, Clock Output.

It has multiple clock sources which get multiplexed to multiple peripherals via the AVR Clock Control Unit.

-> Read our guide about What You Can Build with Adruino.

Why Would You Need To Change ESP32 CPU Clock?

CPU clock affects the power consumption, speed of operation, and performance of MCU. That’s why you need to set the speed of MCU as per your requirement.

If you want more details about the power consumption optimization, please refer to the ESP32 User manual.

How to change ESP32 CPU Speed (in Arduino IDE)

You can change the CPU speed from your code by using the below-mentioned command in the code. 

bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz);

The only preferable values entered are 240, 160, and 80, but you can also use lesser values, i.e., 40MHz, 20MHz, and 10MHz, in case you are not using Wi-Fi or Bluetooth.

FrequencyPower consumption
240 MHz66.8mA
160 MHz45.9mA
80 MHz33.2mA
40 MHz19.88mA
20 MHz15.43mA
10 MHz13.19mA

How To Configure ATmega328p Clock Source?

ATmega328P is an 8-bit microcontroller, and the default clock speed is 16 MHz. It has the following two clocking options only. 

1) Calibrated Internal RC Oscillator 

2) Low Power Crystal Oscillator. 

ATmega328P is clocked by the Calibrated Internal RC Oscillator, which runs at 8MHz. This is By default settings.

The 8 MHz clock is divided by 8 due to the setting of the CKDIV8 bit in Fuse Low Byte.

So the effective clock rate available is 1 MHz.

Configuration of Fuse Low Byte

As you can see in the ATmega328P datasheet, table 27-7 show the Lower Fuse bits of this IC.

Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
CLKDIV8(2)4CKOUTSUT1SUT0CKSEL3CKSEL2CKSEL1CKSEL0

ATmega328P Fuse Low Byte

This fuse low byte is responsible for setting up the clock source and some other parameters of the clock inside the AVR.

Now, The frequency is set based on the value of the Fuse Low Byte.

If the value changes, Frequency also changes.

High Fuse Byte: D9   Extended Fuse Byte: FF

Case 1: If Low fuse Byte value 0xCE to set frequency standard set 16MHz ceramic resonator fast start.

Case 2: If Low fuse Byte value 0xF7 to set frequency standard set crystal 16MHz, slow start + CLKO clock.

Case 3: If Low fuse Byte value 0xE2 to set frequency standard set Internal RC oscillator with Prescaler off. 8MHz system clock.

Case 4: If the High Fuse Byte: D1, Extended Fuse Byte: FF 

Low fuse Byte value 0xFE to set frequency 8MHz crystal oscillator.

Case 5: If the High Fuse Byte: DE, Extended Fuse Byte: D5

Low fuse Byte value 0xFF to set frequency standard set 16MHz slow power starting.

ESP32 CPU Details

The following code will give you information about ESP32 CPU details.

uint32_t  CPU_Frequency;
void setup()
{
   Serial.begin(9600);

  CPU_Frequency = getXtalFrequencyMhz();
  Serial.print("ESP32 Crystal Frequency is = ");
  Serial.print(CPU_Frequency);
  Serial.println(" MHz"); 
  setCpuFrequencyMhz(40);

  CPU_Frequency = getCpuFrequencyMhz();
  Serial.print("ESP32 CPU Frequency = ");
  Serial.print(CPU_Frequency);
  Serial.println(" MHz");
  
  CPU_Frequency = getApbFrequency();
 Serial.print("ESP32 APB Frequency = ");
  Serial.print(CPU_Frequency);
  Serial.println(" Hz");
}
void loop()
 {
 }

Code Explanation

 CPU_Frequency = getXtalFrequencyMhz();
 Serial.print(CPU_Frequency);

Step 1: Declare a variable uint32_t  CPU_Frequency;  to store a return value.

Step 2: In setup() function initialize to Serial.begin();  function to set baudrate at 9600.

Step 3: You can get a lower CPU clock for power consumption optimization. You need to check the XTAL crystal frequency using this function.

setCpuFrequencyMhz(40); using this function, you can set the ESP32 CPU clock frequency and print it on the serial terminal.

Step 4: After changing the CPU clock frequency, you can cross-check the CPU clock rate value by reading the following function’s return value. CPU_Frequency = getApbFrequency(); and get it into the result on the serial terminal.

ESP32 and Arduino Board Speed Testing Using DSO

You can use the following code to test the different boards using Digital Storage Oscilloscope (DSO).

#define test_pin 5  //for ESP8266 use D5 instead of 5

void setup() {
  pinMode(test_pin, OUTPUT); //set pin as output
}

void loop() {
  digitalWrite(test_pin, HIGH); //make pin 5 high
  digitalWrite(test_pin, LOW);  //make pin 5 low
}

Code Description

This code is used to detect the execution of the same instruction in ESP32, ESP8266, Arduino Uno, and Arduino Mega boards.

I have used pin 5 as the output pin, and in void loop(), I have set it high and low without delay.

I have connected the Pin 5 of each board on the Digital Storage Oscilloscope (DSO). The following image shows the pulse duration for digitalWrite(test_pin, HIGH) and overall period in void loop().

ESP32 output pulses
ESP32 output pulses
ESP8266 output pulses
ESP8266 output pulses
Arduino Uno output pulses
Arduino Uno output pulses
Arduino Mega output pulses
Arduino Mega output pulses
ParametersESP32ESP8266Arduino UnoArduino Mega
digitalWrite Pulse width112.37 nS (0.1123 μS)800.00 nS(0.800 μS)4.0657 μS5.4367 μS
Void loop period325.00 nS(0.325 μS)5.1625 μS8.5050 μS11.248 μS

How To Test ESP32 and Arduino Speed Using Code?

Now, I will show you how you can test the speed of ESP and Arduino Boards using code only, without using DSO.

unsigned long start, Total ;
#define test_pin 5             //    for ESP8266 use D5 instead of 5
void setup() {
  Serial.begin(9600);
  pinMode(test_pin, OUTPUT);
}
void loop() {
  start = millis();
  for (int i = 0; i < 20000; i++) {
    digitalWrite(test_pin, HIGH);
    digitalWrite(test_pin, LOW);
  }
  Total = millis() - start ;
  Serial.print("Total time taken to state change : ");
  Serial.println(Total);
}

Code Explanation

Step 1: unsigned long start, Total ;

First, declare a variable to start and Total count in a millisecond.

Step 2: #define test_pin 5

Define a Pin used to Toggle the pin state.

Step 3: In void setup(), setup the baud rate at 9600-speed rate, and test pin mode select as an output mode.

Step 4: In millis() the function returns the number of milliseconds passed since the Arduino board started.

And return millis(); function return value to catch in start variable ,which  before declare.

Step 5: for (int i = 0; i < 20000; i++) 

{digitalWrite(test_pin, HIGH);
 digitalWrite(test_pin, LOW);
  }

This loop rotates 20,000 times and makes test_pin HIGH and LOW.

Step 6: Difference between Till now millisecond and before Received millisecond and result store into Total variable and print on the serial terminal.

Now, You can observe the output on the serial terminal.

Here are the results from the speed tests I ran comparing the speed of the ESP32 vs ESP8266 vs Arduino Mega2560 vs Arduino Uno boards.

Case 1: ESP32 Output

ESP32 Output

Case 2: ESP8266 Output

ESP8266 Output

Case 3: Arduino Mega2560 Output

Arduino Mega2560 Output

Case 4: Arduino Uno Output

Arduino Uno Output

This table summarizes the results from the speed tests that I ran comparing all 4 boards:

ESP32ESP8266ArduinoMega2560Arduino Uno
5 millisecond64 millisecond226 millisecond171 millisecond

As you can see, the ESP32 board was by far the fastest, followed by the ESP8266, then the Arduino Uno, and the slowest was the Arduino Mega2560.

-> Read our article about How Easy Is It To Learn Arduino?

Is ESP32 Faster Than ESP8266?

Yes, ESP32 is faster than ESP8266. The ESP32 is the ESP8266 successor. It adds an extra CPU core, faster Wi-Fi, more GPIOs, and supports Bluetooth 4.2 and Bluetooth low energy.

Both chips have a 32-bit processor. The ESP32 is a dual-core 160MHz to 240MHz CPU, whereas the ESP8266 is a single-core processor that runs at 80MHz.

Also, the result shows that ESP32 is almost seven times faster than ESP8266 because for digitalWrite instruction ESP32 takes 112.37 nS while ESP8266 takes 800 nS.

Is ESP32 More Powerful Than Arduino?

Yes, the ESP32 is faster and more powerful than Arduino.

The ESP32 is a powerful 32-bit microcontroller with integrated Wi-Fi, a full TCP/IP stack for internet connection, and Bluetooth 4.2. It has 10 internal capacitive touch sensors.

Arduino Mega and Uno is an 8-bit microcontroller. The Arduino boards don’t have wireless connectivity, Bluetooth, and touch sensors.

Also, ESP32 is much faster than Arduino boards. So, ESP32 is more powerful than Arduino Board.

Can We Use ESP32 Instead of Arduino?

The ESP32 development board is actually cheaper than the Arduino board. As you already know, the ESP32 development board is a more powerful board for a lower price.

Although ESP32 has a different architecture than Arduino boards, it supports the Arduino IDE framework. So, the code looks similar for both boards.

> Check out our guide to the Top 12 Best Arduino Online Courses

Conclusion

In this article, I have shown you the specification of ESP Board and Arduino Board, and how ESP32 is faster than ESP8266 and Arduino boards.

I hope you found this article informative. I would love to know what project you plan on building or have already made with the Arduino or ESP32.

If you have any queries or suggestions, or if you think things are missing in this tutorial, please leave a comment below.

Note that comments are held for moderation to prevent spam.