Author Topic: Tino MagicCarpet - The automatic heated carpet  (Read 4280 times)

joelucid

  • Hero Member
  • *****
  • Posts: 868
Tino MagicCarpet - The automatic heated carpet
« on: December 14, 2015, 04:45:18 AM »
I tend to get cold feet in the winter at the computer. So I bought a heated carpet last year. Unfortunately I keep forgetting to switch it off - most recently during a 2 week vacation! This needed to be fixed.

I had a few requirements: I want to manually decide when I need the carpet - I don't need it in the summer and in the winter I only need it when I'm cold. I only want to spend the 100W on heat when I'm at the desk, so the carpet should automatically switch off when I'm away. But it should automatically come back on when I return. In the evening it should power off completely so I have to manually switch it on again the next day.

Meet Tino MagicCarpet, the automatic heated carpet:



Basis is a Tino, powered by 2x aaa lithium, which sits on my desk.

A PIR (HC-SR501) with regulator and diode removed is powered via GPIO and feeds into INT1. The carpet is hooked up to a  433Mhz RF outlet, which can be controlled by the RFM69HW as described in https://lowpowerlab.com/forum/index.php/topic,1115.msg7221.html#msg7221.

The Tino normally sits in ListenMode, with the PIR switched off, expending around 3uA which is fine for a long and warm summer  ;). When I'm cold I send a command to it to switch the carpet on. That causes the mote to switch the carpet on and enable the PIR. Also the Mote switches the WDT on to monitor the PIR. The PIR has been configured to the shortest possible On period and not to retrigger during the On state.

If the PIR sends no signal for 1 minute the mote switches the carpet off, but leaves the PIR on. When new PIR activity comes in, the carpet switches back on. After 1 hour of inactivity the PIR gets powered down and needs to be reactivated next morning by sending the heat command to the mote in ListenMode.

Pretty simple, but it actually took 1/2 day to get to work properly: The PIR would just always trigger when the rfm69hw went into TX to control the carpet or update status. I don't think this is caused by VCC drop: an oscilloscope trace didn't show any impact at the PIR. Also RX did not cause false triggers. But it's also not clear it's RF: i put another Moteino right next to the PIR and had it blast into it - no false triggering.

Anyway, I had to disable all status updates while the PIR is on and ignore PIR interrupts during carpet control and it now works fine.

From a battery budget perspective I expect this setup to last at least 2 years. We'll see.

Definitely more fun than doing my taxes - which was what I had planned to do yesterday  :)

Joe
« Last Edit: December 14, 2015, 05:47:33 AM by joelucid »

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Tino MagicCarpet - The automatic heated carpet
« Reply #1 on: December 14, 2015, 07:55:25 AM »
I tend to get cold feet in the winter at the computer.
I hear this is a problem when you get old...  ;)

Nice project, good job.

Weird about the false triggers on the PIR.   Could it be the relay in the RF outlet?

Tom

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Tino MagicCarpet - The automatic heated carpet
« Reply #2 on: December 14, 2015, 11:04:37 AM »
@joe Nice project, and thanks for the write-up! 

Out of curiosity, what is the current drain of your modified PIR?  I ask because it sounds as though you've probably already measured it.  In case you're  interested for any of your future PIR-related projects, I did manage to find a COTS PIR motion detector that most of the time consumes 3.5-8uA (https://lowpowerlab.com/forum/index.php/topic,1265.msg8935.html#msg8935), though it's obviously more expensive.
« Last Edit: December 14, 2015, 11:13:10 AM by WhiteHare »

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Tino MagicCarpet - The automatic heated carpet
« Reply #3 on: December 14, 2015, 11:57:27 AM »
Quote
Weird about the false triggers on the PIR.   Could it be the relay in the RF outlet?

You know, funny thing: it seems to be VCC after all. I can trigger the PIR just by adding a delay(3) to the ListenMode code without any TX. So bottom line you should use a regulator with a PIR.

Interesting to see a case where the bare bones 2x aaa, no regulator approach does not work well. Only remove the PIR regulator if you have one on the MCU. Or be prepared for nasty workarounds.

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Tino MagicCarpet - The automatic heated carpet
« Reply #4 on: December 14, 2015, 12:00:48 PM »
Quote
Out of curiosity, what is the current drain of your modified PIR?

It draws around 50uA when inactive. When it activates it goes to around 150uA. Not too bad, but I remember your earlier posts about the low power ones. I just used what was on hand here.

Joe

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Tino MagicCarpet - The automatic heated carpet
« Reply #5 on: December 14, 2015, 06:45:47 PM »
You know, funny thing: it seems to be VCC after all. I can trigger the PIR just by adding a delay(3) to the ListenMode code without any TX. So bottom line you should use a regulator with a PIR.
I'm not seeing the connection here.  Why do you think it's a VCC issue when it triggers after the delay?
Quote
Interesting to see a case where the bare bones 2x aaa, no regulator approach does not work well. Only remove the PIR regulator if you have one on the MCU. Or be prepared for nasty workarounds.
I presume you're using Lithium AAAs so it seems unlikely to be insufficient voltage at the PIR unless you have a wiring issue. 

I haven't worked with PIRs but the currents you've cited wouldn't lead me to conclude a VCC issue unless I actually scoped it.

Tom

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Tino MagicCarpet - The automatic heated carpet
« Reply #6 on: December 15, 2015, 02:19:13 AM »
Quote
I'm not seeing the connection here.  Why do you think it's a VCC issue when it triggers after the delay?

Sorry, I didn't provide enough context. Here's what I'm seeing: I have a central loop in my library that enters listen mode, sleeps the 328p, on wakeup leaves listen mode, calls sensor specific code and then starts back at the beginning.

Now the PIR sensor code has 3 ways of being called:

1.) Triggered by a listen mode wakeup burst
2.) Triggered by the WDT
3.) Triggered by PIR interrupt

