Go Down

Topic: Turn Arduino On and Off Remotely (Read 8876 times) previous topic - next topic

beccacora

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?

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

beccacora

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?

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

beccacora

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?

FrankRadio

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

beccacora

@ 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.

wayneft

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.

nickgammon

#8
May 25, 2011, 04:09 am Last Edit: May 25, 2011, 04:13 am by Nick Gammon Reason: 1
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:


  • Awake (including the LED shining): 46 mA

  • Asleep: 24.5 mA



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


  • Awake (including the LED shining): 20 mA

  • Asleep: 0.14 mA



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.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon


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).
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

CrossRoads

Nick,
Great explanations there. Glad to see the torch picked up on this!
Robert
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nickgammon

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.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

mattcf

#12
May 25, 2011, 06:46 am Last Edit: May 25, 2011, 08:18 am by mattcf Reason: 1
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

mattcf

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)

nickgammon

As an experiment I added a clock breakout board to my bare-bones processor board:



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:


  • Gnd to Arduino Gnd

  • 5V to Arduino D5 (for power on when required)

  • SDA to Arduino A4

  • SCL to Arduino A5

Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Go Up