Noob needs help - Moteino wakes and send one string then goes back to sleep.

Started by plutonium, July 01, 2015, 02:02:44 PM

TomWS

Anders,
here is an updated version of your sketch.  I've changed the logic around a bit, when I looked at the code I realized that the magswitch is closed when the mailbox is closed and that will cause the current through the resistor to be always conducting - not good for long battery life.

With this new code you should rewire in the following way:
1. remove both resistors.
2. connect one side of the magswitch to ground and the other side to D4.

With this change (and this new code), the Moteino's internal pullup resistor will pull the D4 pin HIGH when the mailbox is opened and LOW when closed.   The other change I made was to have the pinChangeInterrupt on any state change of the switch so that the Moteino can sleep whether waiting for OPEN or waiting for CLOSED (in case the mailbox door is left open).  I also added switch debounce code.

I compiled this and it builds without errors but I can't test it.

Good luck.

Also, to test the current while sleeping, as Felix mentioned, you need to put a Milli-ammeter between the battery and the Vin pin of the Moteino.  Depending on the type and resolution of the meter, you may have to switch scales to measure current during running and sleeping - there should be a fairly large difference between these two.  Unfortunately, with the pullup resistor always conducting with the door is closed, you'll use more power than you would if the switch closes when the door is opened.

Tom

plutonium

Thank you Tom!

I will try this out right away. And tomorrow vacation to greece for a week. Hopefully it will still running when I come back home :)

Cheers
Anders
New to moteino but I love it and have three of them and more to come. See my house homepage at www.essunga.org

TomWS

Quote from: plutonium on July 16, 2015, 05:17:47 PM
Thank you Tom!

I will try this out right away. And tomorrow vacation to greece for a week. Hopefully it will still running when I come back home :)

Cheers
Anders
I forgot to tell you, when someone on the forum helps you, you need to take them on vacation with you!   8)

Have fun!
Tom

plutonium

Haha, I would like that! With some beers and moteino's we can conquer the world in greece :D

Thanks Tom, I will, hope you have a good summer aswell.
New to moteino but I love it and have three of them and more to come. See my house homepage at www.essunga.org