# CircuitPython-Powered 3-minute Nightlight

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/057/229/medium800/led_pixels_dark-nightlight.jpg?1530973847)

There are doorknobs with microcontrollers in them, so how about nightlights? We had houseguests, it was late, and I needed an extra nightlight in a hurry. I had all kinds of glowy things from Adafruit, but I didn't want to wire anything up. The RGB LED on a Gemma M0 was bright enough, and all I had to do was supply power. In one minute, I had a nightlight. Later I made it fancier.

# CircuitPython-Powered 3-minute Nightlight

## Nightlight Basic

![](https://cdn-learn.adafruit.com/assets/assets/000/057/227/medium800/led_pixels_IMG_1241.jpg?1530967871)

 **Note:** When I first wrote this guide, using CircuitPython 3.x, the RGB LED on the Gemma M0 would light up with a solid color when a program was running. That is no longer the case with more recent versions of CircuitPython. However, you can download and install CircuitPython 3.1.2 for the Gemma M0, and the program below will work and make a nightlight.

If you want to use the Gemma M0 for anything else, such as the [Nightlight Pro](https://learn.adafruit.com/circuitpython-powered-gemma-nightlight/nightlight-pro), use the latest version of CircuitPython for the Gemma M0, which you can find [here](https://circuitpython.org/board/gemma_m0/).

[CircuitPython 3.1.2 for the Adafruit Gemma M0](https://adafruit-circuit-python.s3.amazonaws.com/bin/gemma_m0/en_US/OLD/adafruit-circuitpython-gemma_m0-3.1.2.uf2)
When you plug in a Gemma M0 running CircuitPython 3.1.2, the DotStar RGB LED on the board pulses green if there's no `code.py` program to run. If there is a `code.py`, it shows a solid color.

Pulsing green was a little spooky for this nightlight, so I wrote a `code.py` to run forever:

```
while True:
    pass
```

That's it, that's the whole nightlight program -- the shortest project code you'll ever see! To use, just copy and save it as `code.py` on your `CIRCUITPY` drive.

Then I plugged it in to an AC adapter with a short USB cable, but if you only have a long one, you could&nbsp; bunch it up with a twist tie.

This simple nightlight was good enough for our houseguests, but let's make a nicer one. Onward!

# CircuitPython-Powered 3-minute Nightlight

## Nightlight Pro

![](https://cdn-learn.adafruit.com/assets/assets/000/057/226/medium800/led_pixels_gemma-nightlight.jpg?1530967351)

Here's the Pro version of the nightlight. Instead of being limited to the plain green color at one intensity, you can change the colors and brightness of the RGB LED using the capacitive touch pads on the Gemma M0.&nbsp; Pads&nbsp; **D0** and **D2** on one side lower and raise the brightness, and&nbsp; **D1** on the other side changes the color.&nbsp;You can tap the pads or hold them down. If you don't like the colors or the brightness range or steps in the program below, feel free to change them.

You need just one library, `adafruit_dotstar`. It's included in the Project Bundle you can download below.

Copy the program below, and save it as `code.py` on your `CIRCUITPY` drive.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Nightlight/gemma_nightlight/code.py

# CircuitPython-Powered 3-minute Nightlight

## Nightlight Pro Deluxe CPX

![](https://cdn-learn.adafruit.com/assets/assets/000/057/228/medium800/led_pixels_cpx-nightlight.jpg?1530973053)

If you have a Circuit Playground Express (CPX), here's an even fancier version of the nightlight program. It starts by lighting up two NeoPixels to be green. But you can change the number of NeoPixels, change their brightness, and change color, all via the touch pads. It also provides a brightness limit (`MAX_BRIGHTNESS`), because the larger NeoPixels on the CPX are much brighter, and might be too bright for your nightlight.

Download the Project Bundle below, extract **code.py** from it, and upload **code.py** to CIRCUITPY. All the libraries you need are already included in CircuitPython for the CPX.

The program will use the CPX's built-in light sensor to turn off the nightlight if the ambient light is strong enough. If it turns off, it will turn on the small red LED to let you know it's still working. But I found the turn-off feature needs to be calibrated per room,&nbsp; so in the program below, that feature is turned off initially. Change the `TURN_OFF` value as described in the comments to enable it.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Nightlight/cpx_nightlight/code.py


## Featured Products

### Adafruit GEMMA M0 - Miniature wearable electronic platform

[Adafruit GEMMA M0 - Miniature wearable electronic platform](https://www.adafruit.com/product/3501)
The **Adafruit Gemma M0** is a super small microcontroller board, with just enough built-in to create many simple projects. It may look small and cute: round, about the size of a quarter, with friendly alligator-clip sew pads. But do not be fooled! The Gemma M0 is incredibly...

In Stock
[Buy Now](https://www.adafruit.com/product/3501)
[Related Guides to the Product](https://learn.adafruit.com/products/3501/guides)
### USB cable - 6" A/MicroB

[USB cable - 6" A/MicroB](https://www.adafruit.com/product/898)
This here is your standard A-microB USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your NETduino, Arduino Leonardo, Raspberry Pi (among other things).  
  
Approximately 6.5" long from end to end, its a little more compact than our classic 3' long cable  
<br...></br...>

In Stock
[Buy Now](https://www.adafruit.com/product/898)
[Related Guides to the Product](https://learn.adafruit.com/products/898/guides)
### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

In Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)

## Related Guides

- [Adafruit Circuit Playground Express](https://learn.adafruit.com/adafruit-circuit-playground-express.md)
- [Adafruit LED Sequins](https://learn.adafruit.com/adafruit-led-sequins.md)
- [Scratch 3 Walkthrough and Demo](https://learn.adafruit.com/guide-to-scratch-3.md)
- [NeoPixel Spats with Gemma and MakeCode](https://learn.adafruit.com/neopixel-spats.md)
- [CircuitPython Sin Complicaciones para la Circuit Playground Express y la Bluefruit](https://learn.adafruit.com/circuitpython-sin-complicaciones-para-la-circuit-playground-express.md)
- [CircuitPython Snow Globe](https://learn.adafruit.com/circuitpython-snow-globe.md)
- [Cyberpunk Spikes](https://learn.adafruit.com/cyberpunk-spikes.md)
- [Using the Android CircuitPython Editor](https://learn.adafruit.com/using-the-android-circuitpython-editor.md)
- [Mu Keyboard Shortcut Cheat Sheets](https://learn.adafruit.com/mu-keyboard-shortcut-cheat-sheets.md)
- [Neopixel Jewel 10 Minute Necklace](https://learn.adafruit.com/10-minute-neopixel-necklace.md)
- [Hacking Ikea Lamps with Circuit Playground Express](https://learn.adafruit.com/hacking-ikea-lamps-with-circuit-playground-express.md)
- [Circuit Playground Express USB MIDI Controller and Synthesizer](https://learn.adafruit.com/cpx-midi-controller.md)
- [Mason Jar Snow Globe](https://learn.adafruit.com/snow-globe-makecode.md)
- [LED Harness Bra](https://learn.adafruit.com/neopixel-led-harness-bra.md)
- [Using DS18B20 Temperature Sensor with CircuitPython](https://learn.adafruit.com/using-ds18b20-temperature-sensor-with-circuitpython.md)
- [Edit CircuitPython Code on iOS with Runestone](https://learn.adafruit.com/editing-circuitpython-on-ios-with-runestone.md)
