111 dự án khối lệnh · Arduino · ESP32 · Pico

Lập trình khối cho dự án Arduino, ESP32 và Pico

Theo dõi các khối lệnh nhiều màu thay vì đọc code từng dòng. 111 dự án BlueGrays có phiên bản khối lệnh, và mỗi khối tương ứng với một dòng code thật chạy trên bo mạch.

Lập trình khối là gì?

Lập trình khối là tạo chương trình bằng các khối giống mảnh ghép thay vì gõ chữ. "Đặt chân làm đầu ra", "bật LED" và "chờ 1 giây" đều là các khối, và xếp chúng lại sẽ thành chương trình. Không phải lo dấu chấm phẩy, dấu ngoặc hay lỗi gõ, nên bạn tập trung được vào logic.

BlueGrays dùng bộ khối lệnh riêng, và các khối nói ngôn ngữ của bạn: nếu ứng dụng dùng tiếng Anh, trên khối sẽ ghi "repeat forever" và "write HIGH to pin". Trong dự án Arduino và ESP32, khối lệnh tương ứng với code C++; trong dự án Raspberry Pi Pico, chúng tương ứng với MicroPython.

Mục tiêu không phải là dùng khối lệnh mãi mà là hiểu code. Đặt khối lệnh của một dự án cạnh code của nó, bạn sẽ thấy mỗi dòng làm gì. Sau vài dự án, bạn bắt đầu đọc code mà không cần khối lệnh.

Lập trình khối hoạt động thế nào trong BlueGrays

Trong ứng dụng, khối lệnh nằm ở phần code của mọi dự án khối lệnh. Bốn bước:

  1. 01

    Chọn một dự án khối lệnh

    Các dự án có huy hiệu khối lệnh đi kèm phiên bản khối lệnh. Bạn cũng có thể lọc danh sách để chỉ hiện dự án khối lệnh.

  2. 02

    Bật "Hiển thị dạng khối"

    Một công tắc trong phần code biến code thành khối lệnh. Chạm vào ảnh để mở toàn màn hình và phóng to.

  3. 03

    Hiểu khối lệnh

    Tab "Hiểu khối lệnh" dẫn bạn qua chương trình từng bước, chỉ hiện các khối của mỗi bước và việc chúng làm.

  4. 04

    Chuyển sang code thật

    Tắt công tắc và chương trình đó sẽ hiện dưới dạng code. Sao chép vào Arduino IDE (hoặc Thonny cho Pico) rồi nạp vào bo mạch.

Một chương trình: khối lệnh và code

Bên trái là khối lệnh của dự án. Bên phải là code chạy trên bo mạch. Mỗi khối có một dòng code tương ứng.

Khối lệnh

Code khối lệnh của LED Blink
LED BlinkMở kích thước đầy đủ

Code

C++ (Arduino IDE)
1// ─────────────────────────────────────────
2//   BlueGrays · bluegrays.com
3//   LED Blink
4// ─────────────────────────────────────────
5// Blinks a single LED on and off every 100 ms. Shows the basic use of the
6// digitalWrite and delay functions.
7//
8// Pins:
9//   D9 -> LED (with a 220 ohm resistor)
10
11void setup() {
12  pinMode(9,OUTPUT);     // LED pin as output
13}
14
15void loop() {
16  digitalWrite(9,HIGH);  // Turn the LED on
17  delay(100);            // Wait 100 ms (1000 ms = 1 s)
18  digitalWrite(9,LOW);   // Turn the LED off
19  delay(100);
20}
21
Mở dự án: LED Blink

Dự án khối lệnh

Mọi dự án có phiên bản khối lệnh, theo nền tảng. Dự án miễn phí được xếp trước: 31 dự án hoàn toàn miễn phí, gồm cả khối lệnh và code.

Dự án Arduino74 dự án khối lệnh

LED Blink
AR-1Cơ bản

LED Blink

The very first hello of electronics: switching a single LED on and off. The Arduino turns the LED on and off at short intervals, so the light blinks quickly.

4.6(200)
1246
Two LEDs Blinking Alternately
AR-2Cơ bản