As I described I get false alarms whenever I do any TX. But now I've also noticed that a false wakeup occurs whenever the WDT triggers. However it's doesn't occur when a listen mode wakeup happens. In both cases no TX happens, because the PIR is switched on (my previous workaround).

When analyzing the code paths I noticed that the only significant difference was a LED blink in the WDT code path. Now the Tino doesn't even have an LED. So I commented the GPIO code out and only left the 3ms delay of the blink and it would still cause INT1 to rise. Without the 3ms delay no such rise occurs.

Quote
I presume you're using Lithium AAAs so it seems unlikely to be insufficient voltage at the PIR unless you have a wiring issue.

I agree.

Here's my theory: the PIR is extremely sensitive to VCC instability. A lithium aaa obviously will not drop below 3V during code execution. But it will cause a small change in VCC which causes the PIR to misfire.

It's by no means proven and I'll provide updates as I see clearer.

Joe

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Tino MagicCarpet - The automatic heated carpet
« Reply #7 on: December 15, 2015, 05:59:31 AM »
Quote
It's by no means proven and I'll provide updates as I see clearer.

I have now fixed this. It is indeed the VCC instability that causes this problem. But how to fix it?

I could add a larger cap at the PIR, but when VCC breaks down at the Tino it would just drain the cap via the gpio port. I could add a diode - but that would cause some battery life degradation because of the forward voltage drop.

After some experimentation I added the cap at the PIR and modified my code to switch the PIR powering GPIO pin to INPUT first thing after returning from sleep. That way the PIR runs exclusively from the cap and no current flows back into the 328p (the ESD diodes have forward drop of 0.5V). Before returning to sleep I switch PIR power back on to power during sleep and refill the cap.

While a bit complicated this scheme works so well I can now even do TX without triggering the PIR.

Joe

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Tino MagicCarpet - The automatic heated carpet
« Reply #8 on: December 15, 2015, 07:56:15 AM »
After some experimentation I added the cap at the PIR and modified my code to switch the PIR powering GPIO pin to INPUT first thing after returning from sleep. That way the PIR runs exclusively from the cap and no current flows back into the 328p (the ESD diodes have forward drop of 0.5V). Before returning to sleep I switch PIR power back on to power during sleep and refill the cap.
It would seem easier to simply set the GPIO pin to INPUT_PULLUP so there is a steady charge into the cap and you won't have a surge turning on the PIR.  Turn off would be GPIO write to 0 and then switch pinmode to output.  After that, I/O is simply pinmode switching.

Still very odd to me, however.

Tom


joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Tino MagicCarpet - The automatic heated carpet
« Reply #9 on: December 15, 2015, 09:09:16 AM »
Quote
It would seem easier to simply set the GPIO pin to INPUT_PULLUP so there is a steady charge into the cap and you won't have a surge turning on the PIR.  Turn off would be GPIO write to 0 and then switch pinmode to output.  After that, I/O is simply pinmode switching.

That's a great idea! Unfortunately though the internal pull-ups are just too big. At 50kOhm you get 66uA at 3.3V. When activated the PIR draws ~150uA. And it activates every 3-5 seconds when I sit at the desk.

Jim111

  • NewMember
  • *
  • Posts: 5
Re: Tino MagicCarpet - The automatic heated carpet
« Reply #10 on: March 11, 2016, 05:57:07 PM »
I noticed what I think is a similar VCC sensitivity with the MotionMote that Felix sells.  I just put one together and followed the instructions to remove the diode and voltage regulator to get max battery lifetime.  However the PIR falsely triggered all the time.  I tracked it down to the LowPower.powerDown call.  If I commented that out and substituted delay(8000) instead everything worked fine.  After reading this thread I decided to solder the voltage regulator back onto the PIR circuit and the problem is now solved.  I am guessing that the PIR would falsely trigger on the small voltage irregularities caused by putting the processor to sleep or waking it up.

Jim