Raspberry Pi Nursery Cam

One of my most recent projects has centered on the new IMG_20150104_005102addition in my family. With the baby on the way I started looking at baby monitors and realizing that a simple little video-enabled baby monitor was around $300. I figured I could do much better than a tiny 2″ screen and integrate some useful features along the way.

Goal: Sub $300 Baby Monitor Camera

Result: $100 Nightvision Camera /w FM Audio Broadcast

Capabilities:

  • Full 1080p Streaming (cropped image) over Ethernet (Full Frame Image /w 1296×972 resolution)
  • Internet Streaming capabilities to broadcast video to Computers, Phones and HTPCs.
  • Selectable FM Frequency for Audio Transmission – any radio in the house is now a baby monitor including bedside clock radios.
  • Separate Audio and Video Transmission for all different kinds of endpoints
  • Full Nightvision capabilities with the PiNoir Camera Module and IR LED module (can be used in total darkness and picture is excellent)
  • IR LED module shuts itself off when not needed due to a built-in photoresistor
  • Authentic Camera look salvaging a dummy enclosure
  • Stream plays easily in XBMC making any HTPC double as a video receiving endpoint.

Parts list:

Dummy Camera Shell from Monoprice — $7.94
IR LED Light Array from Amazon — $5.90
Slice of Pi Breakout Board — $8.25
Cheap USB Microphone from Amazon — $7.95
Raspberry Pi Model B — ~$40
Raspberry PiNoir Camera Module — $25
Nylon Washers and Tiny Nuts/Bolts — $1.50

Misc Parts (freebies):

SD Card
Piece of Wire
Ethernet Cable
MIcro USB Cable
USB Power Brick
12vdc Power Adapter for LED’s

Project Details:

Gut The Dummy Camera Enclosure

The first order of business was to gut the innards of the dummy camera case to make room for the Pi. In my case I took my dremel cut off wheel and hollowed-out the back of the case to make room for all the wires and SD card which hangs out the back a bit. Removing all the Battery, LED components, and fake LED array left plenty of room for our frankencamera. The IR LED array is pretty much a direct fit for the fake one that was removed. I discarded the black plastic backer behind the fake LED array too. By countersinking the holes that hold the fake LED array in place I was able to reuse the mounting bracket to tighten down the new LED array as a direct replacement for the fake one.

You can see the LED array has mounting holes that line up almost perfectly with one of the pairs from the PiNoir module.
You can see the LED array has mounting holes that line up almost perfectly with one of the pairs from the PiNoir module. I used nylon washers and a pair of nylon spacers between the two boards to keep them from touching each other or anything conductive.
IMG_20141213_124430
You could even dremel-out the battery compartment and stick a little thumb drive here for local storage of video/audio content. Since my device is a network streamer I left this compartment alone after removing all the metallic components.
IMG_20141213_124446
Dremel out the back of the enclosure. This was only necessary for me because of my cheap USB microphone which could not bend very well in the case.
My pet black widow I caught in my workshop as I was working.
My pet black widow I caught in my workshop as I was working.

Install Software

For this project I just used the basic Raspbian image on the SD card. From there I enabled turbo-mode for on demand overclocking up to 1ghz. This project uses PiFM to broadcast audio on the FM bands. PiFM is a quick and dirty solution to acheive my goals. Be aware that PiFM is a pretty noisy transmission that has strong harmonics in bands you should not be transmitting on — that being said, your range is very small (about 30-300ft depending on the length of your antenna) and will probably not hurt anyone (use your judgement and check your local laws to make sure you’re in the clear here). Install PiFM and test that your broadcasting works. Once you’ve confirmed you’re broadcasting as expected you can use Radio Locator to determine which FM frequencies are vacant in your area. Broadcasting on a vacant frequency will give you the best performance and range. I ended up trying a few of the frequencies in the “BEST” category before I found one that was pretty much perfect for me and gave crystal clear audio. For a more permanent antenna attachment, I soldered my antenna wire to the “Slice of Pi” breakout board. I may also add a toggle switch for the FM transmission at some point so it’s nice to have the breakout board ready to go.

Configure Camera

The PiNoir camera module is actually a really capable camera and using the included raspivid software can be configured to behave however you could want it. It’s worth reading about the different modes the camera supports and making a decision as to what is most important for your application. For me I did not need a high quality 1080p stream so much as I did a wide field of view since the camera is close to the subject being filmed. For this reason I selected the 1296×972 resolution which uses the entire sensor for the widest possible field of view.

After selecting the resolution it’s time to tweak your raspivid settings to give you the best results. I after reading through all of the settings and doing a good bit of experimentation I settled on the string below:

#1296×972 1-42fps, 4:3 aspect binned full FOV.
raspivid -h 972 -w 1296 -br 46 --colfx 120:120 -o - -t 0 -vf -hf | cvlc -v stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264

You’ll notice in my code above I’m using the color effects feature to skew all the colors to a nightvision color palette. I did this because occasionally due to power fluctuations on the camera module the image would shift a bit back and forth from green to red, the effect was significant enough for my wife to notice it which means I wanted to fix it. By specifying the color effects I was able to work around the color-shifting artifacts. FYI the color shift is due to the poor design of the Raspberry Pi power supply circuitry; I believe this may no longer be an issue with the enhancements made to the newest B+ model but since I don’t own one, I can’t say.

Create a Streaming File for XBMC/Kodi

If you want to play your stream on an XBMC/Kodi machine you can put the details of your stream into a simple text file and Kodi will play your stream when you play the file. Here’s my example file that I used.

Filename: Baby.strm

rtsp://[IP Address of PI]:8554

Startup Scripts

A bit of scripting will allow the video and audio to start when the machine boots. My startup scripts are provided below.

