3

I want Arduino to conserve energy and turn it on automatically only when the lights is on. Can I use some kind of light sensor and put it in between power supply and arduino somehow? Ideally light sensor will power from the same power source, if possible. I'm not an electrical engineer - just enthusiast, so please explain your idea as detailed as possible. Many thanks!

2
  • I'm quite sure there are indeed purely-electrical schematics for this. Though you could always use powersave functions on arduino? You probably want a light sensor, with a comparator and something like a relais. Sure there are no sources for this on the internet? I don't know that much of electronics either. – Paul Apr 10 '15 at 9:41
  • Beware that Arduino boards can be very power-inefficient. You may want to use a barebones configuration, maybe just an ATmega chip alone. Then you can save significant power by just calling sleep_mode(), and save even more with power_*_disable(). – Edgar Bonet May 12 '15 at 17:32
2

For a chip like the basic Arduino's ATmega, you don't really "turn it off" to save power, rather you put it into a low-power sleep mode.

First, make sure you aren't consuming more power than needed normally. Make sure unused peripherals like the ADC are off. If your program spends most of its time waiting for external events, try reducing the clock speed either with a slower crystal or the 8 MHz oscillator, and with the clock prescale register.

Next, implement a sleep cycle. Turn off everything you can, and program a hardware timer to generate an interrupt at some point in the future. Enter sleep mode, so the processor stops and only the logic in the counter is still running. When the interrupt fires, the ATmega CPU will wake up and continue operating, at which point you enable the ADC, use a GPIO to drive your light sensor, and take a reading from it. If it doesn't meet your conditions, turn it all off again and go back to sleep until it's worth checking again.

In low power design you must be very careful of things outside the processor stealing power. Watch out for any resistors pulling signals, if the signals are actively drive against the resistor. LEDs are an obvious issue. Also watch out for voltage regulators which may have high quiescent current. And finally beware of peripheral chips - a stock Arduino has an entire second processor sitting there in the USB-serial adapter wasting power. So you will either need to customize the firmware of that to shut down too, or else use a simpler board that doesn't have one (don't just hold it in hardware reset, as the reset pin has an internal pullup which will then consume power).

1

You may keep your Arduino powered, but have it sleep when the lights are off. During sleep, it would periodically awake to check the light level: if it's low enough, it goes back to sleep, otherwise it resumes its work. Here are the detailed steps:

  1. Try to find a power-efficient Arduino or clone (no ON LED, no USB bridge...) or learn how to build and program a barebones one. If you can live with a 8 MHz clock, a bare ATmega, or even ATtiny, may be a good option.
  2. Get an LDR (light-dependent resistor) and an ohmmeter.
  3. Measure the resistance of the LDR at the relevant light levels, and decide for a value of resistance that will serve as a threshold for switching on and off. I will call this LDR_THRESHOLD_RES in the code.
  4. Get a plain resistor with a value close to the previous threshold (within a factor 10 should be OK), but not lower than 1 kΩ. This will be your "pullup" resistor, and its resistance will be LDR_PULLUP_RES.
  5. Decide how often the program will check for the lights being turned on. This delay, in milliseconds, will be LDR_CHECK_DELAY.
  6. Assign both a digital and an analog pin for measuring the LDR. These will be LDR_DRIVE_PIN and LDR_SENSE_PIN respectively.
  7. Connect the LDR between LDR_SENSE_PIN and ground; connect the pullup resistor between LDR_SENSE_PIN and LDR_DRIVE_PIN.
  8. Update the code below (the first 5 #defines) and include it in your sketch.
  9. Add pinMode(LDR_DRIVE_PIN, OUTPUT); to your setup().
  10. Call wait_for_lights() inside loop(), wherever you want your program to pause if the lights are off.
#include <avr/sleep.h>

#define LDR_THRESHOLD_RES 25e3  // 25 kOhm
#define LDR_PULLUP_RES    10e3  // 10 kOhm
#define LDR_CHECK_DELAY    200  // 200 ms
#define LDR_DRIVE_PIN        2  // digital 2
#define LDR_SENSE_PIN        0  // analog 0

#define LDR_THRESHOLD_RATIO (1.0*LDR_PULLUP_RES/LDR_THRESHOLD_RES)
#define LDR_THRESHOLD_READING ((int)(1024 / (1 + LDR_THRESHOLD_RATIO)))

/* Sleep until the light is on. */
void wait_for_lights() {
    for (;;) {
        // Sense light level.
        digitalWrite(LDR_DRIVE_PIN, HIGH);
        int reading = analogRead(LDR_SENSE_PIN);
        digitalWrite(LDR_DRIVE_PIN, LOW);

        // Low reading means the light is on.
        if (reading < LDR_THRESHOLD_READING) return;

        // Wait for a few milliseconds.
        unsigned long start = millis();
        do sleep_mode();
        while (millis() - start < LDR_CHECK_DELAY);
    }
}

This should already get your power consumption pretty low. If you want to save further power, you will likely have to dig into your microcontroller's datasheet. You can try the various power_*_disable() functions and turn off all the peripherals you do not need. You can also try a deeper sleep mode than the default one (IDLE), but then your millis() clock will freeze during sleep, and you will have to set up some wake up source if you do not want to sleep forever. The watchdog timer is a good option.

0

If it's OK for it go off (not just to sleep) when the light is off, power it from the lighting circuit. These two parts will do it without messing with the electrics:

enter image description here enter image description here

The light socket adapter with two outlets is a hardware-store part, probably about USD$3, and the USB charger makes a compact and useful Arduino 5v power supply, USD$6 at Amazon right now. (Apple's little USB power cube might fit better but is more expensive). I use the Nokias for Arduino power supplies and their no-load voltage is just barely over 5v. If you substitute a different one, that would be a worthwhile test to make before you connect it to your Arduino.

0

Conserve energy?
There are many ways to conserve energy in an Arduino(e.g. Use a USB adapter that does not waste energy as heat, instead of using Battery power)
But if you want to save energy by only switching on the Arduino when light is on, it depends on the intensity of the light.
If it is supposed to switch on only during the day, use Solar Panels to power the Arduino.
Else, use an LDR.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.