CR2032 powered door sensor?

Hi is it possible to buld a CR2032 powered door sensor that reports everytime a door is opened wirelessly and have the battery last for several months/years?

I was thinking maybe a magnetswitch or simply a microswitch that is pressed against the door when it is closed.

This is routinely done with burglar alarm systems. However I doubt if it will work for a few months using an Arduino.

Weedpharma

It is possible, but it will take a lot of work on energy management. The wireless transmitter needs to be turned off whenever possible, except when actually transmitting. The processor will have to use low power sleep modes and be in deep sleep 99.9% of the time. The power supply will have to be very efficient with very low current leakage. It can be done, but a typical Arduino with a WiFi or Bluetooth shield isn't going to cut it.

The concept is simple, and the basic code will be the easy part. The difficult part here is power management.

just buy a door sensor. the wireless is built in. some things are better off not re-invented.

since all that is needed is for the wireless part to transmit every time the switch changes, you only need a switch, a timer and a transmitter. the power of the transmitter will by your largest load.

I was thinking this could be my first arduino project as it seamed simple in theory, but is seams I was wrong :slight_smile:

But just for example if I wanted to build it just to learn would these parts be suitable?:

Arduino Pro Mini 3.3V
NRF24L01+
Microswitch

Or if I where to buy a cheap door sensor how can I make any of the examples flash a led on another arduino when door opens wirelessly?

as a first project, it would be great. you could add solar power ?

there are lots of reed switches, this is again, better to by those
my dollar store here in the States, sells a door alarm. it has a reed switch, and a buzzer. as long as the door is open, the buzzer goes off. you can just use the device as a switch.

http://www.ebay.com/itm/400764332517 for a hidden and paintable switch. put in the hinge side to conceal completely.

burton666:
I was thinking this could be my first arduino project as it seamed simple in theory, but is seams I was wrong :slight_smile:

It's a very doable project, if you get rid of the requirement to power it from a coin cell for a year. You will either need much more power than that, or you will need to spend most of your effort making the project consume as little power as possible.

But just for example if I wanted to build it just to learn would these parts be suitable?:

Reasonable parts. You may wants consider a reed switch which uses a magnet to activate it, rather than a micro switch with a lever. It will be easier to install, and is what most alarm systems use. Reed switches with a matching magnet for doors and windows are readily available.

Or if I where to buy a cheap door sensor how can I make any of the examples flash a led on another arduino when door opens wirelessly?

I assume you mean an existing wireless door sensor? The trick there is going to be receiving the signal. If it includes a receiver I both a set of relay contacts, it's a trivial project. If there is no receiver included, it gets more complicated, and using a pair of Arduinos and RF transceivers may be easier and more fun.

If you want to run the receiver off of a battery, you're going to need something to switch the radio power off. And you will still want to use low power standby modes as much as possible in the processor. If you can use an AC wall wart power supply, the power management concerns are not important.

For the receiver side, you will want to power that off of a wall wart or a very substantial battery. That's because you won't be able to turn off the receiver radio to save power - it needs to be on and receiving all of the time in order to pick up the transmitter's signal.

This sounds like an interesting project: simple enough to not be overwhelming, but enough technical challenges to make it interesting. Just start out with a solid unlimited power supply (wall wart or USB) to get it working, and then move to batteries as you refine the power budget. As you improve the power utilization, you may get to the point where you can use smaller batteries, but don't expect to get to a coin cell without spending quite some effort.

Resurrecting an old thread, but..

I recently opened up one of these reed switchin', data transmitterin', door sensors.
Quite amazed at just how miniscule the whole circuit is and wondered if anyone had an insight as to how it can be so efficient as well as how, and what sort of data it might transmit? (relatively powerfully too - threw a bunch of walls)

Firing small amounts of data around the place (offline) is always a fun basis for project inspiration

entozoon:
Quite amazed at just how miniscule the whole circuit is and wondered if anyone had an insight as to how it can be so efficient as well as how, and what sort of data it might transmit? (relatively powerfully too - threw a bunch of walls)

The main data sent is probably a message when the trigger switch is activated or restored. It will probably also send identification messages when it is configured. There will probably also be messages sent when the battery is low. There could be periodic messages sent to indicated routine battery level and status, but in order to minimize battery power usage, these will likely not be sent frequently.