Two LEDs Blinking Alternately

Two LEDs blink quickly in turn: when one lights up the other goes off, as if they were tossing a ball back and forth.

4.6(110)
362
Traffic Light
AR-3Cơ bản

Traffic Light

A tiny copy of the traffic light you see on the road every day. Red stays on for two seconds, yellow flashes for a moment, green stays on for two seconds, then it goes back to red through yellow…

4.8(137)
440
LED Police Lights
AR-4Cơ bản

LED Police Lights

Just like the lights on a police car: the red LED flashes three times in quick succession, then the blue LED flashes three times, and the pattern keeps repeating without a break.

4.7(105)
283
LED Chaser
AR-5Trung bình

LED Chaser

Lights that switch on one after another, as if they were running. The Arduino lights six LEDs one at a time; each glows for a brief moment and goes out, so the light walks from start to end and then…

4.6(87)
218
Knight Rider LED Effect
AR-6Trung bình

Knight Rider LED Effect

The classic scanner light: a dot of light slides from one end of six LEDs to the other and then comes back.

4.8(107)
214
LED Chaser with Adjustable Speed
AR-7Trung bình

LED Chaser with Adjustable Speed

Six LEDs light up one after another, so the light seems to run from one end to the other.

4.6(72)
148
Knight Rider LED Effect with Adjustable Speed
AR-8Trung bình

Knight Rider LED Effect with Adjustable Speed

A light runs from one end of six LEDs to the other, turns around and runs back again.

4.5(60)
124

Dự án Arduino: tất cả dự án khối lệnh

Dự án ESP3223 dự án khối lệnh

LED Blink with ESP32
ES-1Cơ bản

LED Blink with ESP32

Teaches basic GPIO output usage with ESP32. We achieve a blinking effect by turning an LED on and off from a digital pin. ESP32 version of the classic blink project on Arduino UNO; the basic blink commands in the Arduino environment are the same, but the ESP32's pin layout and 3.3 V GPIO levels differ from those of the Arduino UNO.

4.7(37)
108
ESP32 LED Control with Push Button (Push)
ES-2Cơ bản

ESP32 LED Control with Push Button (Push)

The LED lights up when the button is pressed and turns off when released. Shows how the ESP32's digital input pin and internal pull-up resistor are used. The INPUT_PULLUP mode eliminates the need for an external resistor.

4.6(36)
57
ESP32 LED Control with Pushbutton (Toggle)
ES-3Cơ bản

ESP32 LED Control with Pushbutton (Toggle)

Each time the button is pressed the state of the LED changes: if it is on it turns off, if it is off it turns on. Classic toggle pattern. With debounce we clean up the mechanical noise of the pushbutton to ensure a single toggle with a single press.

4.6(39)
59
ESP32 Built-in LED Blink
ES-4Cơ bản

ESP32 Built-in LED Blink

Blinking the built-in blue LED on the ESP32 DevKit V1. No external components required! The first project you should try when you buy an ESP32. GPIO 2 is connected to the built-in LED.

4.8(29)
54
ESP32 Traffic Light
ES-5Cơ bản

ESP32 Traffic Light

Real traffic light simulation with 3 LEDs red-yellow-green. Timings close to real traffic logic: red long, yellow short, green long. Classic example of sequential GPIO control.

4.4(22)
45
ESP32 Knight Rider LED
ES-6Cơ bản

ESP32 Knight Rider LED

6 LEDs moving sequentially from left to right and right to left (Knight Rider style). A basic example of using for loops and arrays. Teaches the logic of direction change.

4.5(19)
33
ESP32 LED Fade with PWM
ES-8Cơ bản

ESP32 LED Fade with PWM

Smoothly changing the brightness of the LED from 0 to max, from max to 0. We control PWM with analogWrite() as in Arduino - the same syntax as ESP32 Arduino Core 3.0+ works without problems. Pin definition + pinMode + analogWrite is enough.

4.8(36)
55
ESP32 RGB LED Control
ES-9Cơ bản

ESP32 RGB LED Control