/etc/init.d/SCREEN_STARTUP — quick script that starts both Audio and Video streaming at boot time. Don’t forget to add it to your startup with “sudo update-rc.d SCREEN_STARTUP defaults”.

#!/bin/bash

#Raspberry Pi actually doesn't actually support MTU over 1500
#   but does not bark when you set it. See Link below:
#http://www.raspberrypi.org/forums/viewtopic.php?t=52807&p=405135
#ifconfig eth0 mtu 9198

/usr/bin/screen -d -m -S "RASPIVID SESSION" /home/pi/raspivid_abstraction &

sleep 2 

/usr/bin/screen -d -m -S "PIFM SESSION" /home/pi/pifm_stream_command &

echo "Script has attempted to start both screens"

sleep 1
echo "List of available screens is:"

screen -list

/home/pi/screen_watcher.sh &

exit

/home/pi/raspivid_abstraction — necessary to run VLC under the Pi user, VLC will not run as root without modification.

#!/bin/bash

su - pi -c "/home/pi/raspivid_stream_command"

/home/pi/raspivid_stream_command — starts the video stream (just uncomment whatever mode you want to use)

#!/bin/bash
#1296×972 1-42fps, video mode, 4:3 aspect binned full FOV.
raspivid -h 972 -w 1296 -br 46 --colfx 120:120 -o - -t 0 -vf -hf | cvlc -v stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264

#Experimental adding sound -- does not work! Raspivid sends raw H264 Stream, would need to have an intermediary step with Gstreamer adding the timing information to the video stream in order to layer the audio on top of it.
#raspivid -h 972 -w 1296 -br 46 --colfx 120:120 -o - -t 0 -vf -hf | cvlc -v stream:///dev/stdin --input-slave=alsa://plughw:1,0 --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264


#1296×730 1-49fps, video mode, 16:9 aspect , binned, full FOV (width), used for 720p
#raspivid -h 730 -w 1296 -br 40 --colfx 120:120 -o - -t 0 -vf -hf | cvlc -v stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264

#1920×1080 1-30fps, video mode, 1080p30 cropped
#raspivid -h 1080 -w 1920 -br 40 --colfx 120:120 -o - -t 0 -vf -hf | cvlc -v stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264

/home/pi/pifm_stream_command — Starts PiFM

#!/bin/bash
arecord -fS16_LE -r 22050 -Dplughw:1,0 - |  /home/pi/software/pifm - 106.7 22050

/home/pi/screen_watcher.sh — Makes sure that both commands are still running, I’ve found PiFM occasionally dies out, so this script restarts it.

#!/bin/bash

while true; do
    sleep 30
    PIFM=$(screen -list | grep PIFM | wc -l)
    RASPIVID=$(screen -list | grep RASPIVID | wc -l)
    if [ "$PIFM" -ne "1" ]
    then
        /usr/bin/screen -d -m -S "PIFM SESSION" /home/pi/pifm_stream_command &
        echo " $(date) -- PIFM restarted." >> /var/log/screen_watcher.log
    #else
    #    echo "PIFM still running"
    fi

    if [ "$RASPIVID" -ne "1" ]
    then
        /usr/bin/screen -d -m -S "RASPIVID SESSION" /home/pi/raspivid_abstraction &
        echo " $(date) -- RASPIVID restarted." >> /var/log/screen_watcher.log
    #else
    #    echo "RASPIVID still running"
    fi
done

Ideas for Future Enhancements

  • A button to toggle the FM transmission on/off
  • Eventually I’ll do a similar build (minus the audio) for an exterior surveillance system. Monoprice sells actual camera enclosures for this purpose

Final Tests

Two sided tape was applied to the bottom of the microphone to stick it to the wall. I used the included hardware to mount the bracket as well.
Two sided tape was applied to the bottom of the microphone to stick it to the wall. I used the included hardware to mount the bracket as well.
The baby actually looks a bit creepy here but the picture quality is awesome on this old 25" monitor I had laying around. I purchased a flat screen TV wall mount for my Bedroom Media Center project.
The baby actually looks a bit creepy here; I think he is hypnotized by the faint red glow of the IR LEDs but the picture quality is awesome on this old 25″ monitor I had laying around. I purchased a flat screen TV wall mount for my Bedroom Media Center project which is what I’m using to view the video stream here.
The XBMC Bedroom Media Center playing the stream.
The XBMC Bedroom Media Center playing the stream.

Everything works like a charm. There is about a 6 second delay for both the audio and video transmission which does not really bother me for my application. In my brief research on the subject I think I read it was due to the buffering. One of the things I really like about this project is the separation of the audio and video transmission so you don’t have to have the whole media center on to listen to the audio. You can just use a bedside clock radio (not pictured) to listen to the stream.

Advertisements

6 thoughts on “Raspberry Pi Nursery Cam”

  1. Impressive. Im not so sure its safe to aim an IR camera at anyone for an extended period of time? The eyes to not blink or adjust to the light. Google it “safe to look at ir light”

    Like

  2. Could you post a tutorial to get the hardware together? Like how to connect the IR light to the pi.

    I have a pi running as a security camera already and it vlc-streams to my server. The problem with my pi is that the included IR leds does’t have enough power to even reach the end of the patio. I also have a dead Foscam FI8906W which I can use the enclosure and the 60 IR led array. I just don’t know how I would connect the IR array to the pi.

    Like

    1. I actually don’t have the PI control the LED array per-se. The Array is on 24×7 but only activates when the photo-resistor detects low light levels. Then the Pi Camera adapts to the light source as needed. My color filtering helps to produce a pretty consistent black and white (or nightvision green if you prefer 🙂 ) image regardless of the lightsource being IR or normal light.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s