Arduino Forum

Using Arduino => Networking, Protocols, and Devices => Topic started by: beccacora on May 24, 2011, 03:36 am

Title: Turn Arduino On and Off Remotely
Post by: beccacora on May 24, 2011, 03:36 am
I am working on a piece that consists of an Arduino Duemilanove board and a T-Pro SG5010 servo that moves once every 20 seconds with a fairly light load. It's powered by 8 D cell batteries in series (output of 12 volts). Because it's installed on the ceiling it's hard to access and unplug the batteries to turn the piece off. The batteries need to last as long as possible without needing new ones so leaving it on 24/7 is not a good option and most galleries aren't too happy about needing to climb a ladder twice a day every day to plug and unplug the piece.

I'm thinking the best solution is to find a way to control the power remotely, perhaps using a remote controlled latching relay, but I don't know where to start looking. I'm trying to do this as simply and cheaply as possible.

Anyone have ideas?
Title: Re: Turn Arduino On and Off Remotely
Post by: CrossRoads on May 24, 2011, 04:33 am
Rebuild a little & reprogram.
Rebuild: put a MOSFET in series with the servo power so you can totally turn it off.
Reprogram: Go into sleep mode in between servo  activations, wake up & act, go back to sleep.
Title: Re: Turn Arduino On and Off Remotely
Post by: beccacora on May 24, 2011, 04:55 am
I'm still pretty new to this. Can you explain what you mean and suggest a place that would give me information about how to do it?
Title: Re: Turn Arduino On and Off Remotely
Post by: CrossRoads on May 24, 2011, 06:46 am
See my PM to your PM.
Nchannel mosfet with low Rds between servo ground and battery - (which should be circuit ground).

Need a sleep  mode where you can wake up using internal watchdog timer or similar. Browse some more, or ask in here, I have not done that kind of thing yet, only read about it.
Title: Re: Turn Arduino On and Off Remotely
Post by: beccacora on May 24, 2011, 04:29 pm
Thanks for the clarification. I have a much better idea of what to do now. One quick thing:

The servo runs it's ground through the arduino. The MOSFET would be placed on the ground connecting the servo to the arduino, correct? This sounds like it should definitely extend battery life.

Still looking for a way to power down the arduino entirely so it can be shut off while the gallery is closed. Anyone?
Title: Re: Turn Arduino On and Off Remotely
Post by: FrankRadio on May 24, 2011, 05:36 pm
I don't know what is the activation cycle, i mean how many times at day/hour/minute the CPU must take an action.

Because if you want to save all the bateries, you can use a long time timmer and turn on-off all the electronics, using a mosfet as switch device, and a cd4093 like long time timer, this is easy to do you need only one NAND gate and a resistor and a electrolitic, all the others gates will be used as amplifier to feed the MOSFET gate.

The Arduino runs at 12V with 2-4 mA. Why use conventional bateries? Why do not use a Litium rechargeable batery pack?

Best Regards
Frank
Title: Re: Turn Arduino On and Off Remotely
Post by: beccacora on May 24, 2011, 06:55 pm
@ FrankRadio

Thanks for the input.

Quote
I don't know what is the activation cycle, i mean how many times at day/hour/minute the CPU must take an action.


The motor sweeps once every 20 seconds so that's 3 times a minute, 90 times an hour, for maybe 6-8 hours a day.

Quote
Because if you want to save all the bateries, you can use a long time timmer and turn on-off all the electronics, using a mosfet as switch device, and a cd4093 like long time timer, this is easy to do you need only one NAND gate and a resistor and a electrolitic, all the others gates will be used as amplifier to feed the MOSFET gate.


Do you mind going into detail about what you mean? I apologize, I'm still pretty new to this. I'm learning as fast as I can as I go along, but my background is in fine art rather than in electronics or engineering.

Thanks again.
Title: Re: Turn Arduino On and Off Remotely
Post by: wayneft on May 24, 2011, 11:26 pm
Just curious but when they leave the gallery do they shut the lights off?  I'm wondering if it gets dark enough in the room when there is no one there, you might be able to tie a photosensor into the circuit switch it on and off.  Just my two cents.
Title: Re: Turn Arduino On and Off Remotely
Post by: nickgammon on May 25, 2011, 04:09 am
Glad you asked that because I have been looking for an excuse to work this out. :)