Unlimited color generation with a single RGB LED instead of 3 separate LEDs. As in Arduino, we make a rainbow transition by setting the R/G/B values with analogWrite(). Color theory (such as red+green=yellow) is seen practically.

4.6(29)
52

Dự án Raspberry Pi Pico10 dự án khối lệnh

Raspberry Pi Pico Onboard LED Blink (Pico and Pico W)
PI-1Cơ bản

Raspberry Pi Pico Onboard LED Blink (Pico and Pico W)

The opening project of the Raspberry Pi Pico series! We blink the Pico's green built-in LED to confirm the board works, the classic "Hello World" first experiment. No external parts needed, just the Pico and a USB cable. The code is written in MicroPython, the language officially supported by the Raspberry Pi Foundation.

5.0(1)
10
Raspberry Pi Pico: Controlling an External LED (Breadboard)
PI-2Cơ bản

Raspberry Pi Pico: Controlling an External LED (Breadboard)

The next step after the Pico's built-in LED: connect an external LED on a breadboard and control it through pin GP14. You'll learn how to use any of the Pico's GPIO pins as an output, the LED's polarity (long leg = anode/+, short leg = cathode/–) and why a current-limiting resistor (220Ω) is a must. Without the resistor, too much current flows through the LED and it can burn out.

4.5(2)
7
Raspberry Pi Pico Alternating Two LEDs (Blink-Flip Pattern)
PI-3Cơ bản

Raspberry Pi Pico Alternating Two LEDs (Blink-Flip Pattern)

The next step after the Pico's single LED: the classic flip-flop animation, with two LEDs blinking in turn. One LED turns off as the other turns on, the most basic example of handling multiple GPIOs. Two LEDs of different colors (red on GP14, green on GP13) swap every 500 ms. With MicroPython's Pin.toggle() method, the code stays short and readable.

5.0(2)
19
Raspberry Pi Pico Traffic Light Simulator (3 LEDs Sequential)
PI-4Cơ bản

Raspberry Pi Pico Traffic Light Simulator (3 LEDs Sequential)

We recreate real traffic light logic with red, yellow and green LEDs, the first Pico project to move up to 3 LEDs! Green says "go" for 4 seconds, yellow "get ready" for 1.5 seconds, red "stop" for 3 seconds, and red+yellow "set off" for 1 second (the European traffic light pattern). You'll learn to define functions (def all_off()), state machine logic and multi-GPIO synchronization.

4.0(1)
12
Raspberry Pi Pico Police Strobe Light Effect (Red + Blue)
PI-5Cơ bản

Raspberry Pi Pico Police Strobe Light Effect (Red + Blue)

We simulate a police car's light bar with a Raspberry Pi Pico in its simplest form! The red and blue LEDs take turns (flip-flop): while red is on, blue is off, and they swap every 0.3 seconds, forever. The code writes the two steps directly in a single while True loop; the speed is set with the WAIT_MS constant.

4.7(3)
10
Raspberry Pi Pico 3-Burst Police Flip-Flop (2 LEDs)
PI-6Cơ bản

Raspberry Pi Pico 3-Burst Police Flip-Flop (2 LEDs)

Rhythmic variation of the police strobe project — 3-burst flip-flop! Same 2-LED circuit (GP11 red + GP12 blue), but a different pattern: red LED flashes 3 times rapidly, then blue flashes 3 times, forever. This "burst + switch" pattern is the most recognizable rhythm of real police siren lights. Learn parametrized function def burst(led, count, duration_ms), rhythm design, and generating different visual effects with code on same circuit.

5.0(1)
16
Raspberry Pi Pico Button Toggle LED
PI-10Cơ bản

Raspberry Pi Pico Button Toggle LED

Button + LED — next level! Unlike the basic button project, there is no need to hold the button. Press and release → LED on. Press and release again → LED off (toggle). Same circuit (LED GP14, Button GP2), but big code difference. Learn edge detection (capturing the 1→0 falling moment), state tracking, debounce (mechanical bounce filter). MicroPython's led.toggle() swaps state in one line. Foundation of all interactive button projects (mode switcher, IRQ, double-click).