As to how it can be so efficient, some insights are earlier in this thread:

ShapeShifter:
It is possible, but it will take a lot of work on energy management. The wireless transmitter needs to be turned off whenever possible, except when actually transmitting. The processor will have to use low power sleep modes and be in deep sleep 99.9% of the time.

The key is to keep as much circuitry powered off as long as possible. The biggest energy user in a system like this will be the radio transmitter. It should be off and using minimal power except when it is actually transmitting. The power switch to it needs to be very low leakage (every microamp makes a difference in a circuit like this.)

The processor should be in its lowest power sleep mode as much as possible. Ideally, the reed switch (glass tube on the left side) that activates the sensor should generate an interrupt that can wake it from sleep so that the processor doesn't have to wake up and poll the switch periodically.

It looks like there is a switch in the middle, presumably to configure the device. That switch will also ideally generate an interrupt to wake from sleep so it doesn't need to be polled.

If it periodically measures battery power, it is likely that there will need to be some sort of voltage divider (either internal to the processor or external.) If internal, it should only be enabled when an actual voltage measurement is taking place. If external, even if it is using large value resistors, it will be a significant voltage drain compared to the processor in sleep mode - it will also likely have a transistor to switch it off when a voltage measurement is not taking place, and the transistor should also have low leakage while it is off. There will likely be an internal timer that generates an interrupt to wake the processor when it's time to measure the battery.

The general concepts to keep in mind when designing a battery operated device that has a minimal amount of energy like a coin cell:

  • Run the processor at the slowest speed that gets the job done - the faster the clock, the higher the power consumption
  • Keep the processor in low power sleep mode as much as possible - avoid loops for delays, use internal timers that generate interrupts to wake the processor
  • Use interrupts when possible to wake the processor rather than polling for inputs
  • Keep any external devices (sensors, radios, voltage dividers, etc) off whenever possible
  • Look for and eliminate any phantom current drains: LEDs, voltage dividers, pullup resistors, etc (use pulldowns instead of pullups whenever possible - for switches, use a pulldown and connect the switch so it is high when active, instead of a pullup and grounding the input: if the processor does not have internal pulldowns, use an external resistor)

In summary, every microamp of current drain, and every waking clock cycle, takes power - always try to minimize both to minimize overall power consumtion.

I agree with most of said but:
You should use FASTEST clock speed possible - when executing you consume static AND dynamic power. While the dynamic power is roughly the same for the same amount of work the static dissipation depends on the time the CPU is powered (not in sleep). Ofc this is true only if you can truly sleep when not working - no busy wait loops, no polling for something done, no long waiting for a crystal to stabilize every wake up.

Also I don't see why pullup is worse than a pulldown? There may be leakage from the Vcc as well as from GND.

Another important factor is the supply voltage. Higher voltage means higher current(!) needed by nearly all parts.

And note: 1uA of average current consumption is about 10mAh per year.

Smajdalf:
You should use FASTEST clock speed possible - when executing you consume static AND dynamic power.

We can agree to disagree on this. I've had my best battery performance running with a watch crystal and a 32 kHz clock. Looking at the datasheet for the MSP430 processor I used in my last very low power project, and plotting frequency vs power consumption, it is fairly linear until getting to the last 20% of the frequency range, at which point the power consumption is higher than the linear trend. So, for that particular processor, if only looking at the CPU power consumption, there is no overall penalty for going up to 80% of the max frequency range - any increase over that increases the overall CPU power consumption.

But there is more to it than just the CPU: all of the other peripherals will also be running at a higher frequency, and thus drawing more power. Also, if you are running timers to control operations over longer periods, that means you have to either increase a prescaler count (which draws more power) or you will have to wake up more frequently, which causes more instruction cycles and more power consumption.) In my last project, I had some periodic operations to perform, and I used a timer to periodically wake up the processor. At a 32 KHz clock, the longest interrupt period I could program in the counter was shorter than my desired processing interval. So I had to periodically wake up, update a counter, and perform my processing on every Nth interrupt. If the clock speed were faster, I would have had to been woken up many more times and use a higher N counter value, and each of those additional wake cycles would've been wasted power.

Granted, there may be situations where the wake cycle requires additional circuitry to be powered up, and it may be desirable to increase the processor clock so that the time the circuitry is on is minimized. But that needs to be traded off against other factors, like how much power timer interrupts will use up between those high current events. There is no one answer for every project: each project must be properly engineered taking the project-unique trade-offs into account.

