Controller PS4/PS5 × EV3 × Pybricks

Interactive tutorialEV3

First time? Try the interactive tutorial in your browser first, then follow the steps below with your hub.

This page covers Pybricks v4 / EV3 MicroPython v2 only: how to set it up for the Controller PS4/PS5 on MINDSTORMS EV3, how to read every value, the commands it supports and examples. Use the switcher above to change product, host or software.

Setup

What you need

  • Sensor: Controller PS4/PS5 (EV3 edition, RJ12 plug).
  • Brick: LEGO MINDSTORMS EV3.
  • Software (pick one):
    • Pybricks v4: open code.pybricks.com in Chrome; the EV3 needs the Pybricks firmware first (the stable release now includes EV3 firmware, v4.1.1 as of 2026-10).
    • EV3 MicroPython v2.0: the official LEGO "EV3 MicroPython" microSD boot card + the "LEGO MINDSTORMS EV3 MicroPython" extension for VS Code. Pick this if you already use it.

Install the software

Pybricks v4

  1. Open code.pybricks.com in Chrome.
  2. Follow the website to switch the EV3 to Pybricks firmware. The stable code.pybricks.com now includes EV3 firmware (v4.1.1 as of 2026-10). The examples on this site were first bench-tested on v4.0.0b10; v4.1.1 uses the same code.
  3. To open an example: drag the .py file into the editor and press Run.

EV3 MicroPython v2.0

  1. Boot the EV3 from the official LEGO EV3 MicroPython microSD card.
  2. Install the "LEGO MINDSTORMS EV3 MicroPython" extension in VS Code.
  3. To open an example: paste the program into main.py and press F5 to download and run.

Make the software see the sensor

The beginner examples need no library; they read the sensor data directly:

  • Pybricks v4 uses LUMPDevice(Port.S1); sensor.read(mode) returns that mode's values.
  • EV3 MicroPython v2.0: always read with Ev3devSensor. For products that show up as an infrared sensor, do not use InfraredSensor: every mode change waits about 1.1 s, and buttons() / beacon() / keypad() raise errors or change the values.
  • Both can read modes that EV3-G and Classroom cannot, so examples marked "Pybricks / EV3 MicroPython / clev3r only" run here too.

Important

Do not switch modes often inside the main loop. The EV3 hardware adds a communication wait every time a sensor mode changes. Pick one mode for the task and keep it for the whole run.

Wiring

  1. Plug the sensor into EV3 port 1 with the cable (any of 14 works; use the same port as Port.S1Port.S4 in the program).
  2. Turn the EV3 on first, then plug in the sensor.
  3. Latch up, push the plug in gently.

Pair the gamepad (first use or new gamepad)

  1. Connect the receiver and turn the controller on. Do not hold the receiver's button while plugging it in (that enters flashing mode and the receiver does nothing; release the button, unplug and replug).
  2. First use: a receiver that remembers no gamepad opens a 30-second pairing window at power-on (green LED blinking fast). To change gamepads, or if the 30 seconds are over: press the receiver's button (Reset) once; it forgets the old gamepad and opens 30 seconds again.
  3. Within those 30 seconds put the gamepad in pairing mode until its light bar flashes fast: PS4 hold SHARE + PS; PS5 hold Create + PS.
  4. Once connected, the receiver remembers this gamepad and will not connect to anyone else's. From then on, just press the gamepad's PS button after power-on.
Receiver green LED Meaning
Blinking fast Waiting for a gamepad to pair
Steady on No gamepad connected (press the PS button to reconnect)
Off Gamepad connected

Tip

At a competition, pair at your own table so no other team's gamepad is in pairing mode during the 30 seconds. Paired the wrong one? Press Reset and pair again.

First test

  1. Open example 1 on this page and run it (F5 for the MicroPython version).
  2. If the number on the EV3 screen changes with what is in front of the sensor, everything is connected.

FAQ

  • Cannot find Pybricks firmware for the EV3? Use the stable code.pybricks.com (EV3 v4.1.1 built in since 2026-10); the old ev3dev-based Pybricks (microSD card) is a different system and does not apply here.
  • The number never changes? Unplug the sensor and plug it back in (the EV3 must be on first).
  • The program reacts unevenly? The main loop reads different modes in turn and waits at every switch. Use one mode only.
  • Error when importing a library? The library file must be imported into the same Pybricks project, and its file name must match the import name exactly.

Reading values

Code assumes port 1 and reads raw modes with LUMPDevice; EV3 MicroPython v2 works the same way.

D-pad dpad

D-pad
Range Meaning
0~15 bit up 1, right 2, down 4, left 8, added when pressed together (0~15)
from pybricks.iodevices import LUMPDevice
from pybricks.parameters import Port

sensor = LUMPDevice(Port.S1)   # sensor on port 1

dpad = sensor.read(0)[0]   # D-pad:0~15 bit
dpad = sensor.read(1)[0]   # D-pad:0~15 bit
w = sensor.read(3)[0]
dpad = w & 0x0F   # D-pad (bits 0~3)
dpad = sensor.read(4)[0]   # D-pad:0~15 bit

