Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MotionSensorRS485.ino 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * The MySensors Arduino library handles the wireless radio link and protocol
  3. * between your home built sensors/actuators and HA controller of choice.
  4. * The sensors forms a self healing radio network with optional repeaters. Each
  5. * repeater and gateway builds a routing tables in EEPROM which keeps track of the
  6. * network topology allowing messages to be routed to nodes.
  7. *
  8. * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
  9. * Copyright (C) 2013-2018 Sensnology AB
  10. * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
  11. *
  12. * Documentation: http://www.mysensors.org
  13. * Support Forum: http://forum.mysensors.org
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * version 2 as published by the Free Software Foundation.
  18. *
  19. *******************************
  20. *
  21. * REVISION HISTORY
  22. * Version 1.0 - Henrik Ekblad
  23. *
  24. * DESCRIPTION
  25. * This is an example of sensors using RS485 as transport layer
  26. *
  27. * Motion Sensor example using HC-SR501
  28. * http://www.mysensors.org/build/motion
  29. *
  30. * If your Arduino board has additional serial ports
  31. * you can use to connect the RS485 module.
  32. * Otherwise, the transport uses AltSoftSerial to handle two serial
  33. * links on one Arduino. Use the following pins for RS485 link
  34. *
  35. * Board Transmit Receive PWM Unusable
  36. * ----- -------- ------- ------------
  37. * Teensy 3.0 & 3.1 21 20 22
  38. * Teensy 2.0 9 10 (none)
  39. * Teensy++ 2.0 25 4 26, 27
  40. * Arduino Uno 9 8 10
  41. * Arduino Leonardo 5 13 (none)
  42. * Arduino Mega 46 48 44, 45
  43. * Wiring-S 5 6 4
  44. * Sanguino 13 14 12 *
  45. *
  46. */
  47. // Enable debug prints to serial monitor
  48. #define MY_DEBUG
  49. // Enable RS485 transport layer
  50. #define MY_RS485
  51. // Define this to enables DE-pin management on defined pin
  52. #define MY_RS485_DE_PIN 2
  53. // Set RS485 baud rate to use
  54. #define MY_RS485_BAUD_RATE 9600
  55. // Enable this if RS485 is connected to a hardware serial port
  56. //#define MY_RS485_HWSERIAL Serial1
  57. #include <MySensors.h>
  58. uint32_t SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
  59. #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
  60. #define CHILD_ID 1 // Id of the sensor child
  61. // Initialize motion message
  62. MyMessage msg(CHILD_ID, V_TRIPPED);
  63. void setup()
  64. {
  65. pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
  66. }
  67. void presentation()
  68. {
  69. // Send the sketch version information to the gateway and Controller
  70. sendSketchInfo("Motion Sensor", "1.0");
  71. // Register all sensors to gw (they will be created as child devices)
  72. present(CHILD_ID, S_MOTION);
  73. }
  74. void loop()
  75. {
  76. // Read digital motion value
  77. bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
  78. Serial.println(tripped);
  79. send(msg.set(tripped?"1":"0")); // Send tripped value to gw
  80. // Sleep until interrupt comes in on motion sensor. Send update every two minute.
  81. sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
  82. }