I am making cheapest magnetic door open/close sensor now.
Module is from very cheap door sensor with light which I bought in DAISO 100yen shop.
I may send it as gmail to my phone every 30min.
Give me something cool suggestions to improve it
int ledPin = D7; // LED connected to digital pin 13
int analogPin = A1; //this pin is for door magnetic sensor
int Pin = 0; //value from A1. for door magnetic sensor close is 679
int count = 0; //this counts timing for sending info
int limitTime = 10; //time span for sending door info
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(analogPin, INPUT); //Pin for door magnetic sensor
digitalWrite(ledPin, LOW); //turn off LED for reset
Serial.begin( 9600 );
}
//when magnetic is on, analogPin is 679 ,678
void loop()
{
Serial.print("count is ");
Serial.println(count);
if(count == limitTime){ //this is counting timing for sending info
Serial.print("spent ");
Serial.print(limitTime);
Serial.println("sec, reset count now"); //reset after sending info
count = 0;
}
Pin = analogRead(analogPin);
if(4060 < Pin){
digitalWrite(ledPin, LOW);
Serial.println("Door is Close");
Serial.println(Pin);
delay(500);
count++;
}else{
digitalWrite(ledPin, HIGH);
Serial.println("Door is Open");
Serial.println(Pin);
delay(500);
count++;
}
// if(){ } //it for sending door info
}
When the door is closed, make the magnet open the power to the Core (i.e. ZERO power draw)... when the door opens, the core powers up, connects... and sends an email, then puts itself in deep sleep for 30 minutes, wakes up and sends another email, deep sleep.. repeat. Power it from 3V lithium battery directly on 3V3 pin and GND to bypass the LDO regulator that will consume too much power when the core is in deep sleep.
If the door is closed... the Core is back to zero power draw.
Sure it's going to take up to 10 seconds or so to power up, connect and send the email... but who cares it's super low power now. Peel and stick to all of your doors.
Now obviously this would be better as a lower power radio, but this is worth trying to make work for people that just need one sensor and don't want one on every door of their house.
One problem you could have with that solution is if the door can be opened and closed before the message was sent the sensor becomes fairly ineffective.
10 seconds is a long time, I think most people would open, pass though and close a door in under 10 seconds, unless they have shopping or kids
It would be better if the core could wake from hardware interrupt but nobody answered my question on that and haven’t had time to test it myself.
Good point, but it's solved already! As soon as the core gets power it controls a small mosfet that is in parallel with the normally closed reed switch. The core does not turn off that mosfet until it has sent it's email, then it can turn off the mosfet and go to sleep. If the door is closed already the core effectively turns off it's own power completely.
@Daisuke picture this... if you have a battery powering the core, and you put a switch in between the battery and the Core, you can turn it on and off. When it it off, the circuit is completely open and no power flows to the Core. Now if you replace that switch with a normally closed magnetic reed switch, when a magnet is near by it will OPEN the switch (zero power will go to the Core), and when the magnet is removed the switch will close, connecting power to the Core.
Thanks your suggestion.
I think if I use this scheme, the Core should connect to Wifi every time. It make the core to take long time to be ready to send notification every time. I am afraid a thief open door after I opened the door just in case.
If you are thinking a thief is going to be opening your door right after you've entered... I don't think an immediate email to your phone is going to help you. After you enter the door, re-lock it. Also place a baseball bat about 15 feet from the door just in case someone forces themselves in with you at the same time.
If you can't lock the door and absolutely need to send an email for every case of the door opening, and are worried about special cases like the period 1 minute after you've entered.... you could make the Core stay powered for 1 minute so it's ready to send emails quicker. You could not simply short out the reed switch with a mosfet though, because you wouldn't see the switch open. In that case you'll need to connect power to the core via a mosfet, and then after that actively switch the reed contacts to one of your digital inputs via SPDT relay, or a similar circuit with transistors perhaps. Once the core shuts off it's own power, this extra circuitry to connect the reed switch to your digital input should auto revert to the reed switch being connected to supply power to the core.