{"id":252,"date":"2016-05-13T20:57:55","date_gmt":"2016-05-13T10:27:55","guid":{"rendered":"http:\/\/parablog-wordpress.dockerbox.rei.moe\/?p=252"},"modified":"2016-05-13T20:57:55","modified_gmt":"2016-05-13T10:27:55","slug":"hamshield-motion-sensor","status":"publish","type":"post","link":"https:\/\/blog.lewys.eu\/?p=252","title":{"rendered":"HamShield Motion Sensor"},"content":{"rendered":"<p>I am in need of a motion sensor for something, and I have this HamShield that I got from KickStarter recently.<\/p>\n<p>&nbsp;<\/p>\n<p>heres some code I have mashed together that *MIGHT* make the radio send an SSTV image when motion is triggered..<\/p>\n<p>&nbsp;<\/p>\n<p>I have to rest it and refine it first! its just mashed code from examples!<\/p>\n<p>[su_expand more_text=&#8221;Code:&#8221; less_text=&#8221;Close Code.&#8221;]\/* Morse Code Beacon Test beacon will transmit and wait 30 seconds. Beacon will check to see if the channel is clear before it will transmit. *\/ \/\/ Include the HamSheild #include #define PWM_PIN 3 #define RESET_PIN A3 #define SWITCH_PIN 2 \/\/ Create a new instance of our HamSheild class, called &#8216;radio&#8217; HamShield radio; int calibrationTime = 30; boolean sensorActive = false; boolean previousSensorState = false; int pirPin = 4; \/\/the digital pin connected to the PIR sensor&#8217;s output \/\/ Run our start up things here void setup() { \/\/ NOTE: if not using PWM out, it should be held low to avoid tx noise pinMode(PWM_PIN, OUTPUT); digitalWrite(PWM_PIN, LOW); pinMode(pirPin, INPUT); digitalWrite(pirPin, LOW); \/\/ prep the switch pinMode(SWITCH_PIN, INPUT_PULLUP); \/\/ set up the reset control pin pinMode(RESET_PIN, OUTPUT); digitalWrite(RESET_PIN, HIGH); \/\/ Set up the serial port at 9600 Baud Serial.begin(9600); \/\/ Send a quick serial string Serial.println(&#8220;HamShield FM Beacon Example Sketch&#8221;); \/\/ Query the HamShield for status information Serial.print(&#8220;Radio status: &#8220;); int result = radio.testConnection(); Serial.println(result,DEC); \/\/ Tell the HamShield to start up radio.initialize(); radio.setRfPower(0); \/\/ Configure the HamShield to transmit and recieve on 446.000MHz radio.frequency(145570); Serial.println(&#8220;Radio Configured.&#8221;); Serial.println(&#8220;Sensor Calibration in Progress&#8221;); Serial.println(&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8220;); for(int i = 0; i &lt; calibrationTime; i++){ Serial.print(&#8220;.&#8221;); } Serial.println(&#8220;&#8221;); Serial.println(&#8220;Sensor Calibration Completed&#8221;); Serial.println(&#8220;Sensor Reading Active&#8221;); delay(50); sensorActive = false; previousSensorState = false; } void loop() { \/\/ takes the pin value and saves it to the sensorActive boolean value if(digitalRead(pirPin) == HIGH) { sensorActive = true; radio.setModeTransmit(); \/\/ Turn on the transmitter delay(250); \/\/ Wait a moment radio.SSTVTestPattern(MARTIN1); \/\/ send a MARTIN1 test pattern delay(250); radio.setModeReceive(); \/\/ Turn off the transmitter } if(digitalRead(pirPin) == LOW) { sensorActive = false; delay(250); } \/\/ performs action if the state of the sensor changes \/\/ since this is a loop, here is now it works: \/\/ if the sensor pin goes HIGH (on) after it being LOW (off), the sensorActive value changes from the previousSensorState value. \/\/ it then turns on the LED. when the pin goes LOW (off) it will do the same thing but opposite values. \/\/ it also prints status to serial. it will print the time of triggering by providing the number of seconds that have passed since the program started. if(sensorActive != previousSensorState) { if(sensorActive == true) { previousSensorState = sensorActive; Serial.println(&#8220;&#8212;&#8220;); Serial.print(&#8220;Motion Detected At: &#8220;); Serial.print(millis()\/1000); Serial.println(&#8221; Seconds&#8221;); delay(50); } if(sensorActive == false) { previousSensorState = sensorActive; Serial.println(&#8220;&#8212;&#8220;); Serial.print(&#8220;Motion Stopped At: &#8220;); Serial.print(millis()\/1000); Serial.println(&#8221; Seconds&#8221;); delay(50); } } } [\/su_expand]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am in need of a motion sensor for something, and I have this HamShield that I got from KickStarter recently. &nbsp; heres some code I have mashed together that *MIGHT* make the radio send an SSTV image when motion is triggered.. &nbsp; I have to rest it and refine it first! its just mashed &hellip; <a href=\"https:\/\/blog.lewys.eu\/?p=252\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">HamShield Motion Sensor<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,20,27,18,25],"tags":[],"class_list":["post-252","post","type-post","status-publish","format-standard","hentry","category-amateur-radio","category-arduino-2","category-programming","category-projects","category-wireless"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=\/wp\/v2\/posts\/252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=252"}],"version-history":[{"count":1,"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=\/wp\/v2\/posts\/252\/revisions"}],"predecessor-version":[{"id":253,"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=\/wp\/v2\/posts\/252\/revisions\/253"}],"wp:attachment":[{"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}