For a product like the one being discussed in the prior post, the transmitter does take a significant amount of power, but the time that is spent transmitting is likely to be very small compared to other operations - it is those other operations that likely take a higher amount of power, on average.

Ofc this is true only if you can truly sleep when not working - no busy wait loops, no polling for something done, no long waiting for a crystal to stabilize every wake up.

Agreed!

Also I don't see why pullup is worse than a pulldown? There may be leakage from the Vcc as well as from GND.

Again, engineering must be done to consider specific circumstances. But consider the case of a pushbutton switch that needs to wake the processor to perform a specific operation:

  • If it is wired in the typical configuration that uses the processor's internal pullup resistor with the switch shorting the input to ground when closed, then there is likely to be some leakage current from Vcc through the resistor to ground, and this will be happening 24/7/365. That current will add up over time.
  • If it is wired with an external pulldown resistor to ground, with the switch providing Vcc when pressed (preferably through a current limiting resistor) then there will be no significant current flowing from Vcc to ground until the switch is closed (there could be some slight internal leakage current to ground through the pulldown, but this is likely to be minimal compared to the current flowing from Vcc through a pullup resistor.) The assumption here is that the switch is closed with a very low duty cycle like the configuration button in the middle of the product pictured in the prior post. In the case of the reed switch which is normally closed by an external magnet, this would not be a good configuration - again, a proper engineering analysis needs to be done for every subsystem of every project.

Another important factor is the supply voltage. Higher voltage means higher current(!) needed by nearly all parts.

Agreed!

Temperature is another variable - many parts will draw higher currents as the temperature increases, so proper cooling of the device can make a difference. Proper assembly techniques can also make a difference: not cleaning off flux or other contaminants can cause a leakage path that wastes power.

What I listed in my prior post was a set of guidelines I try to follow when designing very low power projects. There are always exceptions depending on the particular needs of a project.

ShapeShifter:
...then there is likely to be some leakage current from Vcc through the resistor to ground, ...

You can argue there is some small current from the pull-up resistor to GND. But what prevents current to leak from Vcc to pull-down resistor and to GND?

@clock speed - I based this on my experience with AVR. From my experience current consumption per MHz goes up as you reduce clock speed. I concluded power saving may be rarely achieved by reducing clock speed by the prescaler. Maybe switching from 8MHz oscillator to the 128kHz (or maybe using watch crystal). So far I consider external 32kHz crystal for asynchronous sleep timing (<1uA of current) + internal 8Mhz oscillator (prescaled down to 4Mhz to be able to operate around 2V) as most efficient in AVR world. But in given application processor awake time should have average current consumption in order of nAs so this debate is academic.

A) When you say "wireless" do you mean 433MHz?
B) Or can you have a 433MHz to Wifi bridge?
C) Or do you want direct to Wifi device?

Case A:

An Attiny85 with a basic 433MHz Tx. The Tx can be turned on only when needed (transistor). ATTiny85 current use is minuscule in sleep mode (about 3uA maybe?).
Door opens say once every 30 minutes? This is where things get speculative.

With a reed switch, the ATTiny can be awoken, turn on the 433MHz Tx and send a simple byte (manchester encoding maybe?) then go back to sleep. Say it is on for 0.1s.
0.2s every hour = about 6e-5% of the time it is using say 100mA (a capacitor may be needed to store some power for the Tx as the battery is only good for ~10mA draw).

(100mA * 6e-5) + (3uA * (1 - 6e-5)) =~ 9uA draw

120mAH / 9uA =~13,333 hours = about a year and a half? So with very clever design, you may make near a year?

With such a low power system, a solar panel + capacitor may be a nice way to keep that Tx cap topped up rather than relying on the CR2032 so much...with say a 10k resistor to "trickle" charge the power cap. The cap has leakage mind...so decent caps would help?

B) Same as A...but you'd need a repeater powered seperatly that can take the bytes from different doors and talk to a router.
ESP8266 may be ideal with a 433MHz reciever.

C) ESP8266. Again, uses very little power but you won't be getting anywhere near a year off a CR2032! I manage about 3-4 months on 4AA batteris with about 5 sensors read and sent to a SQL database every 15 minutes.