2

(sharon) #1

Make an infrared rangefinder with ESP8266


TUTORIAL


Learn to use I^2 C to add hardware to your microcontrollers


Make an infrared


rangefinder with ESP8266


ost robotics projects need to
measure distance for navigation,
but distance measurement is
also necessary for other projects
such as camera focusing and
surface level determination. In
this project an infrared laser rangefinder is used to
measure target distance, with the results shown
on an OLED display. The rangefinder and the OLED
display are available budget-priced, as adapter boards,
only requiring I^2 C signals and power. The heart of the
device is a NodeMCU embedded-computer board,
using the ESP8266 processor.
The VL53L0X infrared laser rangefinder is more
accurate and has a much smaller sensing element
than the popular ultrasonic rangefinder, the HR-SC04,
and is almost as cheap.
The ESP8266 is a very useful
processor and this project
provides a practical introduction
to using it. The NodeMCU board
is a great board to start with, as
it has all the ancillary components
and a USB interface to allow
it to be programmed straight
out of the box. The same
code and interface wiring can
be used in a final project based
on a raw ESP12E, for even lower
cost and power consumption.

ASSEMBLING
THE HARDWARE
The black and white 0.96”, 128 × 64
pixel, OLED display has graphics and text
capability. It connects to the host processor
via the I^2 C interface. Modules are available,
ready to plug into a breadboard.
The IR rangefinder VL53L0X sensor module,
from ST Microelectronics, is tiny, but several
suppliers provide breakout boards. It has a range of

1.5 metres, runs off 3.3 V and, like the OLED module,
connects via an I^2 C interface. The XSHUT terminal
can be used to put this module into low-power mode,
when measurements are not being taken.
The same I^2 C interface can be used for both
modules, minimising the GPIOs used, as they have
different addresses, 0x52 for the IR rangefinder and
0x3C for the OLED display.
The NodeMCU board is almost too wide for a
standard breadboard, but can easily be mounted
on two mini-breadboards to allow connection to
the modules, as shown in the photograph and
Figure 1 diagram.
The two modules are connected to the NodeMCU
via the I^2 C interface. To use this interface, connect
the two signal lines, SDA and CLK, power lines and
let the ESP8266 version of the wire.h library in the
Arduino IDE handle all the details.
The ESP8266 can be set up to use almost any pair
of GPIO pins to form an I^2 C bus. Here D3(GPIO0) is
used as the SDA line and D2(GPIO2) as the SCL line,
as these lines already have pull-up resistors fitted on
the NodeMCU.

CONNECTING EVERYTHING TOGETHER
All three modules are plugged into a breadboard and
wired up with links, as shown in Figure 1.
The NodeMCU already has pull-up resistors on
D3(GPIO0) and D2(GPIO2), so only wire links to the
OLED and IR rangefinder modules are required. The
XSHUT connection on the IR rangefinder module is
also shown connected to D5(GPIO14).
The NodeMCU provides the power for the display
and sensor modules via the +3.3 V connections,
enabling the whole circuit to be powered from the PC
over the USB or a USB battery pack.

SETTING UP THE ARDUINO IDE FOR USE
WITH ESP8266 BOARDS
The simplest way to program ESP8266 boards is via
the Arduino IDE. The core Arduino IDE package must

M


Bill Grainger


Bill Grainger is a
physicist and design
engineer who loves
coding and having
computers interact
with the real world. He
works with wind energy
on all scales and enjoys
running, sea kayaking,
and mountaineering.

Below
VL53LOX IR laser
rangefinder on
breakout board
Free download pdf