Loading the figure…
Stopped · Your code isn't running yet. Until you press Run, the board runs the program already on it.
Nothing printed yet. Press Run.
Not checked yet
Run your code to check it. The checks replay a fixed script on a virtual clock, so the same code always gets the same result.
Each fault really happens in the simulation. Trigger one, watch the figure, then read why.
Play the world: press, slide and turn the parts while the code runs.
Change a value here or click a chip in the code.
Measure distance with an ultrasonic sensor and light LD2 when something comes close. The sensor runs at 5 V, and its ECHO pin goes straight into D8, one of the Nucleo's 5 V tolerant pins.
| Pin | Connects to | What it does |
|---|---|---|
5V | The sensor's VCC | The HC-SR04 needs 5 V. |
D7 | TRIG | Output: a 10 µs, 3.3 V pulse starts a measurement. |
D8 | ECHO | Input: a 5 V pulse, fine on this 5 V tolerant pin. |
GND | The sensor's GND | Common ground. |
Sensors and actuators this board drives, with the real connections.
VCC on 5V, TRIG on D7, ECHO on D8. D8 (PA9) is 5 V tolerant, so the 5 V echo needs no divider here.
| Part pin | Board pin |
|---|---|
| VCC | 5VWire colour red |
| TRIG | D7Wire colour yellow |
| ECHO | D8Wire colour green |
| GND | GNDWire colour black |
Take ECHO to a digital pin, never to an input you read with analogRead(): in analog mode a pin takes 4.0 V at most.