10
Raspberry Pi Pico PWM LED Fade (Breathing Effect)
PI-14Cơ bản

Raspberry Pi Pico PWM LED Fade (Breathing Effect)

The LED doesn't just blink anymore, it breathes! With the Raspberry Pi Pico's PWM (Pulse Width Modulation), the LED's brightness slowly rises and then slowly fades, a calm "breathing" effect like a sleeping laptop's light. You'll learn the machine.PWM class, the 16-bit brightness value from 0–65535 with duty_u16() and the PWM frequency.

4

Dành cho ai?

Trẻ em và phụ huynh

Lập trình cho trẻ em sẽ nhớ lâu hơn nhiều khi kết thúc bằng một chiếc LED sáng lên trên bàn. Khối lệnh giúp chương trình dễ đọc, và hai người cùng nhau lắp mạch.

Giáo viên và câu lạc bộ

Trong lớp robot hoặc STEM, bạn có thể giải thích dự án bằng khối lệnh trước rồi chuyển sang code. Mỗi dự án đều có sẵn danh sách linh kiện và sơ đồ mạch.

Người mới bắt đầu

Lập trình khối Arduino là cách nhanh nhất để nắm logic của vài dự án đầu tiên. Hãy bắt đầu bằng khối lệnh và chuyển sang code khi bạn thấy sẵn sàng.

Câu hỏi thường gặp

Lập trình dựa trên khối là gì?

Đó là cách lập trình mà các lệnh được hiển thị dưới dạng khối ghép lại như mảnh ghép thay vì văn bản gõ tay. Vì không thể gõ sai, người mới và trẻ em hiểu logic của chương trình dễ hơn.

Có bao nhiêu dự án BlueGrays có khối lệnh?

Hiện có 111: 76 dự án Arduino, 25 dự án ESP32 và 10 dự án Raspberry Pi Pico. Danh sách sẽ tăng dần khi có thêm dự án được chuyển đổi.

Lập trình khối có miễn phí không?

Ứng dụng miễn phí. Khối lệnh và code của 31 dự án khối lệnh mở cho mọi người. Ở các dự án khác, khối lệnh được mở khóa với Premium, giống như code.

Có thể nạp khối lệnh thẳng vào bo mạch không?

Không. Khối lệnh giúp chương trình dễ đọc và dễ hiểu hơn; thứ được nạp vào bo mạch luôn là code thật của dự án. Bạn sao chép code vào Arduino IDE, hoặc Thonny cho Pico, rồi nạp.

Tôi có thể tự tạo chương trình bằng khối lệnh không?

Chưa được. Chúng tôi chuẩn bị khối lệnh cho từng dự án và khớp chúng với code từng dòng một, nên khối lệnh bạn thấy luôn đại diện cho một chương trình đã được kiểm tra và chạy được.

Khác gì so với Scratch hay mBlock?

Trong Scratch và mBlock, bạn kéo thả khối trên máy tính để viết chương trình của riêng mình. Trong BlueGrays, mỗi dự án khối lệnh đi kèm sơ đồ mạch, danh sách linh kiện và code thật, còn khối lệnh là phiên bản dễ đọc của code đó. Hai cách này bổ sung cho nhau.

Có phù hợp với trẻ em không? Bao nhiêu tuổi thì bắt đầu được?

Trẻ khoảng 9 hoặc 10 tuổi đọc tốt có thể bắt đầu cùng người lớn. Các dự án đầu tiên không cần hàn: chúng được lắp trên breadboard với LED, nút nhấn và còi chip.

Khối lệnh có những ngôn ngữ nào?

Tiếng Anh, Thổ Nhĩ Kỳ, Đức, Tây Ban Nha, Pháp và Ý. Khối lệnh hiển thị theo ngôn ngữ bạn dùng trong ứng dụng.

Ứng dụng BlueGrays

Bắt đầu lập trình khối trên điện thoại

Khối lệnh, sơ đồ mạch, danh sách linh kiện và code thật trên một màn hình. Miễn phí trên iOS và Android.

Tải về trên App StoreTải trên Google Play

Trang nền tảng