Search This Blog

Monday, November 22, 2021

Raspberry Pi Pico Plushy Nightlight for Baby

Toward the end of September, as autumn arrived, the weather started to change, the days became shorter and the nights became longer, we took our 2 1/2 month old son out one evening for a ride in the car. We noticed that as it started to get darker outside, and baby boy could no longer see anything in the car, that he started to whine and fuss until we turned a light on in the backseat.

And so, I decided to try and use my new Raspberry Pi Pico microcontroller to make a plushy nightlight for baby boy's car seat.


The Brainstorm

Plans sketched out on paper for Raspberry Pi Pico Pillow prototype
My goal was to use a light dependent resistor to create a pillow that would sense the light levels in the car and signal the LEDs in the pillow to light as it got dark outside.

I'm a decent sewer, but not an expert by any means, so I had to keep the design simple. My original goal of sewing the plushy into some cute shape was quickly scrapped and replaced with a basic rectangular pillow shape, with a pocket on the back for holding a battery pack, and LEDs sewn inside to shine through the fabric. 

I also planned on sewing velcro straps onto the back of the plushy so that I can hang it on baby boy's car seat or stroller.


Process

This was my first Pico project and I was really happy to find that both the "Getting Started with Raspberry Pi Pico" guide on the projects.raspberrypi.org page and with the Getting Started with MicroPython on Raspberry Pi Pico book made it incredibly easy to learn how to program the Pico. I was up and running in minutes, blinking my first LED! 

Coding

  • Once I had my first LED blinking, I started playing with PWM so that I could pulse the lights in my
    pillow. 
  • Then, I researched how to program a photoresistor (LDR) using MicroPython. I'd never used a photoresistor successfully before on my Raspberry Pi 3s, but I found a really simple tutorial online that helped me to get the photoresistor connected and programmed on the Pico fairly quickly.
  • With my LEDs pulsing and my photoresistor sensing, I put both programs together into my final project. I created a function for "twinkling" lights and a function for "no twinkle", then programmed the Pico to pulse the LEDs on/off randomly depending on the level of light in the area. 


Soldering

  • Used needle-nosed pliers to bend LED legs into loops.
    Up to this point, my LEDs were loosely connected to the jumper cables by sliding the LED legs into the female ends of the cables. With everything running smoothly I decided to go ahead and solder all the cables and LEDs together for a more permanent connection.
  • This was my first time soldering LEDs to cables, so there was a bit of a learning curve for me. First, I stripped the cables. Then, for the purpose of sewing the LEDs into the pillow, I used needle nosed pliers to bend the legs on the LEDs into the circles, and wrapped the jumper cable wire around the legs of the LEDs. 
  • Soldered jumper cables onto LEDs
    I also bent the legs on the photoresistor in a similar fashion and wrapped the jumper cables to the LDR & its resistor in the same way. 
  • Finally it was soldering time. Not having done a ton of soldering in the past (aside from soldering leads onto Raspberry Pis) this was a great learning opportunity for me. I ended up with some messy cables, but they all work! 
  • Later on I found a great & simple tutorial on YouTube with some practical tips for a cleaner & maybe easier way of soldering together jumper cables and LEDs that I want to try next time.
(Yes, I could have purchased pre-soldered jumper cables & LEDs, or sewable LEDs and conductive thread, but when I dreamed up the project, the goal was to prototype the pillow using what I already had around and not to spend a lot of money on new materials.)


Sewing

  • Sewing commenced next, and this is when the project got more complicated. I didn't want to buy a whole bunch of new materials, so I stayed away from expensive conductive thread and (after some searching online for LED sewing tips) played with ways of using regular diodes and sewing them into my pillow. 
  • Sewed LEDs onto the fabric using the looped legs & thread
    I am also not a master sewer (I know enough to put together some basic projects, and a Halloween
    costume from time to time), so please excuse the not-so-pretty stitch work. After getting the LEDs sewn into patterned fabric, I sewed the pillow backing to the front along one edge (by hand unfortunately, as I do not have a sewing machine at home).
  • Luckily I was able to schedule time at my mom's house where there is an actual sewing machine. It was there that I realized that sewing in my pocket would be easier with the front and backing separated, so I tore out all of stitches to start again. 
  • Sewing a button hole

    I also decided that a button hole might allow me to run a power cable from the pocket into the microcontroller inside the pillow, so I learned how to sew a button hole with the machine, then attached a pocket to hide the hole, and finally I sewed the pillow backing onto the front, leaving the bottom open for stuffing.
  • I used standard polyester crafter's stuffing to stuff the pillow, making sure that the Pico microcontroller was still easily accessible. 
  • Then (home again with no sewing machine, sadly) I hand-sewed a hem on the bottom edges of the pillow before then sewing the edges together. However, after closing up the pillow, I decided that I wanted to still be able to access the Raspberry Pi Pico inside, to update the code or in case of troubleshooting, so I ripped out the stitches and started again, this time leaving a small opening and attaching Velcro connectors that I could use to open and close the pillow.

Pico & stuffing inside pillow Photoresistor sewn into corner of pillow Pocket sewn on back of pillow Cable inside of pillow, strung threw button hole


Final Product

I didn't end up sewing the straps on the back of the pillow, but may go back and add those later on. I also would like to find a smaller battery pack to run the microcontroller, that is more easily hidden in the outside pocket, but otherwise I am happy with the way this first attempt turned out. 

The pillow is small enough for baby's stroller and car seat, and adds a nice, soothing lighting effect to the back seat of the car when the sun goes down.

 Velcro opening Pillow in car seat Pillow in crib with LED lit









Resources


The Code

from machine import Pin, PWM, ADC

import random

from time import sleep


photoPIN = 26

blue1 = PWM(Pin(20))

white1 = PWM(Pin(16))

blue2 = PWM(Pin(14))

white2 = PWM(Pin(11))

blue3 = PWM(Pin(7))

white3 = PWM(Pin(3))


blue1.freq(1000)



def readLight(photoGP): #function to access photoresistor

    photoRes = ADC(Pin(26))

    light = photoRes.read_u16()

    light = round(light/65535*100,2)

    return light



def twinkle(): #function for twinkling lights

    

    light = [blue1, white1, blue2, white2, blue3, white3]


    for i in range(10):

        pulse_light = random.choice(light)

        for duty in range(65025):

            pulse_light.duty_u16(duty)

            sleep(0.0001)

        for duty in range(65025, 0, -1):

            pulse_light.duty_u16(duty)

            sleep(0.0001)



def no_twinkle(): #function to turn off all LEDs

    

    light = [blue1, white1, blue2, white2, blue3, white3]

    

    for duty in range(0):

        light.duty_u16(duty)

        sleep(0.0001)

   


no_twinkle() #start with all LEDs off



while True:

    print("Light: " + str(readLight(photoPIN)) +"%")

    light = readLight(photoPIN)

    if light <= 5:

        print("It's dark... let's twinkle some lights")

        twinkle()

    else:

        no_twinkle()

    sleep(1)


No comments:

Post a Comment