Simple door open alarm

This is my first Arduino project. I know, door alarm is not a unique project here :), but I could not find answers to my questions.
So what I want is a system with 2 parts: the first one is running on computer that receives some signals wirelessly about door being closed or opened. Another module is obviously sending these signals when it detects that door position changes. The important thing is that the door module should be autonomous, i.e. it should work on battery and it should be able to live on a single battery for at least several months.

Now I have a prototype on my breadboard with Atmega168 programmed (I flashed it with Arduino bootloader) that tracks INT0 pin change. By default (when the door is closed) INT0 is in HIGH state and MK goes to sleep. When the door opens, the circuit from INT0 to +5V breaks and MK wakes up, sends a signal via HC-06 bluetooth and waits until the door closes again. Then it sends "closed" signal and goes to sleep again. Works fine, but not ideal. Here is what bothers me, some things I'm not sure how to fix:

  1. I want the door module to run on CR2032 battery (3V). Currently the module does not start from 3V battery, I guess I need to lower the clock frequency. Currently it is running from 8Mhz internal Oscillator and divide by 8 bit is on. Should I change it to 128KHz? I will need to compile the bootloader or can I still use Arduino IDE without Arduino bootloader on Atmega168? Should I maybe use another MK like ATTiny?
  2. The current in sleep mode is 0.5mA, that's too much. CR2032 is 240mAh, so it means the module will die in less than 480 hours, most likely twice as fast. Maybe I'm doing something wrong with INT0 pin. It is connected with 10KOhm resistor to the ground and the switch is from INT0 to +5. Should I use bigger resistor? 1MOhm maybe?
  3. Maybe bluetooth transceiver is not a good option? Any other suggestions? I just need to send couple of bytes and the module should not verify if receiver gets them. Bluetooth is too complex, with all the pairing, instability.

Thank you!

As far as I know there is no way to power an arduino from a 3v supply. There are low power attinys that will run down to lower voltages but you might need a boost regulator to get a good supply as the battery slowly dies. As far as battery life, there is really no way you are going to get "several months" of battery life out of a CR2032 battery powering an Atmega and a bluetooth module. According to the data sheet for the HC-06, it has a constant current consumption of 8mA, no matter if it is transmitting or not. I would suggest using a larger battery, perhaps a Li-ion like are commonly used in cell phones. Check out this, https://www.sparkfun.com/tutorials/309, thread, it has some good explanations of power saving techniques for the Atmega. Good luck! Sounds like an interesting project.

smokxx:

  1. I want the door module to run on CR2032 battery (3V). Currently the module does not start from 3V battery, I guess I need to lower the clock frequency. Currently it is running from 8Mhz internal Oscillator and divide by 8 bit is on. Should I change it to 128KHz? I will need to compile the bootloader or can I still use Arduino IDE without Arduino bootloader on Atmega168? Should I maybe use another MK like ATTiny?

You are unlikely to get months out of a CR2032 even if you could power it. That is only 225mAh. That means if you draw 225mA constantly for one hour, the battery is dead. A picopower AVR might give you more time, but this is still not an ideal battery if you want months of operation. I also suggest using a cellphone battery. Your circuit is only going to be so small with an ATMega168 and HC05 module. A cellphone battery will probably be smaller than your circuit.

  1. The current in sleep mode is 0.5mA, that's too much. CR2032 is 240mAh, so it means the module will die in less than 480 hours, most likely twice as fast. Maybe I'm doing something wrong with INT0 pin. It is connected with 10KOhm resistor to the ground and the switch is from INT0 to +5. Should I use bigger resistor? 1MOhm maybe?

Ahh.... I see you noticed that. The reason the sleep mode still draws alot of power is because of the regulator. As for the HC-05, you could simply control its ground connection with a transistor so it is only powered when you want to send.

  1. Maybe bluetooth transceiver is not a good option? Any other suggestions? I just need to send couple of bytes and the module should not verify if receiver gets them. Bluetooth is too complex, with all the pairing, instability.

Bluetooth does suck for that reason. Not to mention the range. See if you can find a zigbee module with a shutdown.

smokxx:

  1. Should I change it to 128KHz? I will need to compile the bootloader or can I still use Arduino IDE without Arduino bootloader on Atmega168? Should I maybe use another MK like ATTiny?

Missed this part. At 128Khz, you probably couldn't get serial to run (definitely not using the Arduino code) which you need for the HC-05 module. And yes, you would have to create bootloader for it (but only if you wanted to use serial programming.) You can write your program and upload it with programmer without the bootloader, though. The bootloader is only needed for uploading over the serial connection.

I wonder whether it might be more practical to use a simple electrical solution, using a low power radio transmitter that is powered via a switch (zero power draw in the 'closed' position) and design a receiver that simply detects the presence or absence of the signal. The battery life would be determined by the cumulative time the door was left open, and the battery leakage current. How practical this is would depend on the range between the door and the receiver. You might be able to extend the battery life by including a timer so that the device only transmits intermittently.

I don't know whether it's possible to produce a passive transponder that works over the range you need, but I wonder whether it might be possible to use RFID type technology incorporating a switch to disable the transponder. That would only give you a range of a few inches, and might not be practical at all, but has the potential for a battery-less solution.

