Maintaining Camera Focus with a Radar Module and an ESP32

See how an ESP32 microcontroller, radar module, and screen combine to make focusing older cameras an easier task.

Evan Rust
3 months agoSensors / Productivity / Photos & Video

Street photography

Whether it is macro, wildlife, landscape, or one of the many other genres of photography, all of them rely on a camera and its settings for light sensitivity, focus, and various other aspects. But few compare to the art of street photography and its requirement for capturing many fast-moving objects in a true-to-life manner. And as computer engineer Tom Schucker notes, maintaining the proper distance and focus is key to capturing the perfect scene. One challenge he often faced was trying to estimate the distance between his camera lens and subjects in the foreground in order to keep focus, and his solution is an ESP32-based project that range-finds and reports this value to the photographer for quick adjustments.

A first attempt

There is a large variety of sensors on the market that all attempt to find the distance to an object with differing levels of accuracy, resolution, and reliability. Schucker's first choice was the ubiquitous HC-SR04 ultrasonic module which emits high-frequency pulses of sound, waits for an echo, and allows the microcontroller to measure the time between the two to derive a meaningful value. However, a couple short experiments later revealed this component's range was far too short, so he started considering using radio waves instead.

Connecting a radar module

Radar units, unlike HC-SR04 ultrasonic distance sensors, send out pulses of high-frequency radio waves which reflect off surfaces and can be used to determine both the range and velocity of objects thanks to the Doppler effect. The lower-range model Schucker found works at a maximum range of up to 3.5 meters and can report located subjects in its field-of-view with 5cm accuracy. Even better, he was able to easily connect it to an ESP32 via UART and simply parse the data being streamed back.

Display and interface

Beyond the radar module itself, Schucker also needed a simple way to see the current distance so he could adjust the focus on the lens. The program he wrote instructs the ESP32 to initialize a TFT screen and the radar module before entering into an infinite loop that continuously reads new data from the UART port when available and parses it. Once the distance has been read, it is drawn onto the display for easy viewing.

Possible updates

In the future, Schucker plans on potentially swapping the radar module for lidar, as it can give increased precision and range. He also suggests that an autofocus add-on might be in the works which can automatically adjust the focus based on the distance. To read more, you can visit Schucker's project post here on his blog.

Evan Rust
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles