From: Tomas Mudrunka Date: Wed, 1 Aug 2012 00:08:16 +0000 (+0200) Subject: Sleep Monitor using PIR sensor and Goertzel X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=890439aeff4c6a30e09e66009dc26897f3dc6e66;p=mirrors%2FPrograms.git Sleep Monitor using PIR sensor and Goertzel --- diff --git a/c/goertzel/sleepmon.README b/c/goertzel/sleepmon.README new file mode 100644 index 0000000..f5d38d8 --- /dev/null +++ b/c/goertzel/sleepmon.README @@ -0,0 +1,28 @@ + + __________ + | + ___ _______ __________| + / \/ \/ | 3.5mm Stereo Jack + | || || | + | || || | (Mono version has right and + \___/\_______/\__________| ground merged in single pole) + | + ^ ^ ^ |___________ + * LEFT | | + * RIGHT | + * GROUND + ___________ + | | + | PIR | + LEFT =---------+ | | +Soundcard INPUT GROUND =--+ | | | + | | | | + | +-----|-o/ NC | + | +-----|-/ Switch | +Soundcard OUTPUT GROUND =--+ | | | + LEFT =---------+ | | + | 12V Power | + | + - | + |__|__|_____| + | | + To supply diff --git a/c/goertzel/sleepmon.sh b/c/goertzel/sleepmon.sh new file mode 100755 index 0000000..3e3ee6b --- /dev/null +++ b/c/goertzel/sleepmon.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Simple sleep monitor (Harvie 2012) +# +# You probably have soundcard with one output and input +# Take PIR motion sensor from security system +# Use PIR to switch connection between left channels of output and input (tips of 3.5mm jacks) +# Connect grounds of these two together (maybe you will not need it - depending on your soundcard) +# Power up PIR +# Launch this script +# Use alsamixer and some GUI recorder (like audacity) to tune volume to some usable level +# Place PIR facing to your bed and go sleep +# Wake up +# Enjoy your data + +out=/tmp/sleeplog-"$(date +%F_%r)".txt +speaker-test -t sine &>/dev/null & +tresh=10 +lastdate=0 +arecord | ./goertzel -i -q -a -t $tresh -s 2000 | while read line; do + date="$(date +%s)" + time="$(echo "$line" | cut -f 1)" + level="$(echo "$line" | cut -f 2)" + echo -ne "$time\t$date\t$(date '+%F%t%r')\t" + test "$level" -gt "$tresh" && { + echo -n "Nothing detected..."; + } || { + echo -n "Motion detected!!!!"; + } + test "$lastdate" != 0 && { + after=$(( $date - $lastdate)) + echo -ne "\t$level After $after secs"; + } + echo; + lastdate="$date"; +done | tee "$out" +kill $! +echo "Your file: $out"