# pulseIn\(\) makes the robot slow: set a timeout and avoid waiting

> Fix a robot that freezes when a sensor is missing: pulseIn waits up to a second by default, so pass a short timeout.

Canonical: https://roboticsengineering.in/fix/arduino-pulsein-blocks-robot-timeout-slow-loop/ | Published: 2026-11-03 | Updated: 2026-11-03

**Give pulseIn() a timeout.** Without one it can wait a full second for a pulse that never comes.

## What the message means

The function blocks until the pulse ends. With no echo, the whole sketch stops for the timeout, and the robot drives blind.

## Fix it in this order

1. Pass a timeout in microseconds as the third argument, for example 25000 for about 4 m of range.
2. Treat a return of 0 as no reading and keep the last good value.
3. Read sensors in turns and not all in one pass.
4. Use interrupts or a library that measures in the background where you need speed.
5. Check the wiring if the timeout keeps happening.

## Why it happens

pulseIn waits for the pulse to start and finish, and its default timeout is one second. With no echo, such as an ultrasonic sensor facing open space, the whole sketch stops for that second each time, and a robot can travel some distance in that time. Sound travels about 343 m/s, so a round trip of 25 000 µs corresponds to roughly 4 m, which is why that value suits a typical ultrasonic sensor.

A return value of 0 means the timeout expired. Keep the last good reading instead of treating 0 as a distance of zero.

## If you see this, do this

| You see | Do this |
| --- | --- |
| Robot pauses when nothing is in front | No timeout set. |
| Always times out | Wiring or supply. |

## Related

[HC-SR04 reads 0](https://roboticsengineering.in/fix/hc-sr04-reads-zero-or-random-values/), [delay and millis](https://roboticsengineering.in/fix/arduino-delay-blocks-robot-use-millis/).

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.
