Here's a simple, fun project for sunny days, or dark rooms. We'll take a Circuit Playground Express and a micro servo and make a pair of automatic sunglasses/flashlight.

If you haven't used servos before we have some guides that will provide a good introduction: Using Servos With CircuitPython and Arduino, and the servo section of the Adafruit Motor Selection Guide.


A Black woman's manicured hand holds a round microcontroller with lit up LEDs.
Circuit Playground Express is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and...
Out of Stock
Micro servo with three pin cable
Tiny little servo can rotate approximately 180 degrees (90 in each direction) and works just like the standard kinds you're used to but smaller. You can use any servo...
In Stock
Angled shot of a Lithium Ion Polymer Battery 3.7V 500mAh with JST-PH connector.
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This...
Out of Stock
Group of Small Alligator Clip to Male Jumper Wires
When working with unusual non-header-friendly surfaces, these handy cables will be your best friends! No longer will you have long, cumbersome strands of alligator clips. These...
In Stock


  • A pair of glasses, an old/cheap pair preferrably.
  • Flip up sunglasses, or a cheap pair with the arms removed. 
  • Hot glue and glue gun
  • Superglue
  • Depending on how you want to wire the servo, you'll need soldering equipment or alligator clip jumper wires.

The wiring for this project is simple. that's one of the great things about using a Circuit Playground Express: there's so much already on the board. Need a light sensor? It's there. Need some bright LEDs. That too. Need to control a servo, just hook up the battery and a microservo.

Here's what we're going for.


Views with the shades up (normal light) and down (bright light).

This design lifts the shades up and out of the way by using 90 degrees of servo motion. The design needs the shades to clear the body of the servo when they are lifted up, but the standard horns aren't long enough to to this. To address this we can superglue two horns together.

To provide a more solid gluing surface, a notch can be cut into the bridge of the shades. This depends on what you use for the shades. In the case of a cheap pair of thick-framed swag sunglasses, there is plenty of space for a notch.  This provides more area for the hot glue to stick to.

You need to mount the servo onto the top of the glasses frame. There are so many shapes and sizes that no universal instructions can apply. You will have to figure out how to attach the servo to the particular frames you have. In this case, the frames were metal and thin enough to slide into the slot in the servo's mounting bracket. Once more, hot glue does the job.

Now the Circuit Playground Express needs to be mounted. This can be done, you guessed it, by hot gluing it to the back of the servo. The 500mAh LiPo fits onto the back with a bit of double-sided tape.

Now connect the servo. As shown in the photos, alligator clip to male header jumpers can be used to quickly and non destructively hook it up. For a tidier and more permanent installation the servo wires can be clipped, stripped, and soldered to the Circuit Playground Express pads.

We can write the code for this project using MakeCode! If you aren't already familiar with MakeCode, check out this guide to get started, then return here when you're ready.

On start, turn off the Neopixels and put the shades up. In the forever block the light level is checked and the Neopixels are turned on if it's dark enough, or the shades put down if it's bright enough. If it's in between, the lights are turned off and the shades put up.

We'll be using CircuitPython as an alternative language for this project. Are you new to using CircuitPython? No worries, there is a full getting started guide here.

Adafruit suggests using the Mu editor to edit your code and have an interactive REPL in CircuitPython. You can learn about Mu and its installation in this tutorial.

When the code starts it turns off the Neopixels and puts up the shades. Then it continually checks the light level and turns on the Neopixels if it's dark enough, or puts down the shades if it's bright enough. If neither is the case, it turns off the lights and puts up the shades.

# SPDX-FileCopyrightText: 2018 Dave Astels for Adafruit Industries
# SPDX-License-Identifier: MIT

Circuit Playground Express auto-sunglasses/flashlight

Adafruit invests time and resources providing this open source code.
Please support Adafruit and open source hardware by purchasing
products from Adafruit!

Written by Dave Astels for Adafruit Industries
Copyright (c) 2018 Adafruit Industries
Licensed under the MIT license.

All text above must be included in any redistribution.

import time
import board
import pwmio
from import cpx
from adafruit_motor import servo

pwm = pwmio.PWMOut(board.A1, duty_cycle=2 ** 15, frequency=50)
my_servo = servo.Servo(pwm)

cpx.pixels.fill((0, 0, 0))
my_servo.angle = 90

while True:
    light_level = cpx.light

    if light_level < 10:
        cpx.pixels.fill((200, 200, 200))
        cpx.pixels.fill((0, 0, 0))
        if light_level < 200:
            my_servo.angle = 90
            my_servo.angle = 0


The result isn't the prettiest, but not bad for using glasses that were languishing forgotten in the back of a drawer. Given time and searching, a nicer looking result could be achieved.

The concept could would also serve nicely as the basis for some steampunk articulated sun/welding goggles.  

This guide was first published on Aug 15, 2018. It was last updated on Aug 15, 2018.