Rpi Motion and temperature sensor
Raspberry pi motion and temperature sensor


Basic setup for Rpi with the camera module using Motion and a DS18B20 temperature sensor on Raspbian

Materials:

To do list after burning new Raspbian image to card:

  • expand file system on card

  • change password

  • activate Rpi Camera - test with: raspistill -o image.jpg

  • turn SSH on

  • set time and location


sudo apt-get update

sudo apt-get install

sudo apt-get upgrade

sudo apt-get dist-upgrade

sudo rpi-update

sudo vi /etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
    iface eth0 inet static
        address 192.168.10.2
        netmask 255.255.255.0
        gateway 192.168.10.1
        network 192.168.10.0
        broadcast 192.168.10.255

sudo reboot

sudo vi /boot/config.txt

#Disable Rpi Camera LED
disable_camera_led=1

#Disable device tree for 1 wire
device_tree=

sudo apt-get install motion

sudo apt-get install -y libjpeg62 libjpeg62-dev libavformat53 libavformat-dev libavcodec53 libavcodec-dev libavutil51 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev

wget https://www.dropbox.com/s/xdfcxm5hu71s97d/motion-mmal.tar.gz

tar zxvf motion-mmal.tar.gz

rm motion-mmal.tar.gz

sudo mv motion /usr/bin/motion

sudo mv motion-mmalcam.conf /etc/motion.conf

sudo chmod 644 /etc/motion.conf

sudo chmod 755 /usr/bin/motion

touch /home/pi/motion.log

chmod 664 /home/pi/motion.log

sudo chown pi:motion /home/pi/motion.log

mkdir ~/supraveghere

sudo chown pi:motion ~/supraveghere

sudo chmod g+rw ~/supraveghere

sudo vi /etc/default/motion

start_motion_daemon=yes

sudo vi /etc/motion.conf

# Just the differences to the original file are listed below. I decided I dont nead the real time streaming or movies just pictures on motion and snapshots every hour.

# Start in daemon (background) mode and release terminal (default: off)
daemon on

# Use a file to save logs messages, if not defined stderr and syslog is used. (default: not defined)
logfile /home/pi/motion.log

# Image width (pixels). Valid range: Camera dependent, default: 352
width 1024

# Image height (pixels). Valid range: Camera dependent, default: 288
height 576

# Make automated snapshot every N seconds (default: 0 = disabled)
snapshot_interval 3600

# Draw characters at twice normal size on images. (default: off)
text_double on

# Target base directory for pictures and films
# Recommended to use absolute path. (Default: current working directory)
target_dir /home/pi/supraveghere

# File path for snapshots (jpeg or ppm) relative to target_dir
# Default: %v-%Y%m%d%H%M%S-snapshot
# Default value is equivalent to legacy oldlayout option
# For Motion 3.0 compatible mode choose: %Y/%m/%d/%H/%M/%S-snapshot
# File extension .jpg or .ppm is automatically added so do not include this.
# Note: A symbolic link called lastsnap.jpg created in the target_dir will always
# point to the latest snapshot, unless snapshot_filename is exactly 'lastsnap'
snapshot_filename %Y/%b/%Y%m%d%H%M%S-snapshot

# File path for motion triggered images (jpeg or ppm) relative to target_dir
# Default: %v-%Y%m%d%H%M%S-%q
# Default value is equivalent to legacy oldlayout option
# For Motion 3.0 compatible mode choose: %Y/%m/%d/%H/%M/%S-%q
# File extension .jpg or .ppm is automatically added so do not include this
# Set to 'preview' together with best-preview feature enables special naming
# convention for preview shots. See motion guide for details
picture_filename %Y/%b/%Y%m%d%H%M%S

# The mini-http server listens to this port for requests (default: 0 = disabled)
stream_port 0

sudo vi /etc/modules

w1-therm
w1-gpio pullup=1
i2c-dev
i2c-bcm2708
spi-bcm2708
snd-bcm2835

sudo vim /etc/modprobe.d/1-wire.conf

option w1-gpio pullup=1
option w1-therm strong_pullup=1

cat /etc/modprobe.d/raspi-blacklist.conf

# blacklist spi and i2c by default (many users don't need them)

blacklist spi-bcm2708
blacklist i2c-bcm2708

SSH key and reverse tunnel

crontab -e

20,50 * * * * rsync -avz -e ssh /home/pi/supraveghere/ LinuxServer:/var/www/Your/Picture/
05,25,45 * * * * echo "$(date)" "$(cat /sys/bus/w1/devices/28-000005220167/w1_slave | grep t= | awk '{print $10}')" >> /home/pi/supraveghere/tempext.txt
#The SSH reverse tunnel is for acces behind NAT with no port forward.
*/1 20 * * * ~/tunnel.sh > tunnel.log 2>&1

sudo reboot

Deployed inside the house for trials using a wifi adaptor

Deployed inside the house for trials using a wifi adaptor

Note: The Raspberry Pi even inside the house in the winter at -17 degrees Celsius had the SD card fail but this was probably due to the fact that the SD card was a no name cheap one.

Rpi inside a IP65 box deployed outside

Rpi inside a IP65 box deployed outside

Deployed Outside

Deployed Outside

Sample picture captured by the Rpi

Sample picture captured by the Rpi

Sample graph using Google JavaScript Charts on a web page using the temperatures gathered from the sensor:

Temperature graph sample

Temperature graph sample


Posted on:

December 29, 2014
704 words

Contact Me:

If you are interested in contacting me feel free to do so by mail or online:

nob {at} nob.ro