Device: Raspberry Pi 3 B+
Camera: Raspberry Pi Camera v2.1

I tried to use a Raspberry Pi to shoot a timelapse, to record the growth of my baby tangerine.

However, after checking the first pilot, the tangerine plant is pretty blurry, the camera was focusing on somewhere far away but not the plant, like the floor in the background is clear.

I don’t expect the camera to be smart enough to auto-focus on an object for the price that I paid, but I’m wondering if there’s anything that we can tweak to improve it.

## How to adjust Raspberry Pi Camera’s focus?

The standard Pi Camera is a fixed-focus lens, it’s not like a zoom lens. However, the lens base is like a screw in a nut. You can adjust the lens focus by tightening or loosening the lens base, amazing!

There are some posts talking about it. What surprises me is people are so smart that they can find the workaround, it doesn’t look like an official solution by design.

If you look closer at the double arrow, you can use a small tweezer to rotate it.

## How does it work?

To simplify the structure, here’s the sketch of the camera. The sensor is at the bottom, the lens is on top. When you rotate the lens base, the height is changed, which then changes the internal lens position so that it can focus on a different distance.

Now let’s see how different lens positions can change the focus position.

• v: the image distance, between sensor and lens
• u: the object distance, between lens and object

In the above two cases, when you tighten the lens base clockwise, v decreases, vice versa. When the lens base moves to the left, the focus point moves too, but in a different direction. So in my case, if I want to move the focus point from floor to my plant, I should actually increase v, to rotate the camera base out a little bit.

Why?

Let’s look at the Lens Formula:

$${1 \over v} + {1 \over u} = {1 \over f}$$

The f is the focal length, it’s a constant value that determined by the lens. So, the right side of the equation is a constant, if you increase v, 1/v becomes smaller, 1/u increases, then u actually drops. That means, v is in inverse proportion to u.

Back to the plant, if we want to move the focus point closer, decreasing u require us to increase v, so we need to rotate the lens base out. Voila!

## Tune It!

Let’s start the experiment.

To facilitate the tuning process, I’d suggest rotating it clockwise to the end (minimize the v), then rotate it back (anti-clockwise) gradually to increase v. For two reasons:

• If we start by rotating anti-clockwise, the lens base can pop out, it’s not easy to put it back
• Use the minimum v as a benchmark, keep each rotation step small, so that we won’t skip the best position

After each small rotation, take a photo to check what’s the current focus, you can use the following command.

Here’s what I tried:

Yay! The text on the keyboard becomes clear gradually after a few steps.

## Pay Attention

• Be gentle, don’t screw it too hard
• If you are using a tool like knife, be careful not to hurt yourself
• When you screw anti-clockwise, don’t rotate too far, the lens base will pop out, it’s not that easy to put it back
• Some people suggest to do it with the camera unplugged, well, I did it with it connected, so maybe it’s OK

Special thanks to Dr. Hu’s equation, that’s the basis of the experiment.