Skip to content

Scratch Visual Programming for ESP32

Scratch Visual Programming for ESP32

This section introduces visual (block-based) programming tools for the ESP32. By the end of this section, you will be able to:

  • Identify the major visual programming platforms that support ESP32
  • Set up a block-based programming environment for ESP32
  • Program an ESP32 using Scratch-like blocks
  • Advise education buyers on visual programming options
  • Basic familiarity with Scratch or other block-based programming interfaces
  • An ESP32 development board

Visual programming lowers the barrier to entry for ESP32 development. Instead of writing C++ syntax, users drag and drop logic blocks. This approach is particularly valuable for:

  • K-12 Education: Students learn programming logic (loops, conditionals, variables) without syntax frustration
  • Rapid Prototyping: Quickly test hardware ideas without writing code
  • Non-Developer Audiences: Product managers, designers, and educators who need to understand ESP32 capabilities
  • Workshop Settings: Short sessions where the focus is on hardware interaction, not coding

mBlock (Makeblock)

The most mature Scratch-based platform for ESP32.

  • Based on: Scratch 3.0
  • Platform: Desktop (Windows/macOS) and Web
  • ESP32 Support: Native via “mBuild” ecosystem or generic ESP32
  • Features:
    • Drag-and-drop blocks generate Arduino C++ code
    • Switchable between block view and code view
    • Built-in serial monitor
    • Upload directly to ESP32
    • Supports Wi-Fi and MQTT blocks
  • Best For: Classroom education, K-12 STEM programs

Mixly (BNU/China)

A visual programming tool widely used in Chinese STEM education.

  • Based on: Google Blockly
  • Platform: Desktop (Windows/macOS/Linux)
  • ESP32 Support: Yes, with board package
  • Features:
    • Generates Arduino C++ code
    • Supports most common sensors and actuators
    • Chinese and English interface
    • Lightweight installation (~100 MB)
  • Best For: Chinese education market, budget-constrained classrooms

ArduBlock

An older but still functional block programming plugin for the Arduino IDE.

  • Based on: OpenBlocks
  • Platform: Plugin for Arduino IDE (Java-based)
  • ESP32 Support: Via Arduino IDE’s ESP32 core
  • Features:
    • Runs inside Arduino IDE
    • Generates standard Arduino code
    • Very simple interface (fewer blocks than mBlock)
  • Best For: Transitioning from blocks to text within the Arduino IDE

Arduino PLC IDE (Visual Programming)

Arduino’s official visual programming environment for industrial applications.

  • Platform: Desktop
  • ESP32 Support: Via Arduino Portenta (not standard ESP32)
  • Note: Not recommended for standard ESP32 education
  1. Download mBlock from mblock.makeblock.com
  2. Install the desktop application
  3. Launch mBlock
  4. Go to Devices tab and add a new device
  5. Search for “Arduino” or “ESP32”
  6. Select the appropriate board (e.g., “Arduino Uno” — mBlock uses this as generic code generator)
  7. Connect the ESP32 via USB

Note: mBlock generates Arduino C++ code. The compiled code is uploaded to the ESP32 via the standard Arduino upload process. You need the ESP32 Arduino Core installed (see 01-04).

  1. From the Events category, drag “when Arduino starts” block
  2. From the Pins category, drag “set pin 13 to HIGH” block
  3. From the Control category, drag “wait 1 seconds” block
  4. From the Pins category, drag “set pin 13 to LOW” block
  5. From the Control category, drag “wait 1 seconds” block
  6. Add a “forever” loop block around steps 2-5

Blocks Arrangement:

when Arduino starts
forever
set pin 13 to HIGH
wait 1 seconds
set pin 13 to LOW
wait 1 seconds
  1. Click Upload to compile and upload to ESP32
  2. Observe the built-in LED (GPIO 2 on most ESP32 DevKits) blinking
  1. Connect a DHT11/DHT22 sensor to the ESP32:
    • VCC → 3.3V
    • DATA → GPIO 4
    • GND → GND
  2. In mBlock, add the “DHT11” extension from the Extensions menu
  3. Use the “read temperature from DHT11 pin 4” block
  4. Use the “read humidity from DHT11 pin 4” block
  5. Display the values using a “say” block or send to Serial

Blocks Arrangement:

when Arduino starts
forever
set variable temperature to (read temperature from DHT11 pin 4)
set variable humidity to (read humidity from DHT11 pin 4)
Serial print (join "Temp: " temperature)
Serial print (join " Humidity: " humidity)
Serial print newline
wait 5 seconds

In mBlock, switch to Code View to see the Arduino C++ code generated by the blocks:

#include <Arduino.h>
#include <DHT.h>
DHT dht(4, DHT11);
float temperature = 0;
float humidity = 0;
void setup() {
Serial.begin(115200);
dht.begin();
pinMode(13, OUTPUT);
}
void loop() {
temperature = dht.readTemperature();
humidity = dht.readHumidity();
Serial.print("Temp: ");
Serial.print(temperature);
Serial.print(" Humidity: ");
Serial.print(humidity);
Serial.println();
delay(5000);
}

This is a powerful learning feature: students can see how their visual blocks translate into real C++ code, building a bridge to text-based programming.

  • mBlock (or chosen tool) successfully installs and detects the ESP32
  • The blink program uploads and executes correctly
  • The sensor reading program displays correct values in the serial monitor
  • Generated C++ code can be viewed and understood
  • The board can be switched between block and code views

Causes:

  • USB driver not installed
  • Wrong port selected
  • mBlock Arduino connector not activated

Solutions:

  1. Install CP2102 or CH340 driver
  2. In mBlock, go to Connect and select the correct USB port
  3. Restart mBlock after installing the driver

Causes:

  • ESP32 board package not installed in behind-the-scenes Arduino IDE
  • Wrong board selected for compilation

Solutions:

  1. Manually install ESP32 board support in Arduino IDE first
  2. In mBlock, verify the upload settings point to the correct board
  3. Manually upload the exported .ino file via Arduino IDE

Causes:

  • Extension not installed
  • Sensor not supported by the visual tool

Solutions:

  1. Check if an extension exists for your sensor
  2. Use the “custom block” feature to write a simple Arduino code snippet
  3. Switch to Arduino IDE or PlatformIO for unsupported sensors
  • Use block view for logic learning, code view for syntax transition: The biggest advantage of visual tools is showing the connection between blocks and code
  • Start with mBlock for K-12: It has the best ESP32 support, largest block library, and most classroom resources
  • Limit visual programming to introductory content: Students should transition to text-based programming once they understand logic concepts (typically after 4-8 sessions)
  • Combine with physical computing: Visual programming is most engaging when connected to real LEDs, sensors, and motors
  • For pre-sales demos: Visual programming is an excellent way to show non-technical buyers how ESP32 works without showing code
  1. Visual programming tools (mBlock, Mixly, ArduBlock) enable ESP32 programming without writing C++ code
  2. mBlock is the most comprehensive option, supporting ESP32 with extensions for Wi-Fi, MQTT, and common sensors
  3. Visual tools generate standard Arduino C++ code — students can see the code behind the blocks
  4. Best suited for K-12 education, rapid prototyping, and non-developer audiences
  5. Visual programming should be a stepping stone to text-based programming (Arduino IDE or PlatformIO)