Kid Wake Up Light

Wake Up Light

Idea

My son has this new habit of getting up at 04:00 and wandering into the living room alone. He gets scared and confused because he doesn’t realize that no one else is awake. This light was designed to be a "go / no-go" signal for him to get back to bed. It’s green during "woke up" hours and red during "sleepy time."

Build

This design includes multiple layers: A Raspberry Pi Zero, some Python code, NeoPixel RGB LEDs, and some 3D prints in both clear and black designed in Fusion 360. The Raspberry Pi uses something called "GPIO" to physically interface with the outside world. Connecting wires to things like relays or LEDs allows the Raspberry Pi to communicate through Python code. In the case of NeoPixel LEDs, only GPIO 10, 12, 18, or 21 will work. Note that the GPIO number is not equal to the pin number on the Pi. GPIO 10, for example, is pin 19.

Wake Up Light

These are the steps I took to get this project going:

  • Install Raspberry Pi OS to a microSD card with their installer
    • Change settings like password and wifi details
  • SSH to the Pi
    • sudo apt-get update
    • sudo apt-get upgrade
    • Set the Pi to the correct timezone more info
    • sudo apt-get install python3
    • sudo apt-get install python-rpi.gpio python3-rpi.gpio
    • apt install python3-pip
    • sudo pip3 install adafruit-circuitpython-neopixel

I created a new file called “led.py” in a folder under /home/pi/scripts/ and ran

chmod 755 led.py 

…to give it generally acceptable permissions. In led.py, I wrote the following:

import board
import neopixel
import datetime
import time
pixel_pin = board.D18     # GPIO number (not pin number)
num_pixels = 5            # total number of LEDs
BRIGHTNESS = 0.2          # value from 0.1 to 1.0
ORDER = neopixel.RGB
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=BRIGHTNESS,auto_write=False,pixel_order=ORDER)
while True:
  x = datetime.datetime.now()
  if 7 <= x.hour < 21:
    pixels.fill((255,0,0))
    pixels.show()
    time.sleep(60)
  else:
    pixels.fill((0,255,0))
    pixels.show()
    time.sleep(60)

The last little bit was to get this running automatically on startup. For that we use a tool called CronTab. Typing > sudo crontab -e will bring you into the root user’s cron scheduler. Adding the following line will get your Python script running without needing to login to your Pi. Note the "&" puts the task in the background.

@reboot python3 /home/pi/scripts/led.py \&

Wake Up Light


Thoughts

This was a great learning experience as I’m just starting to get good at Python. It’s a great scripting language and is incredibly fun to use. Let’s see if this continues to work well and if it prevents my son from having some late night scary moments.

Previous: Building a NAS Next: One Glance Lamp