First Sensor App
By the end of this tutorial your device will show a live sensor reading on screen — updating in real time as you interact with the sensor.
What you’re building
Section titled “What you’re building”A UIFlow program that:
- Reads a value from an external sensor (temperature/humidity, or motion)
- Stores it in a variable
- Displays it on screen with a label
The program runs in a forever loop so the reading updates continuously.
Step 1 — Add the sensor as a Unit
Section titled “Step 1 — Add the sensor as a Unit”In UIFlow, external sensors are added as Units before you can use them in blocks.
How to add a Unit:
- Click the Units button in the left sidebar (looks like a plug icon)
- Click + Add Unit
- Find your sensor in the list and select it
- Click OK — UIFlow 2.0 detects the connection automatically
- The unit now appears in your block palette
ENV III measures temperature and humidity.
- In the Units list, select ENV III
- After adding, you’ll see ENV III blocks in the palette:
get temperature,get humidity,get pressure
Which value to display: Start with get temperature — it’s the most satisfying to demonstrate (breathe on the sensor and watch the number change).
M5Stack’s docs page for ENV III includes a short tutorial video: docs.m5stack.com → Units → ENV III
PIR detects motion — it outputs True when motion is detected, False when still.
- In the Units list, select PIR
- After adding, you’ll see a
PIR get stateblock
Note: PIR returns a boolean (True/False), not a number. You’ll display Motion detected! or No motion instead of a number.
M5Stack’s docs page for PIR includes a short tutorial video: docs.m5stack.com → Units → PIR
Step 2 — Read the sensor value in blocks
Section titled “Step 2 — Read the sensor value in blocks”Create the reading logic inside the loop section:
- Open the Blocks editor (not MicroPython)
- Find the loop section on the canvas — UIFlow 2 creates this automatically. Anything inside it repeats forever. If you see separate
SetupandLoopblocks, use theLoopblock. - Inside the loop, drag in Variables → Set [variable] to [value]
- Create a new variable called
sensorValue - Set
sensorValueto the sensor read block:- ENV III: drag
ENV III get temperatureinto the value slot - PIR: drag
PIR get stateinto the value slot
- ENV III: drag
- Add a Time → Wait block at the bottom of the loop: set it to 500 ms (0.5 seconds)
This loop will read the sensor twice per second and store the result.
Step 3 — Display the value on screen
Section titled “Step 3 — Display the value on screen”Add a Label widget to show the sensor reading:
- Switch to the UI tab (screen design view)
- Drag a Label widget onto the screen
- Give it a sensible default text like
--- - Note the label’s variable name (e.g.,
label0) — you’ll use this in blocks
Back in the Blocks editor, inside your forever loop (after the sensor read):
- Drag a Label → set text block
- Select
label0(or whatever your label is named) - Set the text to
sensorValue
For ENV III, you may want to add a unit string. Use a Text → join block to combine the number with " °C":
set label0 text to: join(sensorValue, " °C")Step 4 — Style the screen
Section titled “Step 4 — Style the screen”Make it look intentional:
- In the UI editor, click the screen background and pick a colour (dark blue works well)
- Click your label — find the font size control in the properties panel and increase it until the text is large and easy to read on the M5Stack screen
- Add a second label above it with the sensor name as static text (e.g.,
Temperature) - Set the static label to a smaller size and lighter colour
Step 5 — Run and test
Section titled “Step 5 — Run and test”Click the Run button (▶) in UIFlow.
ENV III: Breathe gently on the sensor — the temperature should tick up within a few seconds.
PIR: Wave your hand in front of the sensor — the display should change between True and False (or Motion detected! / No motion if you added a conditional).
Troubleshooting
Section titled “Troubleshooting”| Problem | Try this |
|---|---|
| Unit doesn’t appear in palette | Remove and re-add it via Units — make sure the sensor is physically connected before adding |
Screen shows --- and never updates | Check the forever loop is running — make sure you clicked Run |
| Temperature reads 0.0 | The cable may be loose — unplug and reconnect, then re-run |
| PIR always shows True | Cover the sensor with your hand briefly to reset it, then uncover |
| UIFlow disconnects mid-session | Reconnect via the device menu — your blocks are saved in the browser |
| Device freezes or crashes on startup | Both sensors are plugged in at once — unplug one, press the reset button on the side of the device, then reconnect |
Was this page helpful?