× General topics about hardware.

Multiple door sensors

5 years 6 months ago #3089 by DaTT
Multiple door sensors was created by DaTT
How can I do multiple door/window sensors on single low power Arduino NRF24L01 ? Add another sensor and the resistor to the pins ( 2, 4, 5, 6, 7, 8 ) ? But how to modify the code for the Arduino? Thank you

I'm sorry for my poor english. I speak Czech.

Please Log in or Create an account to join the conversation.

4 years 10 months ago #3559 by timr
Replied by timr on topic Multiple door sensors
I assume no one replied?

I've started looking at the same. The problem I see is that the code writes the unit address to the Flash, Ideally we want to write reserve 3 consecutive addresses, but then send to each one dependent on trigger.

I managed to get the 3 addresses to register, I just haven't had time to take it further yet.
// Simple binary switch example 
// Connect button or door/window reed switch between 
// digitial I/O pin 3 (BUTTON_PIN1 below) and GND.

#include <avr/sleep.h>    // Sleep Modes
#include <MySensor.h>
#include <SPI.h>
#include <Bounce2.h>

#define CHILD_ID1 3
#define CHILD_ID2 4
#define CHILD_ID3 5

#define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
MySensor gw;

#define INTERRUPT_SENSOR  1 // Interrupt 1 is on DIGITAL PIN 3!
#define SLEEP_IN_MS 86400000 // 1 day

byte val;
int oldBatLevel;

Bounce debouncer = Bounce(); 
int oldValue=-1;

// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msg(CHILD_ID1,V_TRIPPED);
MyMessage msg2(CHILD_ID2,V_TRIPPED);
MyMessage msg3(CHILD_ID3,V_TRIPPED);

void setup()  

 // Setup the button
  // After setting up the button, setup debouncer

  // Register binary input sensor to gw (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.
  gw.present(CHILD_ID1, S_DOOR);
  gw.present(CHILD_ID2, S_DOOR);
  gw.present(CHILD_ID3, S_DOOR);  

  val = digitalRead(BUTTON_PIN);
  oldBatLevel = -1;  


//  Check if digital input has changed and send in new value
void loop() 
  // Get the update value
  int value = debouncer.read();
  if (value != oldValue) {
     // Send in the new value
     gw.send(msg.set(value==HIGH ? 1 : 0));
     oldValue = value;

void sendValue()
  gw.send(msg.set(val==HIGH ? 1 : 0));
  // Here is where we want to add the extra sensors and the GW.send address needs to change.

  int batLevel = getBatteryLevel();
  if (oldBatLevel != batLevel)
    oldBatLevel = batLevel;

// Battery measure
int getBatteryLevel () 
  int results = (readVcc() - 2000)  / 10;   

  if (results > 100)
    results = 100;
  if (results < 0)
    results = 0;
  return results;
} // end of getBandgap

// when ADC completed, take an interrupt 

long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  noInterrupts ();
  // start the conversion
  ADCSRA |= _BV (ADSC) | _BV (ADIE);
  set_sleep_mode (SLEEP_MODE_ADC);    // sleep during sample
  interrupts ();
  sleep_mode (); 
  // reading should be done, but better make sure
  // maybe the timer interrupt fired 
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result; // Back-calculate AVcc in mV

  return result;

Please Log in or Create an account to join the conversation.

4 years 10 months ago #3560 by timr
Replied by timr on topic Multiple door sensors
Screenshot of the added modules....

Please Log in or Create an account to join the conversation.

Time to create page: 0.175 seconds