This code shows how you can sleep for 20 seconds in "power down" mode:

Code: [Select]
// Example of sleeping and saving power
//
// Author: Nick Gammon
// Date:   25 May 2011

#include <avr/sleep.h>
#include <avr/wdt.h>

#define LED 13

// watchdog interrupt
ISR(WDT_vect) {
 wdt_disable();  // disable watchdog
}

void myWatchdogEnable(const byte interval) {  // turn on watchdog timer; interrupt mode every 2.0s
 MCUSR = 0;                          // reset various flags
 WDTCSR |= 0b00011000;               // see docs, set WDCE, WDE
 WDTCSR =  0b01000000 | interval;    // set WDIE, and appropriate delay

 wdt_reset();
 set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here
 sleep_enable();          // enables the sleep bit in the mcucr register
 sleep_mode();            // now goes to Sleep and waits for the interrupt
}

void setup()
{
pinMode (LED, OUTPUT);
}  // end of setup

void loop()
{
 digitalWrite (LED, HIGH);  // awake
 delay (2000);    // ie. do stuff here
 digitalWrite (LED, LOW);  // asleep

 // sleep for a total of 20 seconds
 myWatchdogEnable (0b100001);  // 8 seconds
 myWatchdogEnable (0b100001);  // 8 seconds
 myWatchdogEnable (0b100000);  // 4 seconds

}  // end of loop

// sleep bit patterns:
//  1 second:  0b000110
//  2 seconds: 0b000111
//  4 seconds: 0b100000
//  8 seconds: 0b100001



That puts the CPU into power-down mode with the watchdog timer set to wake it up. It isn't particularly accurate but for a gallery I bet no-one will have their stopwatch out. ;)  You can tweak it by replacing (say) the 4 second delay by a 2 second delay.

Eight seconds is the most the watchdog timer can handle so I made up 20 by using 2 x 8 + 4.

My measurements are:

For a Uno:



