Kể từ ngày 13 tháng 6 năm 2023, Hành động trò chuyện không còn được dùng nữa. Để biết thêm thông tin, hãy xem phần Hành động trò chuyện ngừng hoạt động.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Giờ đây, khi bạn đã chạy Trợ lý trên thiết bị, đã đến lúc mở rộng Trợ lý bằng Hành động trên thiết bị. Thao tác trên thiết bị cho phép bạn điều khiển thiết bị của mình qua giọng nói.
Trong ví dụ này, bạn sẽ sử dụng Tích hợp hành động trên thiết bị để bật và tắt đèn.
Hãy làm theo hướng dẫn sau đây để lắp đặt một đèn LED trên Raffberry Pi 3 Model B. Ở bước sau, bạn sẽ sửa đổi mã mẫu để bật đèn LED bằng lệnh thoại.
Yêu cầu về phần cứng
Trước khi bắt đầu ví dụ này, bạn cần có các thành phần sau:
Bảng mạch khung
Một đèn LED
Điện trở nối tiếp
Hai dây của đấu nhảy, cả hai đều có đầu nối nam và nữ
Điện trở của điện trở phải được gắn với đèn LED cụ thể.
Để tìm giá trị chính xác, bạn có thể sử dụng máy tính trực tuyến (hoặc mua một bộ công cụ).
Kết nối các thành phần
Kết nối chân đầu ra GPIO BCM25 với một bên của điện trở nối tiếp. Lưu ý rằng đây là chân cắm vật lý 22 trên
Rassberry Pi 3.
Nối phía bên kia của điện trở với cực dương (dây dẫn dài hơn) của đèn LED.
Nối cực âm (dây dẫn ngắn hơn) của đèn LED với mặt đất.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003eThis guide explains how to extend Google Assistant on your device with Device Actions, enabling voice control for tasks like turning on/off a light using a built-in Device Action.\u003c/p\u003e\n"],["\u003cp\u003eYou will need a breadboard, LED, resistor, and jumper wires to connect an LED to your Raspberry Pi, enabling physical interaction with the Device Action.\u003c/p\u003e\n"],["\u003cp\u003eThe guide involves connecting an LED to a specific GPIO pin on the Raspberry Pi and registering device traits to control it via Google Assistant, even if you don't have an LED you can still set up a Device Action.\u003c/p\u003e\n"],["\u003cp\u003eWhile an LED and physical setup are recommended for practical demonstration, the core functionality of Device Actions can be explored through terminal output if you don't have an LED at the moment.\u003c/p\u003e\n"]]],[],null,["# Install Hardware (Optional)\n\n| **Warning:** The Google Assistant Library for Python is deprecated as of June 28th, 2019. Use the [Google Assistant Service](/assistant/sdk/guides/service/python) instead.\n\n\u003cbr /\u003e\n\nNow that you have the Assistant running on the device, it is time to extend it\nwith Device Actions. Device Actions allow you to control your device via voice.\nFor this example, you will be using a [Built-in Device Action](/assistant/sdk/device-actions-overview#built-in)\nto turn a light on and off.\n\nFollow these instructions to install an LED on the Raspberry Pi 3 Model B. In a\nlater step, you will modify the sample code to light the LED by voice command.\n| **Note:** Don't worry if you don't have an LED at the moment. You can still set up a Device Action and print some output to the terminal.\n\nHardware requirements\n---------------------\n\nBefore you begin this example, you'll need the following components:\n\n- A breadboard\n- An LED\n- A series resistor\n- Two jumper wires, both with a male and female connector\n\nThe electrical resistance of the resistor should be tied to the specific LED.\nTo find the correct value, you can use an online calculator (or purchase a [kit](https://www.adafruit.com/product/3227)).\n\nConnect the components\n----------------------\n\n| **Note:** You may want to disconnect power to the Raspberry Pi to avoid short circuits.\n\n1. Connect GPIO output pin [BCM25](https://pinout.xyz) to one side of a series resistor. Note that this is physical pin 22 on the Raspberry Pi 3.\n2. Connect the other side of the resistor to the anode side (longer lead) of the LED.\n3. Connect the cathode side (shorter lead) of the LED to ground.\n\nNext step\n---------\n\n[Register Traits](/assistant/sdk/guides/library/python/extend/register-device-traits)"]]