Project 11 XGO Listens to Sounds
Ⅰ. Teaching Aims
Read the on-board microphone
sound level(0-100, refresh approximately each 20 ms).Use single/double threshold(s) to enable XGO to switch emojis or actions based on the sound volume.
Build a simple “rest when quiet / forage when noisy” model.
Ⅱ. Pre-class Check
XGO + Foxbit + MicroBlocks IDE.
XGO battery power ≥ 60 %. Place the robot on a flat ground.
MicroBlocks status bar shows a green dot, XGO-lite extension is loaded and the development board model is Foxbit.
The background noise in the classroom should be maintained at 5 - 15 to avoid continuous high noise from the outside.
Ⅲ. Key Blocks Analysis
|
|
|---|---|
Functions |
Return 0 – 100 ambient volume |
Fallible points |
Forgot to put it in |
|
|
Functions |
Perform actions based on the threshold |
Fallible points |
Too small threshold interval → jitter |
|
|
Functions |
Stand up, sit down, slide, etc |
Fallible points |
Volume jitter causes repeated actions |
|
|
Functions |
Emojis on LED dot matrix |
Fallible points |
Not added |
|
|
Functions |
Eliminate jitter / delay |
Fallible points |
It’s too short to display stably |
Reference value of sound level:
Scenes |
Typical readings |
|---|---|
Quiet classroom |
5 – 15 |
Normal speaking environment |
20 – 35 |
A round of handclap |
45 – 60 |
Loud shouting |
70 – 90 |
Ⅳ. Practice
Test 1: “Sound Volume → Emoji”

Logic:
Volume > 50 →
yesfor 0.5 sOtherwise,
no
Online code: Click here
Test 2: “Rest When Quiet / Forage When Noisy”

Logic
Volume > 50 →
Hunt for food+happy, for 2 sOtherwise, slightly squat down:
slide body Z by 10 mm+sad
Online code: Click here
Ⅴ. Quiz
What would happen if we changed
wait 500in Test 1 to 50 ms?Why does Test 2 use the
modevariable instead of simplyif…else?If you want the volume to be louder and the steps to be wider, how should you use
map()? Please write down the parameters.
Ⅵ. FAQ
Questions |
Possible causes |
Solutions |
|---|---|---|
Emoji flashes |
The volume jitter near the threshold |
Increase the threshold interval; |
Repeated actions |
There are no state variables. |
Import |
Sluggish switching between rest and foraging |
The background noise is high, or the threshold is too far |
Adjust the threshold; Perform the moving average |
The microphone reading is always high |
The sensor is affected by wind noise, or apply a film |
Block the wind; Make sure the microphone hole is exposed |
Large sliding amplitude |
|
Maintain within ± 15 mm |