For a "bare bones" board (described here: http://arduino.cc/forum/index.php/topic,60256.0.html ) :



Straight away you can see that the bare-bones board has much less consumption, particularly asleep. This is because you are not driving the voltage regulator, the USB chip, etc.

You don't have to wire-wrap your own board, there are "bare bones" boards for sale from various places. I think the major thing is to avoid the USB conversion chip and go with programming via an FTDI cable (itself around $20). That obviously saves a lot of power.

My other query is the use of the 12V battery. You may need 12V to drive the display, but it is too much for the Arduino - the voltage regulator is just burning off the excess as heat. I would be inclined to tap into the batteries at about the 6V mark for the processor, thus saving that wastage. Or have a second, smaller, battery bank for the processor (eg.  3 x 1.5 batteries and skip the voltage regulator).

Plus the light-sensing idea is good for saving power when the lights are off. I did an experimental circuit using an op-amp and a light-sensing resistor here:

http://www.gammon.com.au/forum/?id=11011

That shows how you can generate an interrupt, so you could detect the lights are low after one of your 20-second periods of wakefulness, and then set a lengthy sleep time with the op-amp interrupt set to wake you up next morning.

Or, more simply, detect the light level is low, and when you wake up after 20 seconds, just do nothing and go back to sleep. That would be easier.
Title: Re: Turn Arduino On and Off Remotely
Post by: nickgammon on May 25, 2011, 05:07 am

Because it's installed on the ceiling it's hard to access and unplug the batteries to turn the piece off. The batteries need to last as long as possible without needing new ones so leaving it on 24/7 is not a good option and most galleries aren't too happy about needing to climb a ladder twice a day every day to plug and unplug the piece.


Another thing to do is get one of those little clock chips on a board, and set the time on it. Then periodically check the time. If it is out of operating hours of the gallery when you wake up, just do nothing and go back to sleep. And only spend time checking the time every so often (eg. every 100 times you wake up). Once you decide it is "day time" or "night time" set a flag so next time you wake you know whether to do anything or not, until the next time you check the time. You can probably power the clock board itself off one of the Arduino pins, so you can power it right down until you need it (it draws 1.5 mA, well within the capability of one of the digital pins to supply). The on-board battery keeps the time even if it is powered down (eg. the DS1307).
Title: Re: Turn Arduino On and Off Remotely
Post by: CrossRoads on May 25, 2011, 05:41 am
Nick,
Great explanations there. Glad to see the torch picked up on this!
Robert
Title: Re: Turn Arduino On and Off Remotely
Post by: nickgammon on May 25, 2011, 06:12 am
Thanks! I think I'll experiment with driving the clock from the digital pin, just to see how low the power consumption can be.

I think I'd also agree with FrankRadio that the larger the battery pack, the less climbing ladders and replacing them there will be.

Another simple option for the battery would be a simple sealed lead-acid battery pack (SLA). Charge it up with a battery charger, and it should last for ages. That's still 12V.

I have here for example a 7 AH SLA battery. Now consumption in sleep mode of 0.14 mA gives me (by my calculations) 50,000 hours running time (5.7 years). Heck, the battery will probably self-discharge fast than that. Of course the gadget you are driving will consume some of that, but even so, you can probably go for months if not a year without charging the battery.
Title: Re: Turn Arduino On and Off Remotely
Post by: mattcf on May 25, 2011, 06:46 am
a ATtiny25  (with arduino boot-loader) uses very small amounts of power (
picoPower
as called by ATmel) you could use that (and a mosfet) to "wake" your other arduino.  Or possibly even do all the work by its self.

In time (using an external crystal) these things are very accurate.


Code: [Select]


void setup() {
 pinMode(12, OUTPUT);  // N chan MOSFET attached to pin 12
}

void loop()  {
//runs this for a 8 hour work day 9 - 5 formula to find is hours*60*3
for (1440){  
 digitalWrite(12, HIGH);
 delay(12000); //this is a 20 sec delay to run your other ardiono
 // the formulia for finding time in minutes is minutes*60*1000  seconds is seconds*1000
 digitalWrite(12, LOW);
 delay(12000); // delay for 20 sec  almost no power is used here
}

delay(57600000);  // rests for 16 hrs for when the gallary is closed
// formula for that is 24-work hours*60*60*1000

}


Most servos can complete a full 2 cycles in a few seconds off of 5 volts
Title: Re: Turn Arduino On and Off Remotely
Post by: mattcf on May 25, 2011, 07:55 am
Now also know how you have your batts is in Series this only increases voltage NOT amperage.  and your 5v reg wastes more power the greater the voltage is over 7volts (threshold for 5volt regs)
Title: Re: Turn Arduino On and Off Remotely
Post by: nickgammon on May 25, 2011, 08:19 am
As an experiment I added a clock breakout board to my bare-bones processor board:

(http://gammon.com.au/images/Wire_Wrapped_Board_With_Clock.jpg)

With the clock running all the time the power consumption went up from 0.14 mA to 1.3 mA which wasn't very good. However an amended sketch then powered up the clock by bringing pin 5 high (effectively giving power to the clock) and low again afterwards. This dropped power consumption back to 0.14 mA during sleep, and only 19 mA when awake (this sketch didn't use the LED). So it seems reasonable to power up a clock, find the time, and power it down again quickly. Here is the modified sketch:

Code: [Select]
// Example of sleeping and saving power, and reading a clock
//
// Author: Nick Gammon
// Date:   25 May 2011

#include <Wire.h>
#include "RTClib.h"
#include <avr/sleep.h>
#include <avr/wdt.h>

RTC_DS1307 RTC;

#define CLOCK_POWER 5

// watchdog interrupt
ISR(WDT_vect) {
  wdt_disable();  // disable watchdog
}

void myWatchdogEnable(const byte interval) {  // turn on watchdog timer; interrupt mode every 2.0s
  MCUSR = 0;                          // reset various flags
  WDTCSR |= 0b00011000;               // see docs, set WDCE, WDE
  WDTCSR =  0b01000000 | interval;    // set WDIE, and appropriate delay

  wdt_reset();
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here
  sleep_enable();          // enables the sleep bit in the mcucr register
  sleep_mode();            // now goes to Sleep and waits for the interrupt
}   // end of myWatchdogEnable

void setup()
{
  pinMode (CLOCK_POWER, OUTPUT);
 
  digitalWrite (CLOCK_POWER, HIGH);  // power up clock
  delay (1);

  Wire.begin();
  RTC.begin();

  // set time in clock chip if not set before
  if (! RTC.isrunning()) {
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }

  digitalWrite (CLOCK_POWER, LOW);  // power down clock
 
}  // end of setup

void loop()
{

  // power up clock
  digitalWrite (CLOCK_POWER, HIGH);  // power up clock
  delay (1);  // give it time to stabilize

  // activate I2C and clock
  Wire.begin();
  RTC.begin();

  // find the time 
  DateTime now = RTC.now();

  // time now available in now.hour(), now.minute() etc.


  // -------- do something here if required by the time of day
 
  // finished with clock
  digitalWrite (CLOCK_POWER, LOW);
 
  // turn off I2C pull-ups
  digitalWrite (A4, LOW);
  digitalWrite (A5, LOW);
 
  // sleep for a total of 20 seconds
  myWatchdogEnable (0b100001);  // 8 seconds
  myWatchdogEnable (0b100001);  // 8 seconds
  myWatchdogEnable (0b100000);  // 4 seconds

}  // end of loop

// sleep bit patterns:
//  1 second:  0b000110
//  2 seconds: 0b000111
//  4 seconds: 0b100000
//  8 seconds: 0b100001



I wired up the breakout board as follows:

Title: Re: Turn Arduino On and Off Remotely
Post by: nickgammon on May 30, 2011, 07:03 am
I thought I would experiment with trying to save even more power. So read up about the Power Reduction Register (PRR).

By using that you can power off internal "peripherals" thus saving even more power. The code below, when used on a  bare-bones board, drops to 25 uA of current (0.025 mA) when in sleep mode. That's about 1000 times less than when awake. Of course, you don't want to power down something you might need but this shows how you can reduce sleep-mode power consumption from 140 uA in my original test to 25 uA - quite a big saving.

Code: [Select]
// Example of sleeping and saving power, and reading a clock
//
// Author: Nick Gammon
// Date:   25 May 2011

#include <Wire.h>
#include "RTClib.h"

#include <avr/sleep.h>
#include <avr/wdt.h>

RTC_DS1307 RTC;

#define CLOCK_POWER 5

#define LED 13

// watchdog interrupt
ISR(WDT_vect) {
  wdt_disable();  // disable watchdog
  sleep_disable();          // disables the sleep bit in the mcucr register
}

void myWatchdogEnable(const byte interval) {  // turn on watchdog timer; interrupt mode every 2.0s
  MCUSR = 0;                          // reset various flags
  WDTCSR |= 0b00011000;               // see docs, set WDCE, WDE
  WDTCSR =  0b01000000 | interval;    // set WDIE, and appropriate delay

  wdt_reset();
 
  // disable ADC
  ADCSRA = 0; 
 
  // power reduction register
  // Bit 7 - PRTWI: Power Reduction TWI
  // Bit 6 - PRTIM2: Power Reduction Timer/Counter2
  // Bit 5 - PRTIM0: Power Reduction Timer/Counter0
  // Bit 4 - Res: Reserved bit
  // Bit 3 - PRTIM1: Power Reduction Timer/Counter1
  // Bit 2 - PRSPI: Power Reduction Serial Peripheral Interface
  // Bit 1 - PRUSART0: Power Reduction USART0
  // Bit 0 - PRADC: Power Reduction ADC
 
  // turn off various modules
  PRR = 0x11101111;
   
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here
  sleep_enable();          // enables the sleep bit in the mcucr register
  sleep_mode();            // now goes to Sleep and waits for the interrupt
 
  // stop power reduction
  PRR = 0;
}

void setup()
{
  pinMode (CLOCK_POWER, OUTPUT);
  digitalWrite (CLOCK_POWER, HIGH);  // power up clock
  delay (1);

  Wire.begin();
  RTC.begin();

  // set time in clock chip if not set before
  if (! RTC.isrunning()) {
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }

  digitalWrite (CLOCK_POWER, LOW);  // power down clock
 
}  // end of setup

void loop()
{

  // power up clock
  digitalWrite (CLOCK_POWER, HIGH);  // power up clock
  delay (1);  // give it time to stabilize

  // activate I2C and clock
  Wire.begin();
  RTC.begin();

  // find the time 
  DateTime now = RTC.now();

  // time now available in now.hour(), now.minute() etc.

  // finished with clock
  digitalWrite (CLOCK_POWER, LOW);
 
  // turn off I2C pull-ups
  digitalWrite (A4, LOW);
  digitalWrite (A5, LOW);
 
  // turn off I2C
  TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA));

  // -------- do something here if required by the time of day

  // in my case flash an LED for 5 seconds
  pinMode (LED, OUTPUT);
  digitalWrite (LED, HIGH);
  delay (5000);
  digitalWrite (LED, LOW);
 
  // sleep bit patterns:
  //  1 second:  0b000110
  //  2 seconds: 0b000111
  //  4 seconds: 0b100000
  //  8 seconds: 0b100001

  // sleep for a total of 20 seconds
  myWatchdogEnable (0b100001);  // 8 seconds
  myWatchdogEnable (0b100001);  // 8 seconds
  myWatchdogEnable (0b100000);  // 4 seconds

}  // end of loop

