Hello,
I'm creating my first sensor which shall be a sensor monitoring multiple window sash. For that I want't to configure multiple pins as interrupt and set the arduino sleeping until one sash changes its state. Interrupts are working fine but since I'd like to power the sensor using batteries I measured the current and stated that even when thinking the sensor shall sleep it needs about 2mA (cut off power LED)
Since I read that it should be within ยตA-area I'm asking what I'm doing wrong?
Here my sketch:
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* DESCRIPTION
*
* Interrupt driven binary switch example with dual interrupts
* Author: Patrick 'Anticimex' Fallberg
* Connect one button or door/window reed switch between
* digitial I/O pin 3 (BUTTON_PIN below) and GND and the other
* one in similar fashion on digital I/O pin 2.
* This example is designed to fit Arduino Nano/Pro Mini
*
*/
#include <MySensor.h>
#include <SPI.h>
#include <EnableInterrupt.h>
#define SKETCH_NAME "Multiple Window Sensor"
#define SKETCH_MAJOR_VER "1"
#define SKETCH_MINOR_VER "0"
#define FIRST_WINDOW_ID 1
#define SECOND_WINDOW_ID 2
#define THIRD_WINDOW_ID 3
#define FORTH_WINDOW_ID 4
#define FIRST_WINDOW_PIN 4 // Arduino Digital I/O pin for button/reed switch
#define SECOND_WINDOW_PIN 5 // Arduino Digital I/O pin for button/reed switch
#define THIRD_WINDOW_PIN 6 // Arduino Digital I/O pin for button/reed switch
#define FORTH_WINDOW_PIN 7 // Arduino Digital I/O pin for button/reed switch
MySensor sensor_node;
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage first_window_msg(FIRST_WINDOW_ID, V_TRIPPED);
MyMessage second_window_msg(SECOND_WINDOW_ID, V_TRIPPED);
MyMessage third_window_msg(THIRD_WINDOW_ID, V_TRIPPED);
MyMessage forth_window_msg(FORTH_WINDOW_ID, V_TRIPPED);
void interruptFunctionFirstWindow() {
sensor_node.sleep(5);
sensor_node.send(first_window_msg.set(digitalRead(FIRST_WINDOW_PIN)));
}
void interruptFunctionSecondWindow() {
sensor_node.sleep(5);
sensor_node.send(second_window_msg.set(digitalRead(SECOND_WINDOW_PIN)));
}
void interruptFunctionThirdWindow() {
sensor_node.sleep(5);
sensor_node.send(third_window_msg.set(digitalRead(THIRD_WINDOW_PIN)));
}
void interruptFunctionForthWindow() {
sensor_node.sleep(5);
sensor_node.send(forth_window_msg.set(digitalRead(FORTH_WINDOW_PIN)));
}
void setup()
{
sensor_node.begin();
// Setup the buttons
pinMode(FIRST_WINDOW_PIN, INPUT_PULLUP);
pinMode(SECOND_WINDOW_PIN, INPUT_PULLUP);
pinMode(THIRD_WINDOW_PIN, INPUT_PULLUP);
pinMode(FORTH_WINDOW_PIN, INPUT_PULLUP);
// Send the sketch version information to the gateway and Controller
sensor_node.sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER"."SKETCH_MINOR_VER);
// Register binary input sensor to sensor_node (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
sensor_node.present(FIRST_WINDOW_ID, S_DOOR);
sensor_node.present(SECOND_WINDOW_ID, S_DOOR);
sensor_node.present(THIRD_WINDOW_ID, S_DOOR);
sensor_node.present(FORTH_WINDOW_ID, S_DOOR);
enableInterrupt(FIRST_WINDOW_PIN, interruptFunctionFirstWindow, CHANGE);
enableInterrupt(SECOND_WINDOW_PIN, interruptFunctionSecondWindow, CHANGE);
enableInterrupt(THIRD_WINDOW_PIN, interruptFunctionFirstWindow, CHANGE);
enableInterrupt(FORTH_WINDOW_PIN, interruptFunctionSecondWindow, CHANGE);
}
// Loop will iterate on changes on the BUTTON_PINs
void loop()
{
sensor_node.sleep(0, CHANGE, 1, CHANGE, 0);
}
Could anybody help me finding the problem?
Thanks in advance
Ronny