Retroplayer:
You are unlikely to get months out of a CR2032 even if you could power it. That is only 225mAh. That means if you draw 225mA constantly for one hour, the battery is dead. A picopower AVR might give you more time, but this is still not an ideal battery if you want months of operation. I also suggest using a cellphone battery. Your circuit is only going to be so small with an ATMega168 and HC05 module. A cellphone battery will probably be smaller than your circuit.
...
Ahh.... I see you noticed that. The reason the sleep mode still draws alot of power is because of the regulator. As for the HC-05, you could simply control its ground connection with a transistor so it is only powered when you want to send.

It should not be the regulator, because it's on arduino board, and my scheme is completely on a breadboard (I should probably draw my scheme and post it). Breadboard gets power from arduino +5V pin and I measure current between this pin and my breadboard. I also tried to build a minimum circuit (without bluetooth, led etc.) and programmed MK to just go to sleep permanently. In this mode, the current was only 0.5uA, that is, 1000x less than in my current scheme! Now I'm almost sure 0.5mA was the current between +5V and GND via 10kohm resistor, +5V is also connected to INT0 pin making its state HIGH. When door opens, it becomes low and MK wakes up. That's why I'm thinking about using 1MOhm resistor or even more?

Regarding 3V battery, MK should be almost always in sleep mode and goal current in this mode is about 1uA, it should live on such current for months, right? Of course if I power down bluetooth too or choose another protocol for wireless transmission.

I didn't think about transistor, frankly, I'm not sure I understand correctly how it should work or which transistor to use. I should read about transistors :slight_smile:

Bluetooth does suck for that reason. Not to mention the range. See if you can find a zigbee module with a shutdown.

Zigbee is a new word for me, thank you, I'll check it out :slight_smile: On some thread I also read about this RF Link transmitter 315Mhz: RF Link Transmitter - 315MHz - WRL-10535 - SparkFun Electronics, maybe it will work instead of overcomplicated bluetooth module? (for my tasks)

ookid, thanks for the link to the article, will read it right now.

PeterH, when you're saying "low power radio transmitter" what do you mean exactly? I got the idea, it's interesting, but this design while simplifies transmitter module, complicates receiver, it should be always on to not miss anything. I'll think about it. With my bluetooth scheme I was thinking about sending last 10-20 open/close events to the receiver with timestamps, so that if for some reason receiver was off during some door open events, it should be able to catch up.

Is it possible to use reed switch to connect INT0 and GND when the door opens? The switch itself should not need any power when door is closed, right?

smokxx:
It should not be the regulator, because it's on arduino board, and my scheme is completely on a breadboard (I should probably draw my scheme and post it). Breadboard gets power from arduino +5V pin and I measure current between this pin and my breadboard. I also tried to build a minimum circuit (without bluetooth, led etc.) and programmed MK to just go to sleep permanently. In this mode, the current was only 0.5uA, that is, 1000x less than in my current scheme! Now I'm almost sure 0.5mA was the current between +5V and GND via 10kohm resistor, +5V is also connected to INT0 pin making its state HIGH. When door opens, it becomes low and MK wakes up. That's why I'm thinking about using 1MOhm resistor or even more?

Regarding 3V battery, MK should be almost always in sleep mode and goal current in this mode is about 1uA, it should live on such current for months, right? Of course if I power down bluetooth too or choose another protocol for wireless transmission.

I didn't think about transistor, frankly, I'm not sure I understand correctly how it should work or which transistor to use. I should read about transistors :slight_smile:

Bluetooth does suck for that reason. Not to mention the range. See if you can find a zigbee module with a shutdown.

Zigbee is a new word for me, thank you, I'll check it out :slight_smile: On some thread I also read about this RF Link transmitter 315Mhz: RF Link Transmitter - 315MHz - WRL-10535 - SparkFun Electronics, maybe it will work instead of overcomplicated bluetooth module? (for my tasks)

ookid, thanks for the link to the article, will read it right now.

PeterH, when you're saying "low power radio transmitter" what do you mean exactly? I got the idea, it's interesting, but this design while simplifies transmitter module, complicates receiver, it should be always on to not miss anything. I'll think about it. With my bluetooth scheme I was thinking about sending last 10-20 open/close events to the receiver with timestamps, so that if for some reason receiver was off during some door open events, it should be able to catch up.

Is it possible to use reed switch to connect INT0 and GND when the door opens? The switch itself should not need any power when door is closed, right?

The pullup might be your problem then. Maybe arrange the switch so it goes high when the door opens instead. Then no power is going through the switch otherwise.

A transistor is just a volatge controlled switch. When you apply some current to the base, it allows current to flow from the emitter to the collector. The bluetooth module uses 5mA? Just about any transistor would work for that. You just put the collector on the ground pin of the module, and the emitter to Arduino ground. Use an appropriate resistor so that it supplies enough current to saturate the transistor when you send HIGH on the base going to your arduino.

An RF link may be fine. The range is not always great on them, though. It might work and they are cheap to try. I don't know where you live, but sparkfun sells them very cheap.

