[Solved] External interrupts using LDR

Hi All,

I’m building a project using Atmega8a along with few sensors. I need the system to sleep at night when it is absolute dark and wake up when it is morning.

How can I trigger an interrupt to INT1 pin of Atmega8a using an LDR so that I can wakeup Atmega8a from POWER_DOWN sleep mode.

LDR can be sensed using analogRead but I just need only 2 states: dark/night and some ambient light present. I need these 2 states to help wakeup the Atmega8a from PWR_DOWN sleep mode.

How can I convert the analog voltage to 2 absolute states? One thing that comes to my mind is using the LDR output as an input to the base of a transistor (as a switch) and use that as the connection to interrupt pin?

Thanks

Light levels change slowly, and so do LDR’s. Hence there is some anbiguity about the light/dark transition

A good way to clean this up would be a schmidt trigger - eg a 74hc14

regards

Allan

This is untested, but I'm quite sure it would work, as long as the LDR's resistance is >300K when dark :

  • Connect LDR from 5V to INT1.
  • Adjust a 100K 10-turn pot 1/2 way.
  • Connect the pot's wiper to INT1 and one end terminal to GND.
  • Connect 10µF capacitor from INT1 to GND.
  • In the morning, adjust the pot so that the voltage on INT1 is 2.65V.
  • This is the high level threshold where the pin is read as 1.
  • Use RISING interrupt mode.
  • You shouldn't get multiple interrupts due to the 10µF filter and the input's built-in 0.44V hysteresis.

Hi allanhurst,

Thanks for your information.

I read about Schmitt Trigger from here and I got to know that Schmitt trigger switches Vout to Vcc+ or Vcc- based on Vin against a threshold. Also I looked at the pin-out of 74hc14 so its an IC with 6 Schmitt triggers.

As far as I understood I would have to use something like this:

+5v -------- LDR----------10k resistor---------GND
|
|
1A (Schmitt Trigger input)

and then

1Y(Schmitt Trigger output) ------------------ INT1 of Atmega8a.

Will the above design ensure I can get 0 at INT1 pin so that Atmega8a can be put to PWR_DOWN sleep at night and also will it generate an interrupt of logic 1 even if I have LITTLE ambient light present when it is morning?

Am I right?

I think less hardware and less current consumption would be wake up the Mega each ? minutes and check level of the LDR with ADC (or Analog Comparator).

The 74hc14 is an invertor, so to get a '0' with high light levels your suggestion is correct...

But Smajdalf's suggestion is also excellent, and saves the (cheap) chip...

Allan

Thanks everyone.

I managed to get hold of a Schmitt Trigger (74hc14) and its working fine. Although i'll be using "wakeup every 15 minutes" strategy in my project.

The operating point can be adjusted by altering the 10k resistor - the higher the value, the lower the light level at which the schmidt will operate.

Allan

Aren't the Arduino inputs already Schmit-triggered?

0.3 to 0.4V of hysteresis according to the datasheet, which should be enough here, but a decent schmitt-trigger
is 2V or so. For photo diodes and transistors you often get lots of variation due to mains lighting, which
suggests lots of hysteresis, but with a low pass filtered LDR mains flicker shouldn't be an issue.

When voltage on input is close to Arduino digital pin treshold it consumes lot of current. Not enough to kill the chip (unless you keep all the pins close to treshold maybe) but enough to ruin budget of low power application.
If you want to use the LDR as direct interrupt you probably save lot of power by using external Schmitt trigger with low power consumption. But if you want to wake up the Arduino every 15 minutes anyway and measure only at those intervals there is no need for the chip - digital buffering is disabled in sleep unless pin is configured as wake up source.

Smajdalf:
When voltage on input is close to Arduino digital pin treshold it consumes lot of current. Not enough to kill the chip (unless you keep all the pins close to threshold maybe) but enough to ruin budget of low power application.
If you want to use the LDR as direct interrupt you probably save lot of power by using external Schmitt trigger with low power consumption. But if you want to wake up the Arduino every 15 minutes anyway and measure only at those intervals there is no need for the chip - digital buffering is disabled in sleep unless pin is configured as wake up source.

Lowest power consumption would be loosing the external chip all together. Haven't heard of this power consumption issue, unless you mean floating input(s) that are susceptible to noise.

Unknown from ritesht93 is what is the battery voltage and the range of voltage the Atmega8a will be operated at. This changes the threshold levels and hysteresis of the Atmega8a and also for the 74HC14 hex inverter. This should be considered when sizing the LDR's pulldown resistor or when adjusting the pulldown potentiometer.

The 74HC14 takes very little current. All unused inputs shoud either be grounded or connected to the +ve supply.

Allan

dlloyd:
Lowest power consumption would be loosing the external chip all together. Haven't heard of this power consumption issue, unless you mean floating input(s) that are susceptible to noise.

Datasheet of most AVRs in "Minimizing power consumption" section states

If the input buffer is enabled and the input signal is left floating or have an analog signal level close to VCC/2, the input buffer will use excessive power.

I have read CMOS chips with Schmitt trigger should suffer from this issue much less and so saving power when the input signal stays near Vcc/2 for longer time (as LDR probably will).

Smajdalf, thanks.

EDIT:

Seems that here in reply#5, its mentioned that external interrupt pins would keep the schmitt circuitry enabled while in sleep mode. I might do some tests and start a new thread (if ever I get the time). Wish Atmel would clarify "excessive power" with more details.