Sleep Monitor using PIR sensor and Goertzel
authorTomas Mudrunka <tomas@mudrunka.cz>
Wed, 1 Aug 2012 00:08:16 +0000 (02:08 +0200)
committerTomas Mudrunka <tomas@mudrunka.cz>
Wed, 1 Aug 2012 00:08:16 +0000 (02:08 +0200)
c/goertzel/sleepmon.README [new file with mode: 0644]
c/goertzel/sleepmon.sh [new file with mode: 0755]

diff --git a/c/goertzel/sleepmon.README b/c/goertzel/sleepmon.README
new file mode 100644 (file)
index 0000000..f5d38d8
--- /dev/null
@@ -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 (executable)
index 0000000..3e3ee6b
--- /dev/null
@@ -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"
This page took 0.101621 seconds and 4 git commands to generate.