Enter Your Project for a chance to win an Arduino MKR WAN 1300 Kit with a Compatable Lora Gateway or an MKR 1400 GSM with a Shield Combo + a $100 shopping cart! | Project14 Home | |
Monthly Themes | ||
Monthly Theme Poll |
I've installed a few of those inexpensive magnetic door and window alarms around the house, but they only make noise, they are not connected.
For this project, I tap into one of the door alarms and send the door status to the cloud.
We start with this:
Take it apart:
Solder to the V+, Gnd, and trigger input from the reed switch.
Then set up the Cloud service.
I set up a Thing called "FrontDoorSensor" on the Arduino IoT Cloud Service.
Then I set up a parameter called "DoorOpen"
Code for the Thing:
#include <ArduinoIoTCloud.h> #include <WiFiConnectionManager.h> const char THING_ID[] = "asdfjkl-ggfgfgf-200230"; const char SSID[] = SECRET_SSID; // Network SSID (name) const char PASS[] = SECRET_PASS; // Network (for WPA, or use as key for WEP) bool DoorOpen; void initProperties(){ ArduinoCloud.setThingId(THING_ID); ArduinoCloud.addProperty(DoorOpen, READ, ON_CHANGE, NULL); } ConnectionManager *ArduinoIoTPreferredConnection = new WiFiConnectionManager(SSID, PASS);
Main Code:
/* Sketch generated by the Arduino IoT Cloud Thing "FrontDoorSensor" https://create.arduino.cc/cloud/things/---- Arduino IoT Cloud Properties description The following variables are automatically generated and updated when changes are made to the Thing properties bool DoorOpen; Properties which are marked as READ/WRITE in the Cloud Thing will also have functions which are called when their values are changed from the Dashboard. These functions are generated with the Thing and added at the end of this sketch. */ #include "thingProperties.h" int keyIndex = 0; // your network key Index number (needed only for WEP) int inPin = 6; void setup() { // Initialize serial and wait for port to open: Serial.begin(9600); pinMode(inPin, INPUT); // sets the digital pin 6 as input // Defined in thingProperties.h initProperties(); // Connect to Arduino IoT Cloud ArduinoCloud.begin(ArduinoIoTPreferredConnection); /* The following function allows you to obtain more information related to the state of network and IoT Cloud connection and errors the higher number the more granular information you’ll get. The default is 0 (only errors). Maximum is 4 */ setDebugMessageLevel(2); ArduinoCloud.printDebugInfo(); } void loop() { DoorOpen = digitalRead(inPin); // read the input pin ArduinoCloud.update(); }
Next I will add a motion sensor, and have the program email me a message on triggered event.
Scott
Top Comments