I have done almost the same thing with a similar project. I am having other issues, but I got the sleep code with sub uA current to work. I'm using the internal pullup resistor on the INT0 pin, and my pushbutton switch grounds it through an external resistor when I want to wake up. My ammeter registers 0.3 uA current during sleep mode. I'm using an ATTiny44A.

Retroplayer, I can't arrange the switch so that INT0 goes to HIGH when the door opens, because MK can wake up only on LOW on INT0. So most of the time (i.e. when the door is closed) INT0 should have HIGH state. This means that when the door is closed, INT0 and GND should be disconnected. I was thinking about reed switch, but most of them are normally opened, can't find normally closed yet.

TanHadron, glad to know that you've succeeded with low current task. What is the goal of your project?

I was just looking in a datasheet for something else in the AVR and noticed that it said current consumption during sleep mode would be higher if the internal pullup was set. It would seem that you are going to always drw some current with a pullup at all.

Looking at the datasheet, I don't see any reason that you cannot interrupt on a HIGH signal during sleep. In fact, if you read the section on power management and sleep modes, it is suggested. Also, before issuing the _sleep() command, you should set the appropriate registers in the MCUCR and make sure things that would be left running and not needed are turned off.

Also, why do you need a normally closed reed switch? It's all in how you wire it up. You can use either just fine. Typically, for a pullup configuration you should have a normally open anyway.

Maybe we need to see your wiring to help... but get the datasheet for the AVR that you are using and read the power management section.

My project is a modified blinking LED flashlight. I'm having other issues, but at least I got this part working.

My understanding is that the internal pull-up doesn't use much power unless you're grounding the pin externally. The data sheet says, "As inputs, Port A pins that are externally pulled low will source current if the pull-up resistors are activated." It also says, "If some pins are unused, it is recommended to ensure that these pins have a defined level. Even though most of the digital inputs are disabled in the deep sleep modes as described above, floating inputs should be avoided to reduce current consumption in all other modes where the digital inputs are enabled (Reset, Active mode and Idle mode). The simplest method to ensure a defined level of an unused pin, is to enable the internal pull-up."

So if it's normally open, the pull-up keeps the pin high, and the power being used is minimal. When I push my button, the pin goes low through my external resistor, and is uses more power. But then I don't care much because nobody is going to be holding the button in.

Your door may be different if the door gets left open a lot.

Retroplayer:
I was just looking in a datasheet for something else in the AVR and noticed that it said current consumption during sleep mode would be higher if the internal pullup was set. It would seem that you are going to always drw some current with a pullup at all.

Looking at the datasheet, I don't see any reason that you cannot interrupt on a HIGH signal during sleep. In fact, if you read the section on power management and sleep modes, it is suggested. Also, before issuing the _sleep() command, you should set the appropriate registers in the MCUCR and make sure things that would be left running and not needed are turned off.

Also, why do you need a normally closed reed switch? It's all in how you wire it up. You can use either just fine. Typically, for a pullup configuration you should have a normally open anyway.

Maybe we need to see your wiring to help... but get the datasheet for the AVR that you are using and read the power management section.

Here is a quote from section 12 External interrups:
[quoteWhen the INT0 or INT1 interrupts are enabled and are configured as level triggered, the interrupts will trigger as long as the pin is held low. Note that recognition of falling or rising edge interrupts on INT0 or INT1 requires the presence of an I/O clock, described in ”Clock Systems and their Distribution” on page 26. Low level interrupt on INT0 and INT1 is detected asynchro- nously. This implies that this interrupt can be used for waking the part also from sleep modes other than Idle mode. The I/O clock is halted in all sleep modes except Idle mode.

That's also what people are saying on other threads: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=39332

I was thinking about normally closed switch because I can put it between INT0 and GND, removing the connection between INT0 and +5V and using internal pull-up to keep INT0 HIGH when the switch is open. The logic here is that I need to have INT0 high by default (when the door is closed) so INT0-GND must be disconnected. When door opens, magnet goes away from the switch and it closes (normally closed switch) and MK wakes up.

Yes, I can do it the other way: the reed switch is between INT0 and +5V, closed when the door is closed (magnet nearby), so the INT0 state is HIGH and MK is sleeping. INT0 is also connected to GND via 10kohm resistor.

I ordered some parts (RF link, USB FTDI cable, reed switches, ISP programmer, 500K resistors), will post an update when I get them and try various options.

I stand corrected. Apparently I missed that part regarding the two modes. Hmm...

I was thinking about normally closed switch because I can put it between INT0 and GND, removing the connection between INT0 and +5V and using internal pull-up to keep INT0 HIGH when the switch is open. The logic here is that I need to have INT0 high by default (when the door is closed) so INT0-GND must be disconnected. When door opens, magnet goes away from the switch and it closes (normally closed switch) and MK wakes up.

This is how my circuit works. Well, except I have a resistor between the switch and the GND.

I bought one of those door alarms at the $1 store, thinking it might be powered by a Hall effect sensor. It was just some magnetic wire. It would be really easy to bend the wire in another direction so that when the magnet is there it isn't touching, and when the magnet moves the wires touch.