Posted on 7 Comments

#13: Connecting security sensors to Arduino

Just wiring up some lights so you can control them from your phone isn’t real home automation: that’s just turning your house into a really big remote controlled toy, even if you can do it from the other side of the world. For real automation your house needs to change its behaviour based on sensor input, and security sensors are a great way to add simple inputs that allow your house to make decisions about things like turning lights on and off automatically.

In this episode I show a clever way to connect security sensors up so that intruders can’t tamper with the cables undetected.

View directly on YouTube: www.youtube.com/watch?v=NfPDpwtPi6g

Here’s an example Arduino sketch that can read End-of-Line sensors and publish the results to an MQTT server: https://github.com/SuperHouse/SecuritySensor4ToMQTT

7 thoughts on “#13: Connecting security sensors to Arduino

  1. What motion sensor are you using in this video? Orion?

    In later blog, you mentioned a different motion sensor that had a wider “view” of the area that you were monitoring.

    I’m really inspired by what you are doing with your house.

    I’m running OpenHAB with ESP8266’s, but want to use the motion sensors to automate the lights and fans in the house.

    Thanks!

    Rob

  2. Do you share the PCB layout for your arduino shield used for this project? I would like to make one of my own if possible.

    1. Yes, it’s all on GitHub and the page for the shield has links to the source: http://www.freetronics.com.au/secsense

  3. Jonathan,

    I get errors when compiling. Can you help?

    Thanks
    Henri (Netherlands)

    Arduino: 1.8.4 (Windows 10), Board: “Arduino/Genuino Uno”

    Build options changed, rebuilding all
    SecuritySensorToMQTT:117: error: no matching function for call to ‘PubSubClient::PubSubClient(byte [4], int, void (&)(char*, byte*, int))’

    PubSubClient client(server, 1883, callback);

    ^

    C:\Users\Henri\Documents\Arduino\SecuritySensorToMQTT\SecuritySensorToMQTT.ino:117:43: note: candidates are:

    In file included from C:\Users\Henri\Documents\Arduino\SecuritySensorToMQTT\SecuritySensorToMQTT.ino:40:0:

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:116:4: note: PubSubClient::PubSubClient(const char*, uint16_t, void (*)(char*, uint8_t*, unsigned int), Client&, Stream&)

    PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:116:4: note: candidate expects 5 arguments, 3 provided

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:115:4: note: PubSubClient::PubSubClient(const char*, uint16_t, void (*)(char*, uint8_t*, unsigned int), Client&)

    PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:115:4: note: candidate expects 4 arguments, 3 provided

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:114:4: note: PubSubClient::PubSubClient(const char*, uint16_t, Client&, Stream&)

    PubSubClient(const char*, uint16_t, Client& client, Stream&);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:114:4: note: candidate expects 4 arguments, 3 provided

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:113:4: note: PubSubClient::PubSubClient(const char*, uint16_t, Client&)

    PubSubClient(const char*, uint16_t, Client& client);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:113:4: note: no known conversion for argument 3 from ‘void(char*, byte*, int) {aka void(char*, unsigned char*, int)}’ to ‘Client&’

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:112:4: note: PubSubClient::PubSubClient(uint8_t*, uint16_t, void (*)(char*, uint8_t*, unsigned int), Client&, Stream&)

    PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:112:4: note: candidate expects 5 arguments, 3 provided

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:111:4: note: PubSubClient::PubSubClient(uint8_t*, uint16_t, void (*)(char*, uint8_t*, unsigned int), Client&)

    PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:111:4: note: candidate expects 4 arguments, 3 provided

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:110:4: note: PubSubClient::PubSubClient(uint8_t*, uint16_t, Client&, Stream&)

    PubSubClient(uint8_t *, uint16_t, Client& client, Stream&);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:110:4: note: candidate expects 4 arguments, 3 provided

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:109:4: note: PubSubClient::PubSubClient(uint8_t*, uint16_t, Client&)

    PubSubClient(uint8_t *, uint16_t, Client& client);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:109:4: note: no known conversion for argument 3 from ‘void(char*, byte*, int) {aka void(char*, unsigned char*, int)}’ to ‘Client&’

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:108:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, void (*)(char*, uint8_t*, unsigned int), Client&, Stream&)

    PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:108:4: note: candidate expects 5 arguments, 3 provided

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:107:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, void (*)(char*, uint8_t*, unsigned int), Client&)

    PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:107:4: note: candidate expects 4 arguments, 3 provided

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:106:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, Client&, Stream&)

    PubSubClient(IPAddress, uint16_t, Client& client, Stream&);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:106:4: note: candidate expects 4 arguments, 3 provided

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:105:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, Client&)

    PubSubClient(IPAddress, uint16_t, Client& client);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:105:4: note: no known conversion for argument 3 from ‘void(char*, byte*, int) {aka void(char*, unsigned char*, int)}’ to ‘Client&’

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:104:4: note: PubSubClient::PubSubClient(Client&)

    PubSubClient(Client& client);

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:104:4: note: candidate expects 1 argument, 3 provided

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:103:4: note: PubSubClient::PubSubClient()

    PubSubClient();

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:103:4: note: candidate expects 0 arguments, 3 provided

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:83:7: note: constexpr PubSubClient::PubSubClient(const PubSubClient&)

    class PubSubClient {

    ^

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:83:7: note: candidate expects 1 argument, 3 provided

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:83:7: note: constexpr PubSubClient::PubSubClient(PubSubClient&&)

    C:\Users\Henri\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:83:7: note: candidate expects 1 argument, 3 provided

    exit status 1
    no matching function for call to ‘PubSubClient::PubSubClient(byte [4], int, void (&)(char*, byte*, int))’

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    1. I changed this

      // Instantiate MQTT client
      EthernetClient ethClient;
      PubSubClient client(server, 1883, callback, ethClient);

      Now it’s working

  4. Hi,
    I cannot upload due to below error
    Sketch uses 27962 bytes (86%) of program storage space. Maximum is 32256 bytes.
    Global variables use 2582 bytes (126%) of dynamic memory, leaving -534 bytes for local variables. Maximum is 2048 bytes.
    Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint.
    Error compiling for board Arduino/Genuino Uno.

    How i can make it lighter?
    Is there a version without OLED?

  5. Would it be possible to use a Mega and build an all one home security system.
    1. Standalone home security with indoor/outdoor siren/strobe light, keypad/display (and/or RFID), PIR, power/backup battery.
    2. Ability to send “data” to home automation server, so that the HA server can also do other things with the system.
    3. Ability to be controlled by the home automation server.

    The thinking is having a standalone home security system so it’s not reliant on the home automation server for core “home security alarm” functionality, but still have the smart and automation options.

Leave a Reply

Your email address will not be published. Required fields are marked *