Title: Re: Turn Arduino On and Off Remotely
Post by: beccacora on May 30, 2011, 07:12 pm
Thank you everyone for your answers. Lots of really useful stuff, especially the watchdog and this really helps lengthen battery life.

However, the piece itself will be traveling and therefore not subject to consistent light patterns or hours of operation. It will be installed by the gallery and so cannot be reprogrammed once it leaves my studio to adjust for these changes. So I still really need a way to turn the arduino completely on/off remotely. I'm looking essentially for a pretty dumb switch/relay that doesn't need to be controlled by the arduino. I'm thinking to place it between the power source and the arduino, but my searches haven't yeilded much in the way of the correct hardware, probably because I'm not looking in the correct place.

Does anyone have any suggestions?
Title: Re: Turn Arduino On and Off Remotely
Post by: nickgammon on May 30, 2011, 11:17 pm
While it's actually on the road, a simple switch, surely? They could reach that.

While preparing to install, one idea is a couple of those rotary switches with numbers on it. The gallery could "dial up" the switch on and switch off times, before powering it up, and then the device could read the clock and check if the clock time was inside the dial-up time.

Or make it out of something like this:

http://shop.moderndevice.com/products/jeenode-kit

It's still an Atmega328P processor, but on a minimal board (with low power consumption therefore) but at the end is a small transmitter/receiver. This could be programmed with a simple "turn on/turn off" protocol. Then get a second one as the "remote". The remote sends the power-on/power-off code to the master.