mode 0 · int8 · IR-PROX 1×int8; mode 1 · int8 · IR-SEEK [方向鍵, LX, 形狀鍵, LY, 肩鍵, RX, 功能鍵, RY]; mode 3 · int16 · 低 nibble;高 nibble = 形狀鍵;bit8 = 已連線(+256,#67 新增); mode 4 · int8 · IR-S-ALT [方向鍵, LX, 形狀鍵, LY] (locked mode: firmware and hosts will not change it)

shape buttons shapeKeys

shape buttons
Range Meaning
0~15 bit triangle 1, circle 2, cross 4, square 8, added when pressed together (0~15)
from pybricks.iodevices import LUMPDevice
from pybricks.parameters import Port

sensor = LUMPDevice(Port.S1)   # sensor on port 1

shapeKeys = sensor.read(1)[2]   # shape buttons:0~15 bit
w = sensor.read(3)[0]
shapeKeys = (w >> 4) & 0x0F   # shape buttons (bits 4~7)
shapeKeys = sensor.read(4)[2]   # shape buttons:0~15 bit

mode 1 · int8; mode 3 · int16 · 高 nibble(÷16 取整數再 mod 16); mode 4 · int8 (locked mode: firmware and hosts will not change it)

shoulder buttons shoulderKeys

shoulder buttons
Range Meaning
0~15 bit L2 1, R2 2, L1 4, R1 8, added when pressed together (0~15)
from pybricks.iodevices import LUMPDevice
from pybricks.parameters import Port

sensor = LUMPDevice(Port.S1)   # sensor on port 1

shoulderKeys = sensor.read(1)[4]   # shoulder buttons:0~15 bit

mode 1 · int8 (locked mode: firmware and hosts will not change it)

function buttons funcKeys

function buttons
Range Meaning
0~15 bit SELECT(SHARE) 1, L3 2, R3 4, START(OPTIONS) 8, added when pressed together (0~15)
from pybricks.iodevices import LUMPDevice
from pybricks.parameters import Port

sensor = LUMPDevice(Port.S1)   # sensor on port 1

funcKeys = sensor.read(1)[6]   # function buttons:0~15 bit

mode 1 · int8 (locked mode: firmware and hosts will not change it)

connected connected

Range Meaning
0~1 1 = gamepad connected and data seen within 300 ms, 0 = not connected (buttons 0, sticks centred while disconnected)
from pybricks.iodevices import LUMPDevice
from pybricks.parameters import Port

sensor = LUMPDevice(Port.S1)   # sensor on port 1

w = sensor.read(3)[0]
connected = (w >> 8) & 1   # connected (bit 8)

mode 3 · int16 · bit8(值 ≥ 256 = 已連線,#67 新增)

stick axis 1~4 stick

stick axis 1~4
Range Meaning
-100~+100 (EV3 mode 1, mode 2, mode 4 give a scaled value: 0~99 (50 = centre)) 10 LX, 11 LY, 12 RX, 13 RY: −100 to +100, 0 = centre, right/up positive; 0 when not connected
from pybricks.iodevices import LUMPDevice
from pybricks.parameters import Port

sensor = LUMPDevice(Port.S1)   # sensor on port 1

stick = sensor.read(1)[1::2]   # stick axis 1~4 (index 1, 3, 5, 7): 0~99 (50 = centre)
stick = sensor.read(2)[0:4]   # stick axis 1~4
stick = sensor.read(4)[1::2]   # stick axis 1~4 (index 1, 3): 0~99 (50 = centre)

mode 1 · int8 · LX;LY 在 index 3、RX 5、RY 7(與按鍵交錯);0~99,50 = 中間(未連線 50); mode 2 · int8 · IR-REMOTE [LX, LY, RX, RY] 0~99,50 = 中間; mode 4 · int8 · LX;LY 在 index 3(RX、RY 不在模式 4) (locked mode: firmware and hosts will not change it)

Not readable here:16 buttons, battery, L2 analog, R2 analog, system buttons, gamepad type. Use Arduino / mBlock / micro:bit for these.

Commands

The EV3 port is read-only, so this software cannot send commands: calibrate with the button on the sensor and change settings over Arduino I2C, mBlock or micro:bit.

Examples

Example 1: Button tester: see the number of every button

What this example does: Mode 1 sends 8 numbers at once: 4 button groups and 4 stick values. This example shows them all on the screen; press and push everything and you will know each value.

What you need:

  • Controller PS4 Bluetooth receiver (EV3 edition) + gamepad
  • EV3 brick

How to connect: Bluetooth receiver in port 1. The first time, pair the PS4/PS5 gamepad as described on the product page; afterwards pressing the PS button connects automatically.

Download the program (pick your software):

⬇ Pybricks v4 | ⬇ EV3 MicroPython v2.0

Pybricks v4 code
# ============================================================
# 掌控者 PS4/PS5 藍牙遙控接收器 EV3 新手範例 01:按鍵測試器:看看每個按鍵的數字
# 軟體:Pybricks v4(用 Chrome 打開 https://code.pybricks.com ,EV3 版目前是 Beta)
# 接法:掌控者 PS4插 1 號孔
# 這個範例會做什麼:模式 1 一次送出 8 個數字:4 組按鍵和 4 個搖桿值。這個範例把它們全部顯示在螢幕上,按按看、推推看,就知道每個按鍵是多少。
# ============================================================

from pybricks.hubs import EV3Brick
from pybricks.iodevices import LUMPDevice
from pybricks.parameters import Port, Color
from pybricks.tools import wait

ev3 = EV3Brick()
sensor = LUMPDevice(Port.S1)       # 掌控者 PS4插 1 號孔


def read_dpad1():
    # 方向鍵(上 1、右 2、下 4、左 8):0 ~ 15
    return sensor.read(1)[0]


def read_shape():
    # 形狀鍵(▲1、●2、✕4、■8):0 ~ 15
    return sensor.read(1)[2]


def read_shoulder():
    # 肩鍵(L2 1、R2 2、L1 4、R1 8):0 ~ 15
    return sensor.read(1)[4]


def read_func():
    # 功能鍵(SELECT 1、L3 2、R3 4、START 8):0 ~ 15
    return sensor.read(1)[6]


def read_lx():
    # 左搖桿左右:0 ~ 99,50=中間,往右變大
    return sensor.read(1)[1]


def read_ly():
    # 左搖桿上下:0 ~ 99,50=中間,往上變大
    return sensor.read(1)[3]


def read_rx():
    # 右搖桿左右:0 ~ 99,50=中間,往右變大
    return sensor.read(1)[5]


def read_ry():
    # 右搖桿上下:0 ~ 99,50=中間,往上變大
    return sensor.read(1)[7]


# ---------- 程式從這裡開始 ----------
# 清除螢幕
ev3.screen.clear()
# 一直重複
while True:
    # 方向鍵:上 1、右 2、下 4、左 8
    ev3.screen.draw_text(0, 0, "DPAD " + str(read_dpad1()) + "      ", Color.BLACK, Color.WHITE)
    # 形狀鍵:▲1、●2、✕4、■8
    ev3.screen.draw_text(0, 16, "SHAPE " + str(read_shape()) + "      ", Color.BLACK, Color.WHITE)
    # 肩鍵:L2 1、R2 2、L1 4、R1 8
    ev3.screen.draw_text(0, 32, "SHLD " + str(read_shoulder()) + "      ", Color.BLACK, Color.WHITE)
    # 功能鍵:SELECT 1、L3 2、R3 4、START 8
    ev3.screen.draw_text(0, 48, "FUNC " + str(read_func()) + "      ", Color.BLACK, Color.WHITE)
    # 左搖桿左右(50=中間)
    ev3.screen.draw_text(0, 64, "LX " + str(read_lx()) + "      ", Color.BLACK, Color.WHITE)
    # 左搖桿上下(50=中間)
    ev3.screen.draw_text(0, 80, "LY " + str(read_ly()) + "      ", Color.BLACK, Color.WHITE)
    # 右搖桿左右
    ev3.screen.draw_text(0, 96, "RX " + str(read_rx()) + "      ", Color.BLACK, Color.WHITE)
    # 右搖桿上下
    ev3.screen.draw_text(0, 112, "RY " + str(read_ry()) + "      ", Color.BLACK, Color.WHITE)
    # 等 0.1 秒
    wait(100)
EV3 MicroPython v2.0 code
#!/usr/bin/env pybricks-micropython
# ============================================================
# 掌控者 PS4/PS5 藍牙遙控接收器 EV3 新手範例 01:按鍵測試器:看看每個按鍵的數字
# 軟體:樂高官方 EV3 MicroPython v2.0(microSD 開機卡+VS Code「LEGO MINDSTORMS EV3 MicroPython」擴充套件)
# 接法:掌控者 PS4插 1 號孔
# 這個範例會做什麼:模式 1 一次送出 8 個數字:4 組按鍵和 4 個搖桿值。這個範例把它們全部顯示在螢幕上,按按看、推推看,就知道每個按鍵是多少。
# ============================================================

from pybricks.hubs import EV3Brick
from pybricks.iodevices import Ev3devSensor
from pybricks.parameters import Port, Color
from pybricks.tools import wait

ev3 = EV3Brick()
sensor = Ev3devSensor(Port.S1)     # 掌控者 PS4插 1 號孔


def read_dpad1():
    # 方向鍵(上 1、右 2、下 4、左 8):0 ~ 15
    return sensor.read('IR-SEEK')[0]


def read_shape():
    # 形狀鍵(▲1、●2、✕4、■8):0 ~ 15
    return sensor.read('IR-SEEK')[2]


def read_shoulder():
    # 肩鍵(L2 1、R2 2、L1 4、R1 8):0 ~ 15
    return sensor.read('IR-SEEK')[4]


def read_func():
    # 功能鍵(SELECT 1、L3 2、R3 4、START 8):0 ~ 15
    return sensor.read('IR-SEEK')[6]


def read_lx():
    # 左搖桿左右:0 ~ 99,50=中間,往右變大
    return sensor.read('IR-SEEK')[1]


def read_ly():
    # 左搖桿上下:0 ~ 99,50=中間,往上變大
    return sensor.read('IR-SEEK')[3]


def read_rx():
    # 右搖桿左右:0 ~ 99,50=中間,往右變大
    return sensor.read('IR-SEEK')[5]


def read_ry():
    # 右搖桿上下:0 ~ 99,50=中間,往上變大
    return sensor.read('IR-SEEK')[7]


# ---------- 程式從這裡開始 ----------
# 清除螢幕
ev3.screen.clear()
# 一直重複
while True:
    # 方向鍵:上 1、右 2、下 4、左 8
    ev3.screen.draw_text(0, 0, "DPAD " + str(read_dpad1()) + "      ", Color.BLACK, Color.WHITE)
    # 形狀鍵:▲1、●2、✕4、■8
    ev3.screen.draw_text(0, 16, "SHAPE " + str(read_shape()) + "      ", Color.BLACK, Color.WHITE)
    # 肩鍵:L2 1、R2 2、L1 4、R1 8
    ev3.screen.draw_text(0, 32, "SHLD " + str(read_shoulder()) + "      ", Color.BLACK, Color.WHITE)
    # 功能鍵:SELECT 1、L3 2、R3 4、START 8
    ev3.screen.draw_text(0, 48, "FUNC " + str(read_func()) + "      ", Color.BLACK, Color.WHITE)
    # 左搖桿左右(50=中間)
    ev3.screen.draw_text(0, 64, "LX " + str(read_lx()) + "      ", Color.BLACK, Color.WHITE)
    # 左搖桿上下(50=中間)
    ev3.screen.draw_text(0, 80, "LY " + str(read_ly()) + "      ", Color.BLACK, Color.WHITE)
    # 右搖桿左右
    ev3.screen.draw_text(0, 96, "RX " + str(read_rx()) + "      ", Color.BLACK, Color.WHITE)
    # 右搖桿上下
    ev3.screen.draw_text(0, 112, "RY " + str(read_ry()) + "      ", Color.BLACK, Color.WHITE)
    # 等 0.1 秒
    wait(100)

Step by step:

  1. Clear the screen
  2. Repeat forever
    • D-pad: up 1, right 2, down 4, left 8
    • Shape buttons: ▲1, ●2, ✕4, ■8
    • Shoulder buttons: L2 1, R2 2, L1 4, R1 8
    • Function buttons: SELECT 1, L3 2, R3 4, START 8
    • Left stick left/right (50 = centre)
    • Left stick up/down (50 = centre)
    • Right stick left/right
    • Right stick up/down
    • Wait 0.1 s

What you should see: With nothing pressed the buttons read 0 and the sticks 50. Pressing two buttons adds the numbers, for example up + right = 3.

FAQ:

  • The buttons do nothing? Run example 1 first to see if the numbers change. If not, the gamepad is not connected: power-cycle the gamepad, or turn the EV3 on before plugging in the receiver.
  • The robot keeps creeping after you release the stick? The stick centre is not always exactly 50: lower the × 2 in the program, or add a rule "treat 45~55 as 50".

Example 2: Drive with the D-pad

What this example does: Mode 0 reads only the D-pad: up = forward, down = backward, left/right = spin on the spot, release = stop.

What you need:

  • EV3 brick + Education base robot (left wheel on B, right wheel on C)
  • Controller PS4 Bluetooth receiver (EV3 edition) + gamepad

How to connect: Bluetooth receiver in port 1. The first time, pair the PS4/PS5 gamepad as described on the product page; afterwards pressing the PS button connects automatically.

Download the program (pick your software):

⬇ Pybricks v4 | ⬇ EV3 MicroPython v2.0

Pybricks v4 code
# ============================================================
# 掌控者 PS4/PS5 藍牙遙控接收器 EV3 新手範例 02:方向鍵開車
# 軟體:Pybricks v4(用 Chrome 打開 https://code.pybricks.com ,EV3 版目前是 Beta)
# 接法:掌控者 PS4插 1 號孔;左輪馬達接 B、右輪馬達接 C
# 這個範例會做什麼:用模式 0 只讀方向鍵,上前進、下後退、左右原地轉,放開就停。
# ============================================================

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.iodevices import LUMPDevice
from pybricks.parameters import Port
from pybricks.tools import wait

ev3 = EV3Brick()
sensor = LUMPDevice(Port.S1)       # 掌控者 PS4插 1 號孔
left_motor = Motor(Port.B)        # 左輪
right_motor = Motor(Port.C)       # 右輪


def read_dpad():
    # 方向鍵(上 1、右 2、下 4、左 8,同時按會相加):0 ~ 15
    return sensor.read(0)[0]


# ---------- 程式從這裡開始 ----------
# 一直重複
while True:
    # 如果方向鍵=1(上)
    if read_dpad() == 1:
        # 按上:前進
        left_motor.dc(50)
        right_motor.dc(50)
    # 否則,如果方向鍵=4(下)
    elif read_dpad() == 4:
        # 按下:後退
        left_motor.dc(-50)
        right_motor.dc(-50)
    # 否則,如果方向鍵=8(左)
    elif read_dpad() == 8:
        # 按左:原地左轉
        left_motor.dc(-30)
        right_motor.dc(30)
    # 否則,如果方向鍵=2(右)
    elif read_dpad() == 2:
        # 按右:原地右轉
        left_motor.dc(30)
        right_motor.dc(-30)
    else:
        # 都沒按:停車
        left_motor.brake()
        right_motor.brake()
EV3 MicroPython v2.0 code
#!/usr/bin/env pybricks-micropython
# ============================================================
# 掌控者 PS4/PS5 藍牙遙控接收器 EV3 新手範例 02:方向鍵開車
# 軟體:樂高官方 EV3 MicroPython v2.0(microSD 開機卡+VS Code「LEGO MINDSTORMS EV3 MicroPython」擴充套件)
# 接法:掌控者 PS4插 1 號孔;左輪馬達接 B、右輪馬達接 C
# 這個範例會做什麼:用模式 0 只讀方向鍵,上前進、下後退、左右原地轉,放開就停。
# ============================================================

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.iodevices import Ev3devSensor
from pybricks.parameters import Port
from pybricks.tools import wait

ev3 = EV3Brick()
sensor = Ev3devSensor(Port.S1)     # 掌控者 PS4插 1 號孔
left_motor = Motor(Port.B)        # 左輪
right_motor = Motor(Port.C)       # 右輪


def read_dpad():
    # 方向鍵(上 1、右 2、下 4、左 8,同時按會相加):0 ~ 15
    return sensor.read('IR-PROX')[0]


# ---------- 程式從這裡開始 ----------
# 一直重複
while True:
    # 如果方向鍵=1(上)
    if read_dpad() == 1:
        # 按上:前進
        left_motor.dc(50)
        right_motor.dc(50)
    # 否則,如果方向鍵=4(下)
    elif read_dpad() == 4:
        # 按下:後退
        left_motor.dc(-50)
        right_motor.dc(-50)
    # 否則,如果方向鍵=8(左)
    elif read_dpad() == 8:
        # 按左:原地左轉
        left_motor.dc(-30)
        right_motor.dc(30)
    # 否則,如果方向鍵=2(右)
    elif read_dpad() == 2:
        # 按右:原地右轉
        left_motor.dc(30)
        right_motor.dc(-30)
    else:
        # 都沒按:停車
        left_motor.brake()
        right_motor.brake()

Step by step:

  1. Repeat forever
    • If D-pad = 1 (up)
      • Up pressed: forward
      • Otherwise:
        • Otherwise, if D-pad = 4 (down)
          • Down pressed: backward
          • Otherwise:
            • Otherwise, if D-pad = 8 (left)
              • Left pressed: spin left
              • Otherwise:
                • Otherwise, if D-pad = 2 (right)
                  • Right pressed: spin right
                  • Otherwise:
                    • Nothing pressed: stop

What you should see: Hold a D-pad button and the robot moves; release it and the robot stops.

FAQ:

  • The buttons do nothing? Run example 1 first to see if the numbers change. If not, the gamepad is not connected: power-cycle the gamepad, or turn the EV3 on before plugging in the receiver.
  • The robot keeps creeping after you release the stick? The stick centre is not always exactly 50: lower the × 2 in the program, or add a rule "treat 45~55 as 50".

Example 3: Left stick controls one motor speed

What this example does: A stick reads 099 with 50 in the middle. Subtract 50 and multiply by 2 to get the -100+100 a motor wants: push further to go faster, push down to reverse.

What you need:

  • EV3 brick
  • One large motor on B
  • Controller PS4 Bluetooth receiver (EV3 edition) + gamepad

How to connect: Bluetooth receiver in port 1. The first time, pair the PS4/PS5 gamepad as described on the product page; afterwards pressing the PS button connects automatically.

Download the program (pick your software):

⬇ Pybricks v4 | ⬇ EV3 MicroPython v2.0

Pybricks v4 code
# ============================================================
# 掌控者 PS4/PS5 藍牙遙控接收器 EV3 新手範例 03:左搖桿控制一顆馬達的快慢
# 軟體:Pybricks v4(用 Chrome 打開 https://code.pybricks.com ,EV3 版目前是 Beta)
# 接法:掌控者 PS4插 1 號孔;馬達接 B
# 這個範例會做什麼:搖桿的數字是 0~99、中間 50。把它減 50 再乘 2,就變成馬達要的 -100~+100:推越多轉越快,往下推就倒轉。
# ============================================================

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.iodevices import LUMPDevice
from pybricks.parameters import Port, Color
from pybricks.tools import wait

ev3 = EV3Brick()
sensor = LUMPDevice(Port.S1)       # 掌控者 PS4插 1 號孔
motor_b = Motor(Port.B)             # B 埠馬達


def read_ly():
    # 左搖桿上下:0 ~ 99,50=中間,往上變大
    return sensor.read(1)[3]


# ---------- 程式從這裡開始 ----------
# 一直重複
while True:
    # 力量 power =(左搖桿上下 − 50)× 2
    power = (read_ly() - 50) * 2
    # B 馬達用 power 的力量轉
    motor_b.dc(power)
    # 螢幕顯示現在的力量
    ev3.screen.draw_text(0, 0, "POWER " + str(power) + "      ", Color.BLACK, Color.WHITE)
EV3 MicroPython v2.0 code
#!/usr/bin/env pybricks-micropython
# ============================================================
# 掌控者 PS4/PS5 藍牙遙控接收器 EV3 新手範例 03:左搖桿控制一顆馬達的快慢
# 軟體:樂高官方 EV3 MicroPython v2.0(microSD 開機卡+VS Code「LEGO MINDSTORMS EV3 MicroPython」擴充套件)
# 接法:掌控者 PS4插 1 號孔;馬達接 B
# 這個範例會做什麼:搖桿的數字是 0~99、中間 50。把它減 50 再乘 2,就變成馬達要的 -100~+100:推越多轉越快,往下推就倒轉。
# ============================================================

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.iodevices import Ev3devSensor
from pybricks.parameters import Port, Color
from pybricks.tools import wait

ev3 = EV3Brick()
sensor = Ev3devSensor(Port.S1)     # 掌控者 PS4插 1 號孔
motor_b = Motor(Port.B)             # B 埠馬達


def read_ly():
    # 左搖桿上下:0 ~ 99,50=中間,往上變大
    return sensor.read('IR-SEEK')[3]


# ---------- 程式從這裡開始 ----------
# 一直重複
while True:
    # 力量 power =(左搖桿上下 − 50)× 2
    power = (read_ly() - 50) * 2
    # B 馬達用 power 的力量轉
    motor_b.dc(power)
    # 螢幕顯示現在的力量
    ev3.screen.draw_text(0, 0, "POWER " + str(power) + "      ", Color.BLACK, Color.WHITE)

Step by step:

  1. Repeat forever
    • Power = (left stick up/down − 50) × 2
    • Motor B runs with power
    • Show the current power on screen

What you should see: Push the left stick up and motor B runs forward, faster the further you push; push down to reverse; release to stop, the screen shows about 0.

FAQ:

  • The buttons do nothing? Run example 1 first to see if the numbers change. If not, the gamepad is not connected: power-cycle the gamepad, or turn the EV3 on before plugging in the receiver.
  • The robot keeps creeping after you release the stick? The stick centre is not always exactly 50: lower the × 2 in the program, or add a rule "treat 45~55 as 50".

Example 4: Two-stick tank drive

What this example does: Left stick drives the left wheel, right stick drives the right wheel, like a tank: push both forward to go forward, one forward and one back to spin.

What you need:

  • EV3 brick + Education base robot (left wheel on B, right wheel on C)
  • Controller PS4 Bluetooth receiver (EV3 edition) + gamepad

How to connect: Bluetooth receiver in port 1. The first time, pair the PS4/PS5 gamepad as described on the product page; afterwards pressing the PS button connects automatically.

Download the program (pick your software):

⬇ Pybricks v4 | ⬇ EV3 MicroPython v2.0

Pybricks v4 code
# ============================================================
# 掌控者 PS4/PS5 藍牙遙控接收器 EV3 新手範例 04:雙搖桿坦克車
# 軟體:Pybricks v4(用 Chrome 打開 https://code.pybricks.com ,EV3 版目前是 Beta)
# 接法:掌控者 PS4插 1 號孔;左輪馬達接 B、右輪馬達接 C
# 這個範例會做什麼:左搖桿管左輪、右搖桿管右輪,跟開坦克一樣:兩個都往前推就前進,一前一後就原地轉。
# ============================================================

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.iodevices import LUMPDevice
from pybricks.parameters import Port
from pybricks.tools import wait

ev3 = EV3Brick()
sensor = LUMPDevice(Port.S1)       # 掌控者 PS4插 1 號孔
left_motor = Motor(Port.B)        # 左輪
right_motor = Motor(Port.C)       # 右輪


def read_ly():
    # 左搖桿上下:0 ~ 99,50=中間,往上變大
    return sensor.read(1)[3]


def read_ry():
    # 右搖桿上下:0 ~ 99,50=中間,往上變大
    return sensor.read(1)[7]


# ---------- 程式從這裡開始 ----------
# 一直重複
while True:
    # 左輪力量 =(左搖桿上下 − 50)× 2
    left = (read_ly() - 50) * 2
    # 右輪力量 =(右搖桿上下 − 50)× 2
    right = (read_ry() - 50) * 2
    # 兩輪各自用自己的力量轉
    left_motor.dc(left)
    right_motor.dc(right)
EV3 MicroPython v2.0 code
#!/usr/bin/env pybricks-micropython
# ============================================================
# 掌控者 PS4/PS5 藍牙遙控接收器 EV3 新手範例 04:雙搖桿坦克車
# 軟體:樂高官方 EV3 MicroPython v2.0(microSD 開機卡+VS Code「LEGO MINDSTORMS EV3 MicroPython」擴充套件)
# 接法:掌控者 PS4插 1 號孔;左輪馬達接 B、右輪馬達接 C
# 這個範例會做什麼:左搖桿管左輪、右搖桿管右輪,跟開坦克一樣:兩個都往前推就前進,一前一後就原地轉。
# ============================================================

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.iodevices import Ev3devSensor
from pybricks.parameters import Port
from pybricks.tools import wait

ev3 = EV3Brick()
sensor = Ev3devSensor(Port.S1)     # 掌控者 PS4插 1 號孔
left_motor = Motor(Port.B)        # 左輪
right_motor = Motor(Port.C)       # 右輪


def read_ly():
    # 左搖桿上下:0 ~ 99,50=中間,往上變大
    return sensor.read('IR-SEEK')[3]


def read_ry():
    # 右搖桿上下:0 ~ 99,50=中間,往上變大
    return sensor.read('IR-SEEK')[7]


# ---------- 程式從這裡開始 ----------
# 一直重複
while True:
    # 左輪力量 =(左搖桿上下 − 50)× 2
    left = (read_ly() - 50) * 2
    # 右輪力量 =(右搖桿上下 − 50)× 2
    right = (read_ry() - 50) * 2
    # 兩輪各自用自己的力量轉
    left_motor.dc(left)
    right_motor.dc(right)

Step by step:

  1. Repeat forever
    • Left wheel power = (left stick up/down − 50) × 2
    • Right wheel power = (right stick up/down − 50) × 2
    • Each wheel runs with its own power

What you should see: Push both sticks forward and the robot drives forward; left forward and right back and it spins right.

FAQ:

  • The buttons do nothing? Run example 1 first to see if the numbers change. If not, the gamepad is not connected: power-cycle the gamepad, or turn the EV3 on before plugging in the receiver.
  • The robot keeps creeping after you release the stick? The stick centre is not always exactly 50: lower the × 2 in the program, or add a rule "treat 45~55 as 50".

Example 5: ✕ to grab, ● to release: control a gripper

What this example does: Use the shape buttons to control a medium motor (gripper) on port A: ✕ closes, ● opens, nothing pressed stops.

What you need:

  • EV3 brick
  • Medium motor on A (built as a gripper)
  • Controller PS4 Bluetooth receiver (EV3 edition) + gamepad

How to connect: Bluetooth receiver in port 1. The first time, pair the PS4/PS5 gamepad as described on the product page; afterwards pressing the PS button connects automatically.

Download the program (pick your software):

⬇ Pybricks v4 | ⬇ EV3 MicroPython v2.0

Pybricks v4 code
# ============================================================
# 掌控者 PS4/PS5 藍牙遙控接收器 EV3 新手範例 05:✕ 夾、● 放:控制夾爪
# 軟體:Pybricks v4(用 Chrome 打開 https://code.pybricks.com ,EV3 版目前是 Beta)
# 接法:掌控者 PS4插 1 號孔;馬達接 A
# 這個範例會做什麼:用形狀鍵控制接在 A 埠的中馬達(夾爪):按 ✕ 夾緊、按 ● 放開,都不按就停。
# ============================================================

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.iodevices import LUMPDevice
from pybricks.parameters import Port
from pybricks.tools import wait

ev3 = EV3Brick()
sensor = LUMPDevice(Port.S1)       # 掌控者 PS4插 1 號孔
motor_a = Motor(Port.A)             # A 埠馬達


def read_shape():
    # 形狀鍵(▲1、●2、✕4、■8):0 ~ 15
    return sensor.read(1)[2]


# ---------- 程式從這裡開始 ----------
# 一直重複
while True:
    # 如果形狀鍵=4(✕)
    if read_shape() == 4:
        # 按 ✕:夾爪往夾緊的方向轉
        motor_a.dc(40)
    # 否則,如果形狀鍵=2(●)
    elif read_shape() == 2:
        # 按 ●:夾爪往放開的方向轉
        motor_a.dc(-40)
    else:
        # 都沒按:夾爪停住
        motor_a.brake()
EV3 MicroPython v2.0 code
#!/usr/bin/env pybricks-micropython
# ============================================================
# 掌控者 PS4/PS5 藍牙遙控接收器 EV3 新手範例 05:✕ 夾、● 放:控制夾爪
# 軟體:樂高官方 EV3 MicroPython v2.0(microSD 開機卡+VS Code「LEGO MINDSTORMS EV3 MicroPython」擴充套件)
# 接法:掌控者 PS4插 1 號孔;馬達接 A
# 這個範例會做什麼:用形狀鍵控制接在 A 埠的中馬達(夾爪):按 ✕ 夾緊、按 ● 放開,都不按就停。
# ============================================================

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.iodevices import Ev3devSensor
from pybricks.parameters import Port
from pybricks.tools import wait

ev3 = EV3Brick()
sensor = Ev3devSensor(Port.S1)     # 掌控者 PS4插 1 號孔
motor_a = Motor(Port.A)             # A 埠馬達


def read_shape():
    # 形狀鍵(▲1、●2、✕4、■8):0 ~ 15
    return sensor.read('IR-SEEK')[2]


# ---------- 程式從這裡開始 ----------
# 一直重複
while True:
    # 如果形狀鍵=4(✕)
    if read_shape() == 4:
        # 按 ✕:夾爪往夾緊的方向轉
        motor_a.dc(40)
    # 否則,如果形狀鍵=2(●)
    elif read_shape() == 2:
        # 按 ●:夾爪往放開的方向轉
        motor_a.dc(-40)
    else:
        # 都沒按:夾爪停住
        motor_a.brake()

Step by step:

  1. Repeat forever
    • If shape buttons = 4 (✕)
      • ✕ pressed: gripper turns to close
      • Otherwise:
        • Otherwise, if shape buttons = 2 (●)
          • ● pressed: gripper turns to open
          • Otherwise:
            • Nothing pressed: gripper stops

What you should see: Hold ✕ and the gripper closes, hold ● and it opens, release and it stops.

FAQ:

  • Close and open are swapped? Swap 40 and -40.
  • The buttons do nothing? Run example 1 first to see if the numbers change. If not, the gamepad is not connected: power-cycle the gamepad, or turn the EV3 on before plugging in the receiver.
  • The robot keeps creeping after you release the stick? The stick centre is not always exactly 50: lower the × 2 in the program, or add a rule "treat 45~55 as 50".

Example 6: Start only when the gamepad is connected

Pybricks v4 / EV3 MicroPython v2.0 / clev3r only (the EV3-G and Classroom blocks cannot read this mode)

What this example does: Before the gamepad connects, the sticks read centre and the buttons 0, so a program cannot tell "nothing pressed" from "not connected". The mode 3 value includes "connected": 256 or more means the gamepad is connected. This example waits for the connection, beeps and starts; then D-pad up (256 + 1) drives forward, down (256 + 4) backward, and it stops at once if the gamepad disconnects.

What you need:

  • EV3 brick + Education base robot (left wheel on B, right wheel on C)
  • Controller PS4 Bluetooth receiver (EV3 edition, firmware v4.0 or later) + gamepad

How to connect: Bluetooth receiver in port 1. Leave the gamepad off until the program is running, so you can watch "waiting → connected".

Download the program (pick your software):

⬇ Pybricks v4 | ⬇ EV3 MicroPython v2.0

(The code is the example; no screenshot needed.)

Pybricks v4 code
# ============================================================
# 掌控者 PS4/PS5 藍牙遙控接收器 EV3 新手範例 06:手把連上才出發
# 軟體:Pybricks v4(用 Chrome 打開 https://code.pybricks.com ,EV3 版目前是 Beta)
# 接法:掌控者 PS4插 1 號孔;左輪馬達接 B、右輪馬達接 C
# 這個範例會做什麼:手把還沒連上時搖桿是中間、按鍵是 0,程式分不出「沒按」和「沒連上」。模式 3 的數字加了「已連線」:大於等於 256 就是手把連上了。這個範例等手把連上才嗶一聲出發,之後用方向鍵上(256+1)前進、下(256+4)後退,手把斷線就馬上停車。
# ============================================================

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.iodevices import LUMPDevice
from pybricks.parameters import Port, Color
from pybricks.tools import wait

ev3 = EV3Brick()
sensor = LUMPDevice(Port.S1)       # 掌控者 PS4插 1 號孔
left_motor = Motor(Port.B)        # 左輪
right_motor = Motor(Port.C)       # 右輪


def read_status3():
    # 方向鍵+形狀鍵+連線狀態:0 ~ 511:方向鍵(0~15)+ 形狀鍵 × 16 + 已連線 × 256,大於等於 256=手把已連上
    return sensor.read(3)[0]


# ---------- 程式從這裡開始 ----------
# 清除螢幕
ev3.screen.clear()
# 螢幕顯示 WAIT PAD:等手把
ev3.screen.draw_text(0, 0, "WAIT PAD      ", Color.BLACK, Color.WHITE)
# 等到狀態值大於等於 256(手把已連上)
while not (read_status3() >= 256):
    wait(10)
# 連上了:嗶一聲
ev3.speaker.beep()
# 一直重複
while True:
    # 第 2 行顯示狀態值
    ev3.screen.draw_text(0, 16, "STATUS " + str(read_status3()) + "      ", Color.BLACK, Color.WHITE)
    # 如果狀態值小於 256(手把斷線了)
    if read_status3() < 256:
        # 手把斷線:馬上停車
        left_motor.brake()
        right_motor.brake()
        # 螢幕顯示 PAD LOST
        ev3.screen.draw_text(0, 0, "PAD LOST      ", Color.BLACK, Color.WHITE)
    else:
        # 螢幕顯示 PAD OK
        ev3.screen.draw_text(0, 0, "PAD OK      ", Color.BLACK, Color.WHITE)
        # 如果狀態值=257(已連上+方向鍵上)
        if read_status3() == 257:
            # 已連上+方向鍵上(256+1):前進
            left_motor.dc(40)
            right_motor.dc(40)
        # 否則,如果狀態值=260(已連上+方向鍵下)
        elif read_status3() == 260:
            # 已連上+方向鍵下(256+4):後退
            left_motor.dc(-40)
            right_motor.dc(-40)
        else:
            # 連上但沒按:停車
            left_motor.brake()
            right_motor.brake()
EV3 MicroPython v2.0 code
#!/usr/bin/env pybricks-micropython
# ============================================================
# 掌控者 PS4/PS5 藍牙遙控接收器 EV3 新手範例 06:手把連上才出發
# 軟體:樂高官方 EV3 MicroPython v2.0(microSD 開機卡+VS Code「LEGO MINDSTORMS EV3 MicroPython」擴充套件)
# 接法:掌控者 PS4插 1 號孔;左輪馬達接 B、右輪馬達接 C
# 這個範例會做什麼:手把還沒連上時搖桿是中間、按鍵是 0,程式分不出「沒按」和「沒連上」。模式 3 的數字加了「已連線」:大於等於 256 就是手把連上了。這個範例等手把連上才嗶一聲出發,之後用方向鍵上(256+1)前進、下(256+4)後退,手把斷線就馬上停車。
# ============================================================

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.iodevices import Ev3devSensor
from pybricks.parameters import Port, Color
from pybricks.tools import wait

ev3 = EV3Brick()
sensor = Ev3devSensor(Port.S1)     # 掌控者 PS4插 1 號孔
left_motor = Motor(Port.B)        # 左輪
right_motor = Motor(Port.C)       # 右輪


def read_status3():
    # 方向鍵+形狀鍵+連線狀態:0 ~ 511:方向鍵(0~15)+ 形狀鍵 × 16 + 已連線 × 256,大於等於 256=手把已連上
    return sensor.read('IR-REM-A')[0]


# ---------- 程式從這裡開始 ----------
# 清除螢幕
ev3.screen.clear()
# 螢幕顯示 WAIT PAD:等手把
ev3.screen.draw_text(0, 0, "WAIT PAD      ", Color.BLACK, Color.WHITE)
# 等到狀態值大於等於 256(手把已連上)
while not (read_status3() >= 256):
    wait(10)
# 連上了:嗶一聲
ev3.speaker.beep()
# 一直重複
while True:
    # 第 2 行顯示狀態值
    ev3.screen.draw_text(0, 16, "STATUS " + str(read_status3()) + "      ", Color.BLACK, Color.WHITE)
    # 如果狀態值小於 256(手把斷線了)
    if read_status3() < 256:
        # 手把斷線:馬上停車
        left_motor.brake()
        right_motor.brake()
        # 螢幕顯示 PAD LOST
        ev3.screen.draw_text(0, 0, "PAD LOST      ", Color.BLACK, Color.WHITE)
    else:
        # 螢幕顯示 PAD OK
        ev3.screen.draw_text(0, 0, "PAD OK      ", Color.BLACK, Color.WHITE)
        # 如果狀態值=257(已連上+方向鍵上)
        if read_status3() == 257:
            # 已連上+方向鍵上(256+1):前進
            left_motor.dc(40)
            right_motor.dc(40)
        # 否則,如果狀態值=260(已連上+方向鍵下)
        elif read_status3() == 260:
            # 已連上+方向鍵下(256+4):後退
            left_motor.dc(-40)
            right_motor.dc(-40)
        else:
            # 連上但沒按:停車
            left_motor.brake()
            right_motor.brake()

Step by step:

  1. Clear the screen
  2. Show WAIT PAD: waiting for the gamepad
  3. Wait until the status value is 256 or more (gamepad connected)
  4. Connected: beep
  5. Repeat forever
    • Row 2 shows the status value
    • If the status value is less than 256 (gamepad disconnected)
      • Gamepad lost: stop at once
      • Show PAD LOST
      • Otherwise:
        • Show PAD OK
        • If the status value = 257 (connected + D-pad up)
          • Connected + D-pad up (256 + 1): forward
          • Otherwise:
            • Otherwise, if the status value = 260 (connected + D-pad down)
              • Connected + D-pad down (256 + 4): backward
              • Otherwise:
                • Connected but nothing pressed: stop

What you should see: The program first shows WAIT PAD with a value below 256; turn the gamepad on and the EV3 beeps, shows PAD OK and the value becomes 256. Hold D-pad up to drive forward (257), down to reverse (260); switch the gamepad off and the robot stops at once and shows PAD LOST.

FAQ:

  • Pressing up does not give 257? A shape button pressed at the same time adds more (shape × 16), for example up + ✕ = 256 + 1 + 64 = 321. Release the other buttons first.
  • The buttons do nothing? Run example 1 first to see if the numbers change. If not, the gamepad is not connected: power-cycle the gamepad, or turn the EV3 on before plugging in the receiver.
  • The number stays at 0 or never changes? This mode needs sensor firmware v4.0 (2026-10) or later; update older firmware first.
  • Why is there no EV3-G / Classroom version? This example uses a new mode (firmware v4, 2026-10). The EV3-G and Classroom infrared blocks cannot read it; only Pybricks, EV3 MicroPython and clev3r can.

Still stuck? Leave a message on Contact us with the software you use and a screenshot of your program, and we will help.

More questions

  • The EV3 shows an infrared sensor? Expected: the sensor emulates a LEGO sensor so the stock blocks can read it.
  • A short freeze when switching modes? The EV3 needs about 1 s per mode change. Stick to one mode during a run.

Still stuck? Contact us with your software and a screenshot of the program.

Downloads

Sources

  • Host and software list:_build/guides.json
  • Values and commands:_build/protocol/ps4.json (single source of truth)
  • Setup:_build/guides/software/ev3-pybricks.en.md、_build/guides/product/ps4/ev3-pybricks.en.md
  • Examples:sensors/ps4/ev3-examples.md
Email for a quoteBuying Guide