How to create a simple Focus Timer using Raspberry Pi Pico

How to create a simple Focus Timer using Raspberry Pi Pico

In this guide we will create a simple yet extremely useful focus timer using Raspberry Pi Pico development board.

You can use this timer to focus on tasks at hand. The technique also known as the Pomodoro Technique.

Focus timer demo
Code is licensed under the Open Source MIT License

What you need

  • Raspberry Pi Pico or compatible board with CircuitPython installed
  • LED strip (WS2812, also known as NeoPixel)
  • 1M Ohm Resistor
  • Jumper wires
  • USB cable to connect to the power source


Focus timer wiring

You can use any Raspberry Pi Pico board. For this guide we chose a Pimoroni Pico Lipo since it has a handy battery charger if we wanna make our timer mobile.

LED connection

  • Connect Pi Pico Ground and 3v3 to LED strip Ground and VIN
  • Connect GP16 to LED strip data in

Touch sensor

  • Connect our 1M Ohm resistor between GP15 and Ground
  • Connect a piece or wire to GP15, this will be our touch sensor which will control the timer


These libraries are licensed under the Open Source MIT License

Thats it, we can now code our awesome focus timer.

The code

Copy the following code in file on your development board. Be sure to check out the inline comments for the explanation.

import time, os, board
import neopixel, touchio
from rainbowio import colorwheel

OFF = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)

# Settings
pixels_count = 8
# How many LEDs on a strip to glow on each touch
pixels_increment = 1
# Brightness, max is 1, go nuts if you like
pixels_brightness = 0.1
# Each LED is a 5 minutes timer
timer_seconds = (60 * 5)
# See the color constants above, define a new color if you like
color = WHITE

# Initialise lights
pixel_pin = board.GP16
pixels = neopixel.NeoPixel(pixel_pin, pixels_count, brightness=pixels_brightness, auto_write=True)

# Initialise touch pin
touch_pin = touchio.TouchIn(board.GP15)

on_count = 0
prev_count = 0

# Helper to get rounded time monotonic
def time_monotonic():
    return round(time.monotonic())

# A cool rainbow effect, we will use this on startup and when the timer ends
def rainbow_cycle(wait, count):
    for color in range(count):
        for pixel in range(len(pixels)):  # pylint: disable=consider-using-enumerate
            pixel_index = (pixel * 256 // len(pixels)) + color * 5
            pixels[pixel] = colorwheel(pixel_index & 255)

# Glows or switches off the LEDs
def update_pixels():
    if on_count:
        for p in range(on_count):
            pixels[p] = color
rainbow_cycle(0.01, 80)
start_time = time_monotonic()

while True:
    prev_count = on_count
    now_time = time_monotonic()
    if touch_pin.value:
        # Detected a touch
        if on_count >= pixels_count:
            # Still less than 'pixels_count', increase the timer count
            on_count = 0
            # Cant go above 'pixels_count', reset to 0
            on_count += pixels_increment
        # Touch will always reset the start time
        start_time = time_monotonic()

    elapsed_min = now_time - start_time
    if elapsed_min >= timer_seconds and on_count:
        # Each tick (timer_seconds) will trigger this
        # Reduce 'pixels_increment' which will switch off 'pixels_increment' number of LEDs
        start_time = time_monotonic()
        on_count -= pixels_increment
        if on_count is 0:
            # A little show for you
            rainbow_cycle(0.01, 80)



Simply run or you can disconnect/connect your board which will automatically run your code.

On startup you would see a nice rainbow light show for few seconds. To set the timer, touch the wire connected on pin GP15, each touch should increment the timer.

Sit back and focus on the given task, once the timer ends it will again show a little rainbow to celebrate.

Download all files

A little celebration before you go. You can increase the brightness to 1 to see this effect on startup and when the timer ends.

Focus timer rainbow

If you have any questions or would like clarification on any of the steps, don't hesitate to leave a comment.

Hope you have learned something new today.