Or if it is too hard to change the design now to use the JeeNode now, just have it there as well, simply acting as an on/off switch. As in, if a digital out from the JeeNode is high, your main board does its stuff, otherwise it goes back to sleep.
Title: Re: Turn Arduino On and Off Remotely
Post by: edringel on May 31, 2011, 01:13 pm
I addressed this problem in a deep freeze alarm system; I wanted the Arduino to turn once every 10 minutes.  I used a 555CN timer chip to drive a logic level MOSFET-- that's  a MOSFET that turns on fully at only 5 volts gate voltage. The 555CN chip is the classic 555 chip, but implemented using CMOS technology, so it uses very low levels of current. The 555CN chip was independent of the Arduino and all the other electronics.  Every 10 minutes it turned on the MOSFET for 5 seconds and then went back to fully powered down.

You might also look at where your power costs are the greatest-- likely the servo uses much more power than the Arduino. A simple DVM might help you figure out ways of maximizing the efficiency.  It may be that the minimization of Arduino activity is NOT where the paydirt is.  If driving the Arduino is a significant power cost, consider using a DC to DC converter module to get your 12V down to 5V and then powering the board and logic.  If you are plugging the 12V directly into the board, you are wasting a great deal of energy using the Arduino's on-board regulator.

Just some thoughts, hope